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"
38 //#define DEBUG_DISPATCH 1
40 #define DEFO32(name, offset) static TCGv QREG_##name;
41 #define DEFO64(name, offset) static TCGv_i64 QREG_##name;
46 static TCGv_i32 cpu_halted
;
47 static TCGv_i32 cpu_exception_index
;
49 static char cpu_reg_names
[2 * 8 * 3 + 5 * 4];
50 static TCGv cpu_dregs
[8];
51 static TCGv cpu_aregs
[8];
52 static TCGv_i64 cpu_macc
[4];
54 #define REG(insn, pos) (((insn) >> (pos)) & 7)
55 #define DREG(insn, pos) cpu_dregs[REG(insn, pos)]
56 #define AREG(insn, pos) get_areg(s, REG(insn, pos))
57 #define MACREG(acc) cpu_macc[acc]
58 #define QREG_SP get_areg(s, 7)
60 static TCGv NULL_QREG
;
61 #define IS_NULL_QREG(t) (t == NULL_QREG)
62 /* Used to distinguish stores from bad addressing modes. */
63 static TCGv store_dummy
;
65 #include "exec/gen-icount.h"
67 void m68k_tcg_init(void)
72 #define DEFO32(name, offset) \
73 QREG_##name = tcg_global_mem_new_i32(cpu_env, \
74 offsetof(CPUM68KState, offset), #name);
75 #define DEFO64(name, offset) \
76 QREG_##name = tcg_global_mem_new_i64(cpu_env, \
77 offsetof(CPUM68KState, offset), #name);
82 cpu_halted
= tcg_global_mem_new_i32(cpu_env
,
83 -offsetof(M68kCPU
, env
) +
84 offsetof(CPUState
, halted
), "HALTED");
85 cpu_exception_index
= tcg_global_mem_new_i32(cpu_env
,
86 -offsetof(M68kCPU
, env
) +
87 offsetof(CPUState
, exception_index
),
91 for (i
= 0; i
< 8; i
++) {
93 cpu_dregs
[i
] = tcg_global_mem_new(cpu_env
,
94 offsetof(CPUM68KState
, dregs
[i
]), p
);
97 cpu_aregs
[i
] = tcg_global_mem_new(cpu_env
,
98 offsetof(CPUM68KState
, aregs
[i
]), p
);
101 for (i
= 0; i
< 4; i
++) {
102 sprintf(p
, "ACC%d", i
);
103 cpu_macc
[i
] = tcg_global_mem_new_i64(cpu_env
,
104 offsetof(CPUM68KState
, macc
[i
]), p
);
108 NULL_QREG
= tcg_global_mem_new(cpu_env
, -4, "NULL");
109 store_dummy
= tcg_global_mem_new(cpu_env
, -8, "NULL");
112 /* internal defines */
113 typedef struct DisasContext
{
114 DisasContextBase base
;
117 CCOp cc_op
; /* Current CC operation */
123 #define MAX_TO_RELEASE 8
125 TCGv release
[MAX_TO_RELEASE
];
129 static void init_release_array(DisasContext
*s
)
131 #ifdef CONFIG_DEBUG_TCG
132 memset(s
->release
, 0, sizeof(s
->release
));
134 s
->release_count
= 0;
137 static void do_release(DisasContext
*s
)
140 for (i
= 0; i
< s
->release_count
; i
++) {
141 tcg_temp_free(s
->release
[i
]);
143 init_release_array(s
);
146 static TCGv
mark_to_release(DisasContext
*s
, TCGv tmp
)
148 g_assert(s
->release_count
< MAX_TO_RELEASE
);
149 return s
->release
[s
->release_count
++] = tmp
;
152 static TCGv
get_areg(DisasContext
*s
, unsigned regno
)
154 if (s
->writeback_mask
& (1 << regno
)) {
155 return s
->writeback
[regno
];
157 return cpu_aregs
[regno
];
161 static void delay_set_areg(DisasContext
*s
, unsigned regno
,
162 TCGv val
, bool give_temp
)
164 if (s
->writeback_mask
& (1 << regno
)) {
166 tcg_temp_free(s
->writeback
[regno
]);
167 s
->writeback
[regno
] = val
;
169 tcg_gen_mov_i32(s
->writeback
[regno
], val
);
172 s
->writeback_mask
|= 1 << regno
;
174 s
->writeback
[regno
] = val
;
176 TCGv tmp
= tcg_temp_new();
177 s
->writeback
[regno
] = tmp
;
178 tcg_gen_mov_i32(tmp
, val
);
183 static void do_writebacks(DisasContext
*s
)
185 unsigned mask
= s
->writeback_mask
;
187 s
->writeback_mask
= 0;
189 unsigned regno
= ctz32(mask
);
190 tcg_gen_mov_i32(cpu_aregs
[regno
], s
->writeback
[regno
]);
191 tcg_temp_free(s
->writeback
[regno
]);
197 /* is_jmp field values */
198 #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
199 #define DISAS_EXIT DISAS_TARGET_1 /* cpu state was modified dynamically */
201 #if defined(CONFIG_USER_ONLY)
204 #define IS_USER(s) (!(s->base.tb->flags & TB_FLAGS_MSR_S))
205 #define SFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_SFC_S) ? \
206 MMU_KERNEL_IDX : MMU_USER_IDX)
207 #define DFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_DFC_S) ? \
208 MMU_KERNEL_IDX : MMU_USER_IDX)
211 typedef void (*disas_proc
)(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
);
213 #ifdef DEBUG_DISPATCH
214 #define DISAS_INSN(name) \
215 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
217 static void disas_##name(CPUM68KState *env, DisasContext *s, \
220 qemu_log("Dispatch " #name "\n"); \
221 real_disas_##name(env, s, insn); \
223 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
226 #define DISAS_INSN(name) \
227 static void disas_##name(CPUM68KState *env, DisasContext *s, \
231 static const uint8_t cc_op_live
[CC_OP_NB
] = {
232 [CC_OP_DYNAMIC
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
233 [CC_OP_FLAGS
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
234 [CC_OP_ADDB
... CC_OP_ADDL
] = CCF_X
| CCF_N
| CCF_V
,
235 [CC_OP_SUBB
... CC_OP_SUBL
] = CCF_X
| CCF_N
| CCF_V
,
236 [CC_OP_CMPB
... CC_OP_CMPL
] = CCF_X
| CCF_N
| CCF_V
,
237 [CC_OP_LOGIC
] = CCF_X
| CCF_N
240 static void set_cc_op(DisasContext
*s
, CCOp op
)
242 CCOp old_op
= s
->cc_op
;
252 * Discard CC computation that will no longer be used.
253 * Note that X and N are never dead.
255 dead
= cc_op_live
[old_op
] & ~cc_op_live
[op
];
257 tcg_gen_discard_i32(QREG_CC_C
);
260 tcg_gen_discard_i32(QREG_CC_Z
);
263 tcg_gen_discard_i32(QREG_CC_V
);
267 /* Update the CPU env CC_OP state. */
268 static void update_cc_op(DisasContext
*s
)
270 if (!s
->cc_op_synced
) {
272 tcg_gen_movi_i32(QREG_CC_OP
, s
->cc_op
);
276 /* Generate a jump to an immediate address. */
277 static void gen_jmp_im(DisasContext
*s
, uint32_t dest
)
280 tcg_gen_movi_i32(QREG_PC
, dest
);
281 s
->base
.is_jmp
= DISAS_JUMP
;
284 /* Generate a jump to the address in qreg DEST. */
285 static void gen_jmp(DisasContext
*s
, TCGv dest
)
288 tcg_gen_mov_i32(QREG_PC
, dest
);
289 s
->base
.is_jmp
= DISAS_JUMP
;
292 static void gen_raise_exception(int nr
)
296 tmp
= tcg_const_i32(nr
);
297 gen_helper_raise_exception(cpu_env
, tmp
);
298 tcg_temp_free_i32(tmp
);
301 static void gen_exception(DisasContext
*s
, uint32_t dest
, int nr
)
304 tcg_gen_movi_i32(QREG_PC
, dest
);
306 gen_raise_exception(nr
);
308 s
->base
.is_jmp
= DISAS_NORETURN
;
311 static inline void gen_addr_fault(DisasContext
*s
)
313 gen_exception(s
, s
->base
.pc_next
, EXCP_ADDRESS
);
317 * Generate a load from the specified address. Narrow values are
318 * sign extended to full register width.
320 static inline TCGv
gen_load(DisasContext
*s
, int opsize
, TCGv addr
,
324 tmp
= tcg_temp_new_i32();
328 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
330 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
334 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
336 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
339 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
342 g_assert_not_reached();
347 /* Generate a store. */
348 static inline void gen_store(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
353 tcg_gen_qemu_st8(val
, addr
, index
);
356 tcg_gen_qemu_st16(val
, addr
, index
);
359 tcg_gen_qemu_st32(val
, addr
, index
);
362 g_assert_not_reached();
373 * Generate an unsigned load if VAL is 0 a signed load if val is -1,
374 * otherwise generate a store.
376 static TCGv
gen_ldst(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
377 ea_what what
, int index
)
379 if (what
== EA_STORE
) {
380 gen_store(s
, opsize
, addr
, val
, index
);
383 return mark_to_release(s
, gen_load(s
, opsize
, addr
,
384 what
== EA_LOADS
, index
));
388 /* Read a 16-bit immediate constant */
389 static inline uint16_t read_im16(CPUM68KState
*env
, DisasContext
*s
)
392 im
= translator_lduw(env
, &s
->base
, s
->pc
);
397 /* Read an 8-bit immediate constant */
398 static inline uint8_t read_im8(CPUM68KState
*env
, DisasContext
*s
)
400 return read_im16(env
, s
);
403 /* Read a 32-bit immediate constant. */
404 static inline uint32_t read_im32(CPUM68KState
*env
, DisasContext
*s
)
407 im
= read_im16(env
, s
) << 16;
408 im
|= 0xffff & read_im16(env
, s
);
412 /* Read a 64-bit immediate constant. */
413 static inline uint64_t read_im64(CPUM68KState
*env
, DisasContext
*s
)
416 im
= (uint64_t)read_im32(env
, s
) << 32;
417 im
|= (uint64_t)read_im32(env
, s
);
421 /* Calculate and address index. */
422 static TCGv
gen_addr_index(DisasContext
*s
, uint16_t ext
, TCGv tmp
)
427 add
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(ext
, 12);
428 if ((ext
& 0x800) == 0) {
429 tcg_gen_ext16s_i32(tmp
, add
);
432 scale
= (ext
>> 9) & 3;
434 tcg_gen_shli_i32(tmp
, add
, scale
);
441 * Handle a base + index + displacement effective address.
442 * A NULL_QREG base means pc-relative.
444 static TCGv
gen_lea_indexed(CPUM68KState
*env
, DisasContext
*s
, TCGv base
)
453 ext
= read_im16(env
, s
);
455 if ((ext
& 0x800) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_WORD_INDEX
))
458 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
) &&
459 !m68k_feature(s
->env
, M68K_FEATURE_SCALED_INDEX
)) {
464 /* full extension word format */
465 if (!m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
))
468 if ((ext
& 0x30) > 0x10) {
469 /* base displacement */
470 if ((ext
& 0x30) == 0x20) {
471 bd
= (int16_t)read_im16(env
, s
);
473 bd
= read_im32(env
, s
);
478 tmp
= mark_to_release(s
, tcg_temp_new());
479 if ((ext
& 0x44) == 0) {
481 add
= gen_addr_index(s
, ext
, tmp
);
485 if ((ext
& 0x80) == 0) {
486 /* base not suppressed */
487 if (IS_NULL_QREG(base
)) {
488 base
= mark_to_release(s
, tcg_const_i32(offset
+ bd
));
491 if (!IS_NULL_QREG(add
)) {
492 tcg_gen_add_i32(tmp
, add
, base
);
498 if (!IS_NULL_QREG(add
)) {
500 tcg_gen_addi_i32(tmp
, add
, bd
);
504 add
= mark_to_release(s
, tcg_const_i32(bd
));
506 if ((ext
& 3) != 0) {
507 /* memory indirect */
508 base
= mark_to_release(s
, gen_load(s
, OS_LONG
, add
, 0, IS_USER(s
)));
509 if ((ext
& 0x44) == 4) {
510 add
= gen_addr_index(s
, ext
, tmp
);
511 tcg_gen_add_i32(tmp
, add
, base
);
517 /* outer displacement */
518 if ((ext
& 3) == 2) {
519 od
= (int16_t)read_im16(env
, s
);
521 od
= read_im32(env
, s
);
527 tcg_gen_addi_i32(tmp
, add
, od
);
532 /* brief extension word format */
533 tmp
= mark_to_release(s
, tcg_temp_new());
534 add
= gen_addr_index(s
, ext
, tmp
);
535 if (!IS_NULL_QREG(base
)) {
536 tcg_gen_add_i32(tmp
, add
, base
);
538 tcg_gen_addi_i32(tmp
, tmp
, (int8_t)ext
);
540 tcg_gen_addi_i32(tmp
, add
, offset
+ (int8_t)ext
);
547 /* Sign or zero extend a value. */
549 static inline void gen_ext(TCGv res
, TCGv val
, int opsize
, int sign
)
554 tcg_gen_ext8s_i32(res
, val
);
556 tcg_gen_ext8u_i32(res
, val
);
561 tcg_gen_ext16s_i32(res
, val
);
563 tcg_gen_ext16u_i32(res
, val
);
567 tcg_gen_mov_i32(res
, val
);
570 g_assert_not_reached();
574 /* Evaluate all the CC flags. */
576 static void gen_flush_flags(DisasContext
*s
)
587 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
588 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
589 /* Compute signed overflow for addition. */
592 tcg_gen_sub_i32(t0
, QREG_CC_N
, QREG_CC_V
);
593 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_ADDB
, 1);
594 tcg_gen_xor_i32(t1
, QREG_CC_N
, QREG_CC_V
);
595 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
597 tcg_gen_andc_i32(QREG_CC_V
, t1
, QREG_CC_V
);
604 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
605 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
606 /* Compute signed overflow for subtraction. */
609 tcg_gen_add_i32(t0
, QREG_CC_N
, QREG_CC_V
);
610 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_SUBB
, 1);
611 tcg_gen_xor_i32(t1
, QREG_CC_N
, t0
);
612 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
614 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t1
);
621 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_C
, QREG_CC_N
, QREG_CC_V
);
622 tcg_gen_sub_i32(QREG_CC_Z
, QREG_CC_N
, QREG_CC_V
);
623 gen_ext(QREG_CC_Z
, QREG_CC_Z
, s
->cc_op
- CC_OP_CMPB
, 1);
624 /* Compute signed overflow for subtraction. */
626 tcg_gen_xor_i32(t0
, QREG_CC_Z
, QREG_CC_N
);
627 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, QREG_CC_N
);
628 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t0
);
630 tcg_gen_mov_i32(QREG_CC_N
, QREG_CC_Z
);
634 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
635 tcg_gen_movi_i32(QREG_CC_C
, 0);
636 tcg_gen_movi_i32(QREG_CC_V
, 0);
640 gen_helper_flush_flags(cpu_env
, QREG_CC_OP
);
645 t0
= tcg_const_i32(s
->cc_op
);
646 gen_helper_flush_flags(cpu_env
, t0
);
652 /* Note that flush_flags also assigned to env->cc_op. */
653 s
->cc_op
= CC_OP_FLAGS
;
656 static inline TCGv
gen_extend(DisasContext
*s
, TCGv val
, int opsize
, int sign
)
660 if (opsize
== OS_LONG
) {
663 tmp
= mark_to_release(s
, tcg_temp_new());
664 gen_ext(tmp
, val
, opsize
, sign
);
670 static void gen_logic_cc(DisasContext
*s
, TCGv val
, int opsize
)
672 gen_ext(QREG_CC_N
, val
, opsize
, 1);
673 set_cc_op(s
, CC_OP_LOGIC
);
676 static void gen_update_cc_cmp(DisasContext
*s
, TCGv dest
, TCGv src
, int opsize
)
678 tcg_gen_mov_i32(QREG_CC_N
, dest
);
679 tcg_gen_mov_i32(QREG_CC_V
, src
);
680 set_cc_op(s
, CC_OP_CMPB
+ opsize
);
683 static void gen_update_cc_add(TCGv dest
, TCGv src
, int opsize
)
685 gen_ext(QREG_CC_N
, dest
, opsize
, 1);
686 tcg_gen_mov_i32(QREG_CC_V
, src
);
689 static inline int opsize_bytes(int opsize
)
692 case OS_BYTE
: return 1;
693 case OS_WORD
: return 2;
694 case OS_LONG
: return 4;
695 case OS_SINGLE
: return 4;
696 case OS_DOUBLE
: return 8;
697 case OS_EXTENDED
: return 12;
698 case OS_PACKED
: return 12;
700 g_assert_not_reached();
704 static inline int insn_opsize(int insn
)
706 switch ((insn
>> 6) & 3) {
707 case 0: return OS_BYTE
;
708 case 1: return OS_WORD
;
709 case 2: return OS_LONG
;
711 g_assert_not_reached();
715 static inline int ext_opsize(int ext
, int pos
)
717 switch ((ext
>> pos
) & 7) {
718 case 0: return OS_LONG
;
719 case 1: return OS_SINGLE
;
720 case 2: return OS_EXTENDED
;
721 case 3: return OS_PACKED
;
722 case 4: return OS_WORD
;
723 case 5: return OS_DOUBLE
;
724 case 6: return OS_BYTE
;
726 g_assert_not_reached();
731 * Assign value to a register. If the width is less than the register width
732 * only the low part of the register is set.
734 static void gen_partset_reg(int opsize
, TCGv reg
, TCGv val
)
739 tcg_gen_andi_i32(reg
, reg
, 0xffffff00);
740 tmp
= tcg_temp_new();
741 tcg_gen_ext8u_i32(tmp
, val
);
742 tcg_gen_or_i32(reg
, reg
, tmp
);
746 tcg_gen_andi_i32(reg
, reg
, 0xffff0000);
747 tmp
= tcg_temp_new();
748 tcg_gen_ext16u_i32(tmp
, val
);
749 tcg_gen_or_i32(reg
, reg
, tmp
);
754 tcg_gen_mov_i32(reg
, val
);
757 g_assert_not_reached();
762 * Generate code for an "effective address". Does not adjust the base
763 * register for autoincrement addressing modes.
765 static TCGv
gen_lea_mode(CPUM68KState
*env
, DisasContext
*s
,
766 int mode
, int reg0
, int opsize
)
774 case 0: /* Data register direct. */
775 case 1: /* Address register direct. */
777 case 3: /* Indirect postincrement. */
778 if (opsize
== OS_UNSIZED
) {
782 case 2: /* Indirect register */
783 return get_areg(s
, reg0
);
784 case 4: /* Indirect predecrememnt. */
785 if (opsize
== OS_UNSIZED
) {
788 reg
= get_areg(s
, reg0
);
789 tmp
= mark_to_release(s
, tcg_temp_new());
790 if (reg0
== 7 && opsize
== OS_BYTE
&&
791 m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
792 tcg_gen_subi_i32(tmp
, reg
, 2);
794 tcg_gen_subi_i32(tmp
, reg
, opsize_bytes(opsize
));
797 case 5: /* Indirect displacement. */
798 reg
= get_areg(s
, reg0
);
799 tmp
= mark_to_release(s
, tcg_temp_new());
800 ext
= read_im16(env
, s
);
801 tcg_gen_addi_i32(tmp
, reg
, (int16_t)ext
);
803 case 6: /* Indirect index + displacement. */
804 reg
= get_areg(s
, reg0
);
805 return gen_lea_indexed(env
, s
, reg
);
808 case 0: /* Absolute short. */
809 offset
= (int16_t)read_im16(env
, s
);
810 return mark_to_release(s
, tcg_const_i32(offset
));
811 case 1: /* Absolute long. */
812 offset
= read_im32(env
, s
);
813 return mark_to_release(s
, tcg_const_i32(offset
));
814 case 2: /* pc displacement */
816 offset
+= (int16_t)read_im16(env
, s
);
817 return mark_to_release(s
, tcg_const_i32(offset
));
818 case 3: /* pc index+displacement. */
819 return gen_lea_indexed(env
, s
, NULL_QREG
);
820 case 4: /* Immediate. */
825 /* Should never happen. */
829 static TCGv
gen_lea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
832 int mode
= extract32(insn
, 3, 3);
833 int reg0
= REG(insn
, 0);
834 return gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
838 * Generate code to load/store a value from/into an EA. If WHAT > 0 this is
839 * a write otherwise it is a read (0 == sign extend, -1 == zero extend).
840 * ADDRP is non-null for readwrite operands.
842 static TCGv
gen_ea_mode(CPUM68KState
*env
, DisasContext
*s
, int mode
, int reg0
,
843 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
,
846 TCGv reg
, tmp
, result
;
850 case 0: /* Data register direct. */
851 reg
= cpu_dregs
[reg0
];
852 if (what
== EA_STORE
) {
853 gen_partset_reg(opsize
, reg
, val
);
856 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
858 case 1: /* Address register direct. */
859 reg
= get_areg(s
, reg0
);
860 if (what
== EA_STORE
) {
861 tcg_gen_mov_i32(reg
, val
);
864 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
866 case 2: /* Indirect register */
867 reg
= get_areg(s
, reg0
);
868 return gen_ldst(s
, opsize
, reg
, val
, what
, index
);
869 case 3: /* Indirect postincrement. */
870 reg
= get_areg(s
, reg0
);
871 result
= gen_ldst(s
, opsize
, reg
, val
, what
, index
);
872 if (what
== EA_STORE
|| !addrp
) {
873 TCGv tmp
= tcg_temp_new();
874 if (reg0
== 7 && opsize
== OS_BYTE
&&
875 m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
876 tcg_gen_addi_i32(tmp
, reg
, 2);
878 tcg_gen_addi_i32(tmp
, reg
, opsize_bytes(opsize
));
880 delay_set_areg(s
, reg0
, tmp
, true);
883 case 4: /* Indirect predecrememnt. */
884 if (addrp
&& what
== EA_STORE
) {
887 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
888 if (IS_NULL_QREG(tmp
)) {
895 result
= gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
896 if (what
== EA_STORE
|| !addrp
) {
897 delay_set_areg(s
, reg0
, tmp
, false);
900 case 5: /* Indirect displacement. */
901 case 6: /* Indirect index + displacement. */
903 if (addrp
&& what
== EA_STORE
) {
906 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
907 if (IS_NULL_QREG(tmp
)) {
914 return gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
917 case 0: /* Absolute short. */
918 case 1: /* Absolute long. */
919 case 2: /* pc displacement */
920 case 3: /* pc index+displacement. */
922 case 4: /* Immediate. */
923 /* Sign extend values for consistency. */
926 if (what
== EA_LOADS
) {
927 offset
= (int8_t)read_im8(env
, s
);
929 offset
= read_im8(env
, s
);
933 if (what
== EA_LOADS
) {
934 offset
= (int16_t)read_im16(env
, s
);
936 offset
= read_im16(env
, s
);
940 offset
= read_im32(env
, s
);
943 g_assert_not_reached();
945 return mark_to_release(s
, tcg_const_i32(offset
));
950 /* Should never happen. */
954 static TCGv
gen_ea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
955 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
, int index
)
957 int mode
= extract32(insn
, 3, 3);
958 int reg0
= REG(insn
, 0);
959 return gen_ea_mode(env
, s
, mode
, reg0
, opsize
, val
, addrp
, what
, index
);
962 static TCGv_ptr
gen_fp_ptr(int freg
)
964 TCGv_ptr fp
= tcg_temp_new_ptr();
965 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fregs
[freg
]));
969 static TCGv_ptr
gen_fp_result_ptr(void)
971 TCGv_ptr fp
= tcg_temp_new_ptr();
972 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fp_result
));
976 static void gen_fp_move(TCGv_ptr dest
, TCGv_ptr src
)
981 t32
= tcg_temp_new();
982 tcg_gen_ld16u_i32(t32
, src
, offsetof(FPReg
, l
.upper
));
983 tcg_gen_st16_i32(t32
, dest
, offsetof(FPReg
, l
.upper
));
986 t64
= tcg_temp_new_i64();
987 tcg_gen_ld_i64(t64
, src
, offsetof(FPReg
, l
.lower
));
988 tcg_gen_st_i64(t64
, dest
, offsetof(FPReg
, l
.lower
));
989 tcg_temp_free_i64(t64
);
992 static void gen_load_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
998 t64
= tcg_temp_new_i64();
999 tmp
= tcg_temp_new();
1002 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
1003 gen_helper_exts32(cpu_env
, fp
, tmp
);
1006 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
1007 gen_helper_exts32(cpu_env
, fp
, tmp
);
1010 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
1011 gen_helper_exts32(cpu_env
, fp
, tmp
);
1014 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
1015 gen_helper_extf32(cpu_env
, fp
, tmp
);
1018 tcg_gen_qemu_ld64(t64
, addr
, index
);
1019 gen_helper_extf64(cpu_env
, fp
, t64
);
1022 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1023 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1026 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
1027 tcg_gen_shri_i32(tmp
, tmp
, 16);
1028 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1029 tcg_gen_addi_i32(tmp
, addr
, 4);
1030 tcg_gen_qemu_ld64(t64
, tmp
, index
);
1031 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1035 * unimplemented data type on 68040/ColdFire
1036 * FIXME if needed for another FPU
1038 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1041 g_assert_not_reached();
1044 tcg_temp_free_i64(t64
);
1047 static void gen_store_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
1053 t64
= tcg_temp_new_i64();
1054 tmp
= tcg_temp_new();
1057 gen_helper_reds32(tmp
, cpu_env
, fp
);
1058 tcg_gen_qemu_st8(tmp
, addr
, index
);
1061 gen_helper_reds32(tmp
, cpu_env
, fp
);
1062 tcg_gen_qemu_st16(tmp
, addr
, index
);
1065 gen_helper_reds32(tmp
, cpu_env
, fp
);
1066 tcg_gen_qemu_st32(tmp
, addr
, index
);
1069 gen_helper_redf32(tmp
, cpu_env
, fp
);
1070 tcg_gen_qemu_st32(tmp
, addr
, index
);
1073 gen_helper_redf64(t64
, cpu_env
, fp
);
1074 tcg_gen_qemu_st64(t64
, addr
, index
);
1077 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1078 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1081 tcg_gen_ld16u_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1082 tcg_gen_shli_i32(tmp
, tmp
, 16);
1083 tcg_gen_qemu_st32(tmp
, addr
, index
);
1084 tcg_gen_addi_i32(tmp
, addr
, 4);
1085 tcg_gen_ld_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1086 tcg_gen_qemu_st64(t64
, tmp
, index
);
1090 * unimplemented data type on 68040/ColdFire
1091 * FIXME if needed for another FPU
1093 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1096 g_assert_not_reached();
1099 tcg_temp_free_i64(t64
);
1102 static void gen_ldst_fp(DisasContext
*s
, int opsize
, TCGv addr
,
1103 TCGv_ptr fp
, ea_what what
, int index
)
1105 if (what
== EA_STORE
) {
1106 gen_store_fp(s
, opsize
, addr
, fp
, index
);
1108 gen_load_fp(s
, opsize
, addr
, fp
, index
);
1112 static int gen_ea_mode_fp(CPUM68KState
*env
, DisasContext
*s
, int mode
,
1113 int reg0
, int opsize
, TCGv_ptr fp
, ea_what what
,
1116 TCGv reg
, addr
, tmp
;
1120 case 0: /* Data register direct. */
1121 reg
= cpu_dregs
[reg0
];
1122 if (what
== EA_STORE
) {
1127 gen_helper_reds32(reg
, cpu_env
, fp
);
1130 gen_helper_redf32(reg
, cpu_env
, fp
);
1133 g_assert_not_reached();
1136 tmp
= tcg_temp_new();
1139 tcg_gen_ext8s_i32(tmp
, reg
);
1140 gen_helper_exts32(cpu_env
, fp
, tmp
);
1143 tcg_gen_ext16s_i32(tmp
, reg
);
1144 gen_helper_exts32(cpu_env
, fp
, tmp
);
1147 gen_helper_exts32(cpu_env
, fp
, reg
);
1150 gen_helper_extf32(cpu_env
, fp
, reg
);
1153 g_assert_not_reached();
1158 case 1: /* Address register direct. */
1160 case 2: /* Indirect register */
1161 addr
= get_areg(s
, reg0
);
1162 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1164 case 3: /* Indirect postincrement. */
1165 addr
= cpu_aregs
[reg0
];
1166 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1167 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(opsize
));
1169 case 4: /* Indirect predecrememnt. */
1170 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1171 if (IS_NULL_QREG(addr
)) {
1174 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1175 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
1177 case 5: /* Indirect displacement. */
1178 case 6: /* Indirect index + displacement. */
1180 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1181 if (IS_NULL_QREG(addr
)) {
1184 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1188 case 0: /* Absolute short. */
1189 case 1: /* Absolute long. */
1190 case 2: /* pc displacement */
1191 case 3: /* pc index+displacement. */
1193 case 4: /* Immediate. */
1194 if (what
== EA_STORE
) {
1199 tmp
= tcg_const_i32((int8_t)read_im8(env
, s
));
1200 gen_helper_exts32(cpu_env
, fp
, tmp
);
1204 tmp
= tcg_const_i32((int16_t)read_im16(env
, s
));
1205 gen_helper_exts32(cpu_env
, fp
, tmp
);
1209 tmp
= tcg_const_i32(read_im32(env
, s
));
1210 gen_helper_exts32(cpu_env
, fp
, tmp
);
1214 tmp
= tcg_const_i32(read_im32(env
, s
));
1215 gen_helper_extf32(cpu_env
, fp
, tmp
);
1219 t64
= tcg_const_i64(read_im64(env
, s
));
1220 gen_helper_extf64(cpu_env
, fp
, t64
);
1221 tcg_temp_free_i64(t64
);
1224 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1225 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1228 tmp
= tcg_const_i32(read_im32(env
, s
) >> 16);
1229 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1231 t64
= tcg_const_i64(read_im64(env
, s
));
1232 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1233 tcg_temp_free_i64(t64
);
1237 * unimplemented data type on 68040/ColdFire
1238 * FIXME if needed for another FPU
1240 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1243 g_assert_not_reached();
1253 static int gen_ea_fp(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
1254 int opsize
, TCGv_ptr fp
, ea_what what
, int index
)
1256 int mode
= extract32(insn
, 3, 3);
1257 int reg0
= REG(insn
, 0);
1258 return gen_ea_mode_fp(env
, s
, mode
, reg0
, opsize
, fp
, what
, index
);
1269 static void gen_cc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
1275 /* The CC_OP_CMP form can handle most normal comparisons directly. */
1276 if (op
== CC_OP_CMPB
|| op
== CC_OP_CMPW
|| op
== CC_OP_CMPL
) {
1283 tcond
= TCG_COND_LEU
;
1287 tcond
= TCG_COND_LTU
;
1291 tcond
= TCG_COND_EQ
;
1296 c
->v2
= tcg_const_i32(0);
1297 c
->v1
= tmp
= tcg_temp_new();
1298 tcg_gen_sub_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1299 gen_ext(tmp
, tmp
, op
- CC_OP_CMPB
, 1);
1303 tcond
= TCG_COND_LT
;
1307 tcond
= TCG_COND_LE
;
1314 c
->v2
= tcg_const_i32(0);
1320 tcond
= TCG_COND_NEVER
;
1322 case 14: /* GT (!(Z || (N ^ V))) */
1323 case 15: /* LE (Z || (N ^ V)) */
1325 * Logic operations clear V, which simplifies LE to (Z || N),
1326 * and since Z and N are co-located, this becomes a normal
1329 if (op
== CC_OP_LOGIC
) {
1331 tcond
= TCG_COND_LE
;
1335 case 12: /* GE (!(N ^ V)) */
1336 case 13: /* LT (N ^ V) */
1337 /* Logic operations clear V, which simplifies this to N. */
1338 if (op
!= CC_OP_LOGIC
) {
1342 case 10: /* PL (!N) */
1343 case 11: /* MI (N) */
1344 /* Several cases represent N normally. */
1345 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1346 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1347 op
== CC_OP_LOGIC
) {
1349 tcond
= TCG_COND_LT
;
1353 case 6: /* NE (!Z) */
1354 case 7: /* EQ (Z) */
1355 /* Some cases fold Z into N. */
1356 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1357 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1358 op
== CC_OP_LOGIC
) {
1359 tcond
= TCG_COND_EQ
;
1364 case 4: /* CC (!C) */
1365 case 5: /* CS (C) */
1366 /* Some cases fold C into X. */
1367 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1368 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
) {
1369 tcond
= TCG_COND_NE
;
1374 case 8: /* VC (!V) */
1375 case 9: /* VS (V) */
1376 /* Logic operations clear V and C. */
1377 if (op
== CC_OP_LOGIC
) {
1378 tcond
= TCG_COND_NEVER
;
1385 /* Otherwise, flush flag state to CC_OP_FLAGS. */
1392 /* Invalid, or handled above. */
1394 case 2: /* HI (!C && !Z) -> !(C || Z)*/
1395 case 3: /* LS (C || Z) */
1396 c
->v1
= tmp
= tcg_temp_new();
1398 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1399 tcg_gen_or_i32(tmp
, tmp
, QREG_CC_C
);
1400 tcond
= TCG_COND_NE
;
1402 case 4: /* CC (!C) */
1403 case 5: /* CS (C) */
1405 tcond
= TCG_COND_NE
;
1407 case 6: /* NE (!Z) */
1408 case 7: /* EQ (Z) */
1410 tcond
= TCG_COND_EQ
;
1412 case 8: /* VC (!V) */
1413 case 9: /* VS (V) */
1415 tcond
= TCG_COND_LT
;
1417 case 10: /* PL (!N) */
1418 case 11: /* MI (N) */
1420 tcond
= TCG_COND_LT
;
1422 case 12: /* GE (!(N ^ V)) */
1423 case 13: /* LT (N ^ V) */
1424 c
->v1
= tmp
= tcg_temp_new();
1426 tcg_gen_xor_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1427 tcond
= TCG_COND_LT
;
1429 case 14: /* GT (!(Z || (N ^ V))) */
1430 case 15: /* LE (Z || (N ^ V)) */
1431 c
->v1
= tmp
= tcg_temp_new();
1433 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1434 tcg_gen_neg_i32(tmp
, tmp
);
1435 tmp2
= tcg_temp_new();
1436 tcg_gen_xor_i32(tmp2
, QREG_CC_N
, QREG_CC_V
);
1437 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1438 tcg_temp_free(tmp2
);
1439 tcond
= TCG_COND_LT
;
1444 if ((cond
& 1) == 0) {
1445 tcond
= tcg_invert_cond(tcond
);
1450 static void free_cond(DisasCompare
*c
)
1453 tcg_temp_free(c
->v1
);
1456 tcg_temp_free(c
->v2
);
1460 static void gen_jmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
1464 gen_cc_cond(&c
, s
, cond
);
1466 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
1470 /* Force a TB lookup after an instruction that changes the CPU state. */
1471 static void gen_exit_tb(DisasContext
*s
)
1474 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
1475 s
->base
.is_jmp
= DISAS_EXIT
;
1478 #define SRC_EA(env, result, opsize, op_sign, addrp) do { \
1479 result = gen_ea(env, s, insn, opsize, NULL_QREG, addrp, \
1480 op_sign ? EA_LOADS : EA_LOADU, IS_USER(s)); \
1481 if (IS_NULL_QREG(result)) { \
1482 gen_addr_fault(s); \
1487 #define DEST_EA(env, insn, opsize, val, addrp) do { \
1488 TCGv ea_result = gen_ea(env, s, insn, opsize, val, addrp, \
1489 EA_STORE, IS_USER(s)); \
1490 if (IS_NULL_QREG(ea_result)) { \
1491 gen_addr_fault(s); \
1496 /* Generate a jump to an immediate address. */
1497 static void gen_jmp_tb(DisasContext
*s
, int n
, uint32_t dest
)
1499 if (unlikely(s
->ss_active
)) {
1501 tcg_gen_movi_i32(QREG_PC
, dest
);
1502 gen_raise_exception(EXCP_TRACE
);
1503 } else if (translator_use_goto_tb(&s
->base
, dest
)) {
1505 tcg_gen_movi_i32(QREG_PC
, dest
);
1506 tcg_gen_exit_tb(s
->base
.tb
, n
);
1508 gen_jmp_im(s
, dest
);
1509 tcg_gen_exit_tb(NULL
, 0);
1511 s
->base
.is_jmp
= DISAS_NORETURN
;
1520 cond
= (insn
>> 8) & 0xf;
1521 gen_cc_cond(&c
, s
, cond
);
1523 tmp
= tcg_temp_new();
1524 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
1527 tcg_gen_neg_i32(tmp
, tmp
);
1528 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
1540 reg
= DREG(insn
, 0);
1542 offset
= (int16_t)read_im16(env
, s
);
1543 l1
= gen_new_label();
1544 gen_jmpcc(s
, (insn
>> 8) & 0xf, l1
);
1546 tmp
= tcg_temp_new();
1547 tcg_gen_ext16s_i32(tmp
, reg
);
1548 tcg_gen_addi_i32(tmp
, tmp
, -1);
1549 gen_partset_reg(OS_WORD
, reg
, tmp
);
1550 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, -1, l1
);
1551 gen_jmp_tb(s
, 1, base
+ offset
);
1553 gen_jmp_tb(s
, 0, s
->pc
);
1556 DISAS_INSN(undef_mac
)
1558 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEA
);
1561 DISAS_INSN(undef_fpu
)
1563 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEF
);
1569 * ??? This is both instructions that are as yet unimplemented
1570 * for the 680x0 series, as well as those that are implemented
1571 * but actually illegal for CPU32 or pre-68020.
1573 qemu_log_mask(LOG_UNIMP
, "Illegal instruction: %04x @ %08x\n",
1574 insn
, s
->base
.pc_next
);
1575 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1585 sign
= (insn
& 0x100) != 0;
1586 reg
= DREG(insn
, 9);
1587 tmp
= tcg_temp_new();
1589 tcg_gen_ext16s_i32(tmp
, reg
);
1591 tcg_gen_ext16u_i32(tmp
, reg
);
1592 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1593 tcg_gen_mul_i32(tmp
, tmp
, src
);
1594 tcg_gen_mov_i32(reg
, tmp
);
1595 gen_logic_cc(s
, tmp
, OS_LONG
);
1605 /* divX.w <EA>,Dn 32/16 -> 16r:16q */
1607 sign
= (insn
& 0x100) != 0;
1609 /* dest.l / src.w */
1611 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1612 destr
= tcg_const_i32(REG(insn
, 9));
1614 gen_helper_divsw(cpu_env
, destr
, src
);
1616 gen_helper_divuw(cpu_env
, destr
, src
);
1618 tcg_temp_free(destr
);
1620 set_cc_op(s
, CC_OP_FLAGS
);
1629 ext
= read_im16(env
, s
);
1631 sign
= (ext
& 0x0800) != 0;
1634 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
1635 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1639 /* divX.l <EA>, Dr:Dq 64/32 -> 32r:32q */
1641 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1642 num
= tcg_const_i32(REG(ext
, 12));
1643 reg
= tcg_const_i32(REG(ext
, 0));
1645 gen_helper_divsll(cpu_env
, num
, reg
, den
);
1647 gen_helper_divull(cpu_env
, num
, reg
, den
);
1651 set_cc_op(s
, CC_OP_FLAGS
);
1655 /* divX.l <EA>, Dq 32/32 -> 32q */
1656 /* divXl.l <EA>, Dr:Dq 32/32 -> 32r:32q */
1658 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1659 num
= tcg_const_i32(REG(ext
, 12));
1660 reg
= tcg_const_i32(REG(ext
, 0));
1662 gen_helper_divsl(cpu_env
, num
, reg
, den
);
1664 gen_helper_divul(cpu_env
, num
, reg
, den
);
1669 set_cc_op(s
, CC_OP_FLAGS
);
1672 static void bcd_add(TCGv dest
, TCGv src
)
1677 * dest10 = dest10 + src10 + X
1681 * t3 = t2 + dest + X
1685 * t7 = (t6 >> 2) | (t6 >> 3)
1690 * t1 = (src + 0x066) + dest + X
1691 * = result with some possible exceeding 0x6
1694 t0
= tcg_const_i32(0x066);
1695 tcg_gen_add_i32(t0
, t0
, src
);
1697 t1
= tcg_temp_new();
1698 tcg_gen_add_i32(t1
, t0
, dest
);
1699 tcg_gen_add_i32(t1
, t1
, QREG_CC_X
);
1701 /* we will remove exceeding 0x6 where there is no carry */
1704 * t0 = (src + 0x0066) ^ dest
1705 * = t1 without carries
1708 tcg_gen_xor_i32(t0
, t0
, dest
);
1711 * extract the carries
1713 * = only the carries
1716 tcg_gen_xor_i32(t0
, t0
, t1
);
1719 * generate 0x1 where there is no carry
1720 * and for each 0x10, generate a 0x6
1723 tcg_gen_shri_i32(t0
, t0
, 3);
1724 tcg_gen_not_i32(t0
, t0
);
1725 tcg_gen_andi_i32(t0
, t0
, 0x22);
1726 tcg_gen_add_i32(dest
, t0
, t0
);
1727 tcg_gen_add_i32(dest
, dest
, t0
);
1731 * remove the exceeding 0x6
1732 * for digits that have not generated a carry
1735 tcg_gen_sub_i32(dest
, t1
, dest
);
1739 static void bcd_sub(TCGv dest
, TCGv src
)
1744 * dest10 = dest10 - src10 - X
1745 * = bcd_add(dest + 1 - X, 0x199 - src)
1748 /* t0 = 0x066 + (0x199 - src) */
1750 t0
= tcg_temp_new();
1751 tcg_gen_subfi_i32(t0
, 0x1ff, src
);
1753 /* t1 = t0 + dest + 1 - X*/
1755 t1
= tcg_temp_new();
1756 tcg_gen_add_i32(t1
, t0
, dest
);
1757 tcg_gen_addi_i32(t1
, t1
, 1);
1758 tcg_gen_sub_i32(t1
, t1
, QREG_CC_X
);
1760 /* t2 = t0 ^ dest */
1762 t2
= tcg_temp_new();
1763 tcg_gen_xor_i32(t2
, t0
, dest
);
1767 tcg_gen_xor_i32(t0
, t1
, t2
);
1771 * t0 = (t2 >> 2) | (t2 >> 3)
1773 * to fit on 8bit operands, changed in:
1775 * t2 = ~(t0 >> 3) & 0x22
1780 tcg_gen_shri_i32(t2
, t0
, 3);
1781 tcg_gen_not_i32(t2
, t2
);
1782 tcg_gen_andi_i32(t2
, t2
, 0x22);
1783 tcg_gen_add_i32(t0
, t2
, t2
);
1784 tcg_gen_add_i32(t0
, t0
, t2
);
1787 /* return t1 - t0 */
1789 tcg_gen_sub_i32(dest
, t1
, t0
);
1794 static void bcd_flags(TCGv val
)
1796 tcg_gen_andi_i32(QREG_CC_C
, val
, 0x0ff);
1797 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_C
);
1799 tcg_gen_extract_i32(QREG_CC_C
, val
, 8, 1);
1801 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
1804 DISAS_INSN(abcd_reg
)
1809 gen_flush_flags(s
); /* !Z is sticky */
1811 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1812 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1814 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1819 DISAS_INSN(abcd_mem
)
1821 TCGv src
, dest
, addr
;
1823 gen_flush_flags(s
); /* !Z is sticky */
1825 /* Indirect pre-decrement load (mode 4) */
1827 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1828 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1829 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1830 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1834 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1835 EA_STORE
, IS_USER(s
));
1840 DISAS_INSN(sbcd_reg
)
1844 gen_flush_flags(s
); /* !Z is sticky */
1846 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1847 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1851 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1856 DISAS_INSN(sbcd_mem
)
1858 TCGv src
, dest
, addr
;
1860 gen_flush_flags(s
); /* !Z is sticky */
1862 /* Indirect pre-decrement load (mode 4) */
1864 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1865 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1866 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1867 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1871 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1872 EA_STORE
, IS_USER(s
));
1882 gen_flush_flags(s
); /* !Z is sticky */
1884 SRC_EA(env
, src
, OS_BYTE
, 0, &addr
);
1886 dest
= tcg_const_i32(0);
1889 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
1893 tcg_temp_free(dest
);
1906 add
= (insn
& 0x4000) != 0;
1907 opsize
= insn_opsize(insn
);
1908 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
1909 dest
= tcg_temp_new();
1911 SRC_EA(env
, tmp
, opsize
, 1, &addr
);
1915 SRC_EA(env
, src
, opsize
, 1, NULL
);
1918 tcg_gen_add_i32(dest
, tmp
, src
);
1919 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, src
);
1920 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
1922 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, tmp
, src
);
1923 tcg_gen_sub_i32(dest
, tmp
, src
);
1924 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
1926 gen_update_cc_add(dest
, src
, opsize
);
1928 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1930 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
1932 tcg_temp_free(dest
);
1935 /* Reverse the order of the bits in REG. */
1939 reg
= DREG(insn
, 0);
1940 gen_helper_bitrev(reg
, reg
);
1943 DISAS_INSN(bitop_reg
)
1953 if ((insn
& 0x38) != 0)
1957 op
= (insn
>> 6) & 3;
1958 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
1961 src2
= tcg_temp_new();
1962 if (opsize
== OS_BYTE
)
1963 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 7);
1965 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 31);
1967 tmp
= tcg_const_i32(1);
1968 tcg_gen_shl_i32(tmp
, tmp
, src2
);
1969 tcg_temp_free(src2
);
1971 tcg_gen_and_i32(QREG_CC_Z
, src1
, tmp
);
1973 dest
= tcg_temp_new();
1976 tcg_gen_xor_i32(dest
, src1
, tmp
);
1979 tcg_gen_andc_i32(dest
, src1
, tmp
);
1982 tcg_gen_or_i32(dest
, src1
, tmp
);
1989 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1991 tcg_temp_free(dest
);
1997 reg
= DREG(insn
, 0);
1999 gen_helper_sats(reg
, reg
, QREG_CC_V
);
2000 gen_logic_cc(s
, reg
, OS_LONG
);
2003 static void gen_push(DisasContext
*s
, TCGv val
)
2007 tmp
= tcg_temp_new();
2008 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
2009 gen_store(s
, OS_LONG
, tmp
, val
, IS_USER(s
));
2010 tcg_gen_mov_i32(QREG_SP
, tmp
);
2014 static TCGv
mreg(int reg
)
2018 return cpu_dregs
[reg
];
2021 return cpu_aregs
[reg
& 7];
2026 TCGv addr
, incr
, tmp
, r
[16];
2027 int is_load
= (insn
& 0x0400) != 0;
2028 int opsize
= (insn
& 0x40) != 0 ? OS_LONG
: OS_WORD
;
2029 uint16_t mask
= read_im16(env
, s
);
2030 int mode
= extract32(insn
, 3, 3);
2031 int reg0
= REG(insn
, 0);
2034 tmp
= cpu_aregs
[reg0
];
2037 case 0: /* data register direct */
2038 case 1: /* addr register direct */
2043 case 2: /* indirect */
2046 case 3: /* indirect post-increment */
2048 /* post-increment is not allowed */
2053 case 4: /* indirect pre-decrement */
2055 /* pre-decrement is not allowed */
2059 * We want a bare copy of the address reg, without any pre-decrement
2060 * adjustment, as gen_lea would provide.
2065 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
2066 if (IS_NULL_QREG(tmp
)) {
2072 addr
= tcg_temp_new();
2073 tcg_gen_mov_i32(addr
, tmp
);
2074 incr
= tcg_const_i32(opsize_bytes(opsize
));
2077 /* memory to register */
2078 for (i
= 0; i
< 16; i
++) {
2079 if (mask
& (1 << i
)) {
2080 r
[i
] = gen_load(s
, opsize
, addr
, 1, IS_USER(s
));
2081 tcg_gen_add_i32(addr
, addr
, incr
);
2084 for (i
= 0; i
< 16; i
++) {
2085 if (mask
& (1 << i
)) {
2086 tcg_gen_mov_i32(mreg(i
), r
[i
]);
2087 tcg_temp_free(r
[i
]);
2091 /* post-increment: movem (An)+,X */
2092 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2095 /* register to memory */
2097 /* pre-decrement: movem X,-(An) */
2098 for (i
= 15; i
>= 0; i
--) {
2099 if ((mask
<< i
) & 0x8000) {
2100 tcg_gen_sub_i32(addr
, addr
, incr
);
2101 if (reg0
+ 8 == i
&&
2102 m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
)) {
2104 * M68020+: if the addressing register is the
2105 * register moved to memory, the value written
2106 * is the initial value decremented by the size of
2107 * the operation, regardless of how many actual
2108 * stores have been performed until this point.
2109 * M68000/M68010: the value is the initial value.
2111 tmp
= tcg_temp_new();
2112 tcg_gen_sub_i32(tmp
, cpu_aregs
[reg0
], incr
);
2113 gen_store(s
, opsize
, addr
, tmp
, IS_USER(s
));
2116 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2120 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2122 for (i
= 0; i
< 16; i
++) {
2123 if (mask
& (1 << i
)) {
2124 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2125 tcg_gen_add_i32(addr
, addr
, incr
);
2131 tcg_temp_free(incr
);
2132 tcg_temp_free(addr
);
2144 displ
= read_im16(env
, s
);
2146 addr
= AREG(insn
, 0);
2147 reg
= DREG(insn
, 9);
2149 abuf
= tcg_temp_new();
2150 tcg_gen_addi_i32(abuf
, addr
, displ
);
2151 dbuf
= tcg_temp_new();
2160 for ( ; i
> 0 ; i
--) {
2161 tcg_gen_shri_i32(dbuf
, reg
, (i
- 1) * 8);
2162 tcg_gen_qemu_st8(dbuf
, abuf
, IS_USER(s
));
2164 tcg_gen_addi_i32(abuf
, abuf
, 2);
2168 for ( ; i
> 0 ; i
--) {
2169 tcg_gen_qemu_ld8u(dbuf
, abuf
, IS_USER(s
));
2170 tcg_gen_deposit_i32(reg
, reg
, dbuf
, (i
- 1) * 8, 8);
2172 tcg_gen_addi_i32(abuf
, abuf
, 2);
2176 tcg_temp_free(abuf
);
2177 tcg_temp_free(dbuf
);
2180 DISAS_INSN(bitop_im
)
2190 if ((insn
& 0x38) != 0)
2194 op
= (insn
>> 6) & 3;
2196 bitnum
= read_im16(env
, s
);
2197 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
2198 if (bitnum
& 0xfe00) {
2199 disas_undef(env
, s
, insn
);
2203 if (bitnum
& 0xff00) {
2204 disas_undef(env
, s
, insn
);
2209 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
2212 if (opsize
== OS_BYTE
)
2218 tcg_gen_andi_i32(QREG_CC_Z
, src1
, mask
);
2221 tmp
= tcg_temp_new();
2224 tcg_gen_xori_i32(tmp
, src1
, mask
);
2227 tcg_gen_andi_i32(tmp
, src1
, ~mask
);
2230 tcg_gen_ori_i32(tmp
, src1
, mask
);
2235 DEST_EA(env
, insn
, opsize
, tmp
, &addr
);
2240 static TCGv
gen_get_ccr(DisasContext
*s
)
2245 dest
= tcg_temp_new();
2246 gen_helper_get_ccr(dest
, cpu_env
);
2250 static TCGv
gen_get_sr(DisasContext
*s
)
2255 ccr
= gen_get_ccr(s
);
2256 sr
= tcg_temp_new();
2257 tcg_gen_andi_i32(sr
, QREG_SR
, 0xffe0);
2258 tcg_gen_or_i32(sr
, sr
, ccr
);
2263 static void gen_set_sr_im(DisasContext
*s
, uint16_t val
, int ccr_only
)
2266 tcg_gen_movi_i32(QREG_CC_C
, val
& CCF_C
? 1 : 0);
2267 tcg_gen_movi_i32(QREG_CC_V
, val
& CCF_V
? -1 : 0);
2268 tcg_gen_movi_i32(QREG_CC_Z
, val
& CCF_Z
? 0 : 1);
2269 tcg_gen_movi_i32(QREG_CC_N
, val
& CCF_N
? -1 : 0);
2270 tcg_gen_movi_i32(QREG_CC_X
, val
& CCF_X
? 1 : 0);
2272 TCGv sr
= tcg_const_i32(val
);
2273 gen_helper_set_sr(cpu_env
, sr
);
2276 set_cc_op(s
, CC_OP_FLAGS
);
2279 static void gen_set_sr(DisasContext
*s
, TCGv val
, int ccr_only
)
2282 gen_helper_set_ccr(cpu_env
, val
);
2284 gen_helper_set_sr(cpu_env
, val
);
2286 set_cc_op(s
, CC_OP_FLAGS
);
2289 static void gen_move_to_sr(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
2292 if ((insn
& 0x3f) == 0x3c) {
2294 val
= read_im16(env
, s
);
2295 gen_set_sr_im(s
, val
, ccr_only
);
2298 SRC_EA(env
, src
, OS_WORD
, 0, NULL
);
2299 gen_set_sr(s
, src
, ccr_only
);
2303 DISAS_INSN(arith_im
)
2311 bool with_SR
= ((insn
& 0x3f) == 0x3c);
2313 op
= (insn
>> 9) & 7;
2314 opsize
= insn_opsize(insn
);
2317 im
= tcg_const_i32((int8_t)read_im8(env
, s
));
2320 im
= tcg_const_i32((int16_t)read_im16(env
, s
));
2323 im
= tcg_const_i32(read_im32(env
, s
));
2326 g_assert_not_reached();
2330 /* SR/CCR can only be used with andi/eori/ori */
2331 if (op
== 2 || op
== 3 || op
== 6) {
2332 disas_undef(env
, s
, insn
);
2337 src1
= gen_get_ccr(s
);
2341 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2344 src1
= gen_get_sr(s
);
2347 /* OS_LONG; others already g_assert_not_reached. */
2348 disas_undef(env
, s
, insn
);
2352 SRC_EA(env
, src1
, opsize
, 1, (op
== 6) ? NULL
: &addr
);
2354 dest
= tcg_temp_new();
2357 tcg_gen_or_i32(dest
, src1
, im
);
2359 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2361 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2362 gen_logic_cc(s
, dest
, opsize
);
2366 tcg_gen_and_i32(dest
, src1
, im
);
2368 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2370 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2371 gen_logic_cc(s
, dest
, opsize
);
2375 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, src1
, im
);
2376 tcg_gen_sub_i32(dest
, src1
, im
);
2377 gen_update_cc_add(dest
, im
, opsize
);
2378 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2379 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2382 tcg_gen_add_i32(dest
, src1
, im
);
2383 gen_update_cc_add(dest
, im
, opsize
);
2384 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, im
);
2385 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2386 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2389 tcg_gen_xor_i32(dest
, src1
, im
);
2391 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2393 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2394 gen_logic_cc(s
, dest
, opsize
);
2398 gen_update_cc_cmp(s
, src1
, im
, opsize
);
2404 tcg_temp_free(dest
);
2416 switch ((insn
>> 9) & 3) {
2430 g_assert_not_reached();
2433 ext
= read_im16(env
, s
);
2435 /* cas Dc,Du,<EA> */
2437 addr
= gen_lea(env
, s
, insn
, opsize
);
2438 if (IS_NULL_QREG(addr
)) {
2443 cmp
= gen_extend(s
, DREG(ext
, 0), opsize
, 1);
2446 * if <EA> == Dc then
2448 * Dc = <EA> (because <EA> == Dc)
2453 load
= tcg_temp_new();
2454 tcg_gen_atomic_cmpxchg_i32(load
, addr
, cmp
, DREG(ext
, 6),
2456 /* update flags before setting cmp to load */
2457 gen_update_cc_cmp(s
, load
, cmp
, opsize
);
2458 gen_partset_reg(opsize
, DREG(ext
, 0), load
);
2460 tcg_temp_free(load
);
2462 switch (extract32(insn
, 3, 3)) {
2463 case 3: /* Indirect postincrement. */
2464 tcg_gen_addi_i32(AREG(insn
, 0), addr
, opsize_bytes(opsize
));
2466 case 4: /* Indirect predecrememnt. */
2467 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2474 uint16_t ext1
, ext2
;
2478 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2480 ext1
= read_im16(env
, s
);
2482 if (ext1
& 0x8000) {
2483 /* Address Register */
2484 addr1
= AREG(ext1
, 12);
2487 addr1
= DREG(ext1
, 12);
2490 ext2
= read_im16(env
, s
);
2491 if (ext2
& 0x8000) {
2492 /* Address Register */
2493 addr2
= AREG(ext2
, 12);
2496 addr2
= DREG(ext2
, 12);
2500 * if (R1) == Dc1 && (R2) == Dc2 then
2508 regs
= tcg_const_i32(REG(ext2
, 6) |
2509 (REG(ext1
, 6) << 3) |
2510 (REG(ext2
, 0) << 6) |
2511 (REG(ext1
, 0) << 9));
2512 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2513 gen_helper_exit_atomic(cpu_env
);
2515 gen_helper_cas2w(cpu_env
, regs
, addr1
, addr2
);
2517 tcg_temp_free(regs
);
2519 /* Note that cas2w also assigned to env->cc_op. */
2520 s
->cc_op
= CC_OP_CMPW
;
2521 s
->cc_op_synced
= 1;
2526 uint16_t ext1
, ext2
;
2527 TCGv addr1
, addr2
, regs
;
2529 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2531 ext1
= read_im16(env
, s
);
2533 if (ext1
& 0x8000) {
2534 /* Address Register */
2535 addr1
= AREG(ext1
, 12);
2538 addr1
= DREG(ext1
, 12);
2541 ext2
= read_im16(env
, s
);
2542 if (ext2
& 0x8000) {
2543 /* Address Register */
2544 addr2
= AREG(ext2
, 12);
2547 addr2
= DREG(ext2
, 12);
2551 * if (R1) == Dc1 && (R2) == Dc2 then
2559 regs
= tcg_const_i32(REG(ext2
, 6) |
2560 (REG(ext1
, 6) << 3) |
2561 (REG(ext2
, 0) << 6) |
2562 (REG(ext1
, 0) << 9));
2563 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2564 gen_helper_cas2l_parallel(cpu_env
, regs
, addr1
, addr2
);
2566 gen_helper_cas2l(cpu_env
, regs
, addr1
, addr2
);
2568 tcg_temp_free(regs
);
2570 /* Note that cas2l also assigned to env->cc_op. */
2571 s
->cc_op
= CC_OP_CMPL
;
2572 s
->cc_op_synced
= 1;
2579 reg
= DREG(insn
, 0);
2580 tcg_gen_bswap32_i32(reg
, reg
);
2590 switch (insn
>> 12) {
2591 case 1: /* move.b */
2594 case 2: /* move.l */
2597 case 3: /* move.w */
2603 SRC_EA(env
, src
, opsize
, 1, NULL
);
2604 op
= (insn
>> 6) & 7;
2607 /* The value will already have been sign extended. */
2608 dest
= AREG(insn
, 9);
2609 tcg_gen_mov_i32(dest
, src
);
2613 dest_ea
= ((insn
>> 9) & 7) | (op
<< 3);
2614 DEST_EA(env
, dest_ea
, opsize
, src
, NULL
);
2615 /* This will be correct because loads sign extend. */
2616 gen_logic_cc(s
, src
, opsize
);
2627 opsize
= insn_opsize(insn
);
2628 SRC_EA(env
, src
, opsize
, 1, &addr
);
2630 gen_flush_flags(s
); /* compute old Z */
2633 * Perform subtract with borrow.
2634 * (X, N) = -(src + X);
2637 z
= tcg_const_i32(0);
2638 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, z
, QREG_CC_X
, z
);
2639 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, z
, z
, QREG_CC_N
, QREG_CC_X
);
2641 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
2643 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
2646 * Compute signed-overflow for negation. The normal formula for
2647 * subtraction is (res ^ src) & (src ^ dest), but with dest==0
2648 * this simplifies to res & src.
2651 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_N
, src
);
2653 /* Copy the rest of the results into place. */
2654 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
2655 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
2657 set_cc_op(s
, CC_OP_FLAGS
);
2659 /* result is in QREG_CC_N */
2661 DEST_EA(env
, insn
, opsize
, QREG_CC_N
, &addr
);
2669 reg
= AREG(insn
, 9);
2670 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2671 if (IS_NULL_QREG(tmp
)) {
2675 tcg_gen_mov_i32(reg
, tmp
);
2683 zero
= tcg_const_i32(0);
2685 opsize
= insn_opsize(insn
);
2686 DEST_EA(env
, insn
, opsize
, zero
, NULL
);
2687 gen_logic_cc(s
, zero
, opsize
);
2688 tcg_temp_free(zero
);
2691 DISAS_INSN(move_from_ccr
)
2695 ccr
= gen_get_ccr(s
);
2696 DEST_EA(env
, insn
, OS_WORD
, ccr
, NULL
);
2706 opsize
= insn_opsize(insn
);
2707 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2708 dest
= tcg_temp_new();
2709 tcg_gen_neg_i32(dest
, src1
);
2710 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2711 gen_update_cc_add(dest
, src1
, opsize
);
2712 tcg_gen_setcondi_i32(TCG_COND_NE
, QREG_CC_X
, dest
, 0);
2713 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2714 tcg_temp_free(dest
);
2717 DISAS_INSN(move_to_ccr
)
2719 gen_move_to_sr(env
, s
, insn
, true);
2729 opsize
= insn_opsize(insn
);
2730 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2731 dest
= tcg_temp_new();
2732 tcg_gen_not_i32(dest
, src1
);
2733 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2734 gen_logic_cc(s
, dest
, opsize
);
2743 src1
= tcg_temp_new();
2744 src2
= tcg_temp_new();
2745 reg
= DREG(insn
, 0);
2746 tcg_gen_shli_i32(src1
, reg
, 16);
2747 tcg_gen_shri_i32(src2
, reg
, 16);
2748 tcg_gen_or_i32(reg
, src1
, src2
);
2749 tcg_temp_free(src2
);
2750 tcg_temp_free(src1
);
2751 gen_logic_cc(s
, reg
, OS_LONG
);
2756 gen_exception(s
, s
->base
.pc_next
, EXCP_DEBUG
);
2763 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2764 if (IS_NULL_QREG(tmp
)) {
2777 reg
= DREG(insn
, 0);
2778 op
= (insn
>> 6) & 7;
2779 tmp
= tcg_temp_new();
2781 tcg_gen_ext16s_i32(tmp
, reg
);
2783 tcg_gen_ext8s_i32(tmp
, reg
);
2785 gen_partset_reg(OS_WORD
, reg
, tmp
);
2787 tcg_gen_mov_i32(reg
, tmp
);
2788 gen_logic_cc(s
, tmp
, OS_LONG
);
2797 opsize
= insn_opsize(insn
);
2798 SRC_EA(env
, tmp
, opsize
, 1, NULL
);
2799 gen_logic_cc(s
, tmp
, opsize
);
2804 /* Implemented as a NOP. */
2809 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2812 /* ??? This should be atomic. */
2819 dest
= tcg_temp_new();
2820 SRC_EA(env
, src1
, OS_BYTE
, 1, &addr
);
2821 gen_logic_cc(s
, src1
, OS_BYTE
);
2822 tcg_gen_ori_i32(dest
, src1
, 0x80);
2823 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
2824 tcg_temp_free(dest
);
2833 ext
= read_im16(env
, s
);
2838 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
2839 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2843 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2846 tcg_gen_muls2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2848 tcg_gen_mulu2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2850 /* if Dl == Dh, 68040 returns low word */
2851 tcg_gen_mov_i32(DREG(ext
, 0), QREG_CC_N
);
2852 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_Z
);
2853 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
);
2855 tcg_gen_movi_i32(QREG_CC_V
, 0);
2856 tcg_gen_movi_i32(QREG_CC_C
, 0);
2858 set_cc_op(s
, CC_OP_FLAGS
);
2861 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2862 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
2863 tcg_gen_movi_i32(QREG_CC_C
, 0);
2865 tcg_gen_muls2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2866 /* QREG_CC_V is -(QREG_CC_V != (QREG_CC_N >> 31)) */
2867 tcg_gen_sari_i32(QREG_CC_Z
, QREG_CC_N
, 31);
2868 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_Z
);
2870 tcg_gen_mulu2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2871 /* QREG_CC_V is -(QREG_CC_V != 0), use QREG_CC_C as 0 */
2872 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_C
);
2874 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
2875 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_N
);
2877 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
2879 set_cc_op(s
, CC_OP_FLAGS
);
2882 * The upper 32 bits of the product are discarded, so
2883 * muls.l and mulu.l are functionally equivalent.
2885 tcg_gen_mul_i32(DREG(ext
, 12), src1
, DREG(ext
, 12));
2886 gen_logic_cc(s
, DREG(ext
, 12), OS_LONG
);
2890 static void gen_link(DisasContext
*s
, uint16_t insn
, int32_t offset
)
2895 reg
= AREG(insn
, 0);
2896 tmp
= tcg_temp_new();
2897 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
2898 gen_store(s
, OS_LONG
, tmp
, reg
, IS_USER(s
));
2899 if ((insn
& 7) != 7) {
2900 tcg_gen_mov_i32(reg
, tmp
);
2902 tcg_gen_addi_i32(QREG_SP
, tmp
, offset
);
2910 offset
= read_im16(env
, s
);
2911 gen_link(s
, insn
, offset
);
2918 offset
= read_im32(env
, s
);
2919 gen_link(s
, insn
, offset
);
2928 src
= tcg_temp_new();
2929 reg
= AREG(insn
, 0);
2930 tcg_gen_mov_i32(src
, reg
);
2931 tmp
= gen_load(s
, OS_LONG
, src
, 0, IS_USER(s
));
2932 tcg_gen_mov_i32(reg
, tmp
);
2933 tcg_gen_addi_i32(QREG_SP
, src
, 4);
2938 #if defined(CONFIG_SOFTMMU)
2942 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2946 gen_helper_reset(cpu_env
);
2957 int16_t offset
= read_im16(env
, s
);
2959 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
2960 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, offset
+ 4);
2970 sp
= tcg_temp_new();
2971 ccr
= gen_load(s
, OS_WORD
, QREG_SP
, 0, IS_USER(s
));
2972 tcg_gen_addi_i32(sp
, QREG_SP
, 2);
2973 tmp
= gen_load(s
, OS_LONG
, sp
, 0, IS_USER(s
));
2974 tcg_gen_addi_i32(QREG_SP
, sp
, 4);
2977 gen_set_sr(s
, ccr
, true);
2987 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
2988 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, 4);
2997 * Load the target address first to ensure correct exception
3000 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
3001 if (IS_NULL_QREG(tmp
)) {
3005 if ((insn
& 0x40) == 0) {
3007 gen_push(s
, tcg_const_i32(s
->pc
));
3021 if ((insn
& 070) == 010) {
3022 /* Operation on address register is always long. */
3025 opsize
= insn_opsize(insn
);
3027 SRC_EA(env
, src
, opsize
, 1, &addr
);
3028 imm
= (insn
>> 9) & 7;
3032 val
= tcg_const_i32(imm
);
3033 dest
= tcg_temp_new();
3034 tcg_gen_mov_i32(dest
, src
);
3035 if ((insn
& 0x38) == 0x08) {
3037 * Don't update condition codes if the destination is an
3040 if (insn
& 0x0100) {
3041 tcg_gen_sub_i32(dest
, dest
, val
);
3043 tcg_gen_add_i32(dest
, dest
, val
);
3046 if (insn
& 0x0100) {
3047 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
3048 tcg_gen_sub_i32(dest
, dest
, val
);
3049 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
3051 tcg_gen_add_i32(dest
, dest
, val
);
3052 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
3053 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
3055 gen_update_cc_add(dest
, val
, opsize
);
3058 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3059 tcg_temp_free(dest
);
3065 case 2: /* One extension word. */
3068 case 3: /* Two extension words. */
3071 case 4: /* No extension words. */
3074 disas_undef(env
, s
, insn
);
3085 op
= (insn
>> 8) & 0xf;
3086 offset
= (int8_t)insn
;
3088 offset
= (int16_t)read_im16(env
, s
);
3089 } else if (offset
== -1) {
3090 offset
= read_im32(env
, s
);
3094 gen_push(s
, tcg_const_i32(s
->pc
));
3098 TCGLabel
*l1
= gen_new_label();
3099 gen_jmpcc(s
, ((insn
>> 8) & 0xf) ^ 1, l1
);
3100 gen_jmp_tb(s
, 1, base
+ offset
);
3102 gen_jmp_tb(s
, 0, s
->pc
);
3104 /* Unconditional branch. */
3106 gen_jmp_tb(s
, 0, base
+ offset
);
3112 tcg_gen_movi_i32(DREG(insn
, 9), (int8_t)insn
);
3113 gen_logic_cc(s
, DREG(insn
, 9), OS_LONG
);
3126 SRC_EA(env
, src
, opsize
, (insn
& 0x80) == 0, NULL
);
3127 reg
= DREG(insn
, 9);
3128 tcg_gen_mov_i32(reg
, src
);
3129 gen_logic_cc(s
, src
, opsize
);
3140 opsize
= insn_opsize(insn
);
3141 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 0);
3142 dest
= tcg_temp_new();
3144 SRC_EA(env
, src
, opsize
, 0, &addr
);
3145 tcg_gen_or_i32(dest
, src
, reg
);
3146 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3148 SRC_EA(env
, src
, opsize
, 0, NULL
);
3149 tcg_gen_or_i32(dest
, src
, reg
);
3150 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
3152 gen_logic_cc(s
, dest
, opsize
);
3153 tcg_temp_free(dest
);
3161 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3162 reg
= AREG(insn
, 9);
3163 tcg_gen_sub_i32(reg
, reg
, src
);
3166 static inline void gen_subx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3170 gen_flush_flags(s
); /* compute old Z */
3173 * Perform subtract with borrow.
3174 * (X, N) = dest - (src + X);
3177 tmp
= tcg_const_i32(0);
3178 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, tmp
, QREG_CC_X
, tmp
);
3179 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, dest
, tmp
, QREG_CC_N
, QREG_CC_X
);
3180 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3181 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
3183 /* Compute signed-overflow for subtract. */
3185 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, dest
);
3186 tcg_gen_xor_i32(tmp
, dest
, src
);
3187 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3190 /* Copy the rest of the results into place. */
3191 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3192 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3194 set_cc_op(s
, CC_OP_FLAGS
);
3196 /* result is in QREG_CC_N */
3199 DISAS_INSN(subx_reg
)
3205 opsize
= insn_opsize(insn
);
3207 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3208 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3210 gen_subx(s
, src
, dest
, opsize
);
3212 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3215 DISAS_INSN(subx_mem
)
3223 opsize
= insn_opsize(insn
);
3225 addr_src
= AREG(insn
, 0);
3226 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3227 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3229 addr_dest
= AREG(insn
, 9);
3230 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3231 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3233 gen_subx(s
, src
, dest
, opsize
);
3235 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3237 tcg_temp_free(dest
);
3246 val
= (insn
>> 9) & 7;
3249 src
= tcg_const_i32(val
);
3250 gen_logic_cc(s
, src
, OS_LONG
);
3251 DEST_EA(env
, insn
, OS_LONG
, src
, NULL
);
3261 opsize
= insn_opsize(insn
);
3262 SRC_EA(env
, src
, opsize
, 1, NULL
);
3263 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3264 gen_update_cc_cmp(s
, reg
, src
, opsize
);
3278 SRC_EA(env
, src
, opsize
, 1, NULL
);
3279 reg
= AREG(insn
, 9);
3280 gen_update_cc_cmp(s
, reg
, src
, OS_LONG
);
3285 int opsize
= insn_opsize(insn
);
3288 /* Post-increment load (mode 3) from Ay. */
3289 src
= gen_ea_mode(env
, s
, 3, REG(insn
, 0), opsize
,
3290 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3291 /* Post-increment load (mode 3) from Ax. */
3292 dst
= gen_ea_mode(env
, s
, 3, REG(insn
, 9), opsize
,
3293 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3295 gen_update_cc_cmp(s
, dst
, src
, opsize
);
3305 opsize
= insn_opsize(insn
);
3307 SRC_EA(env
, src
, opsize
, 0, &addr
);
3308 dest
= tcg_temp_new();
3309 tcg_gen_xor_i32(dest
, src
, DREG(insn
, 9));
3310 gen_logic_cc(s
, dest
, opsize
);
3311 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3312 tcg_temp_free(dest
);
3315 static void do_exg(TCGv reg1
, TCGv reg2
)
3317 TCGv temp
= tcg_temp_new();
3318 tcg_gen_mov_i32(temp
, reg1
);
3319 tcg_gen_mov_i32(reg1
, reg2
);
3320 tcg_gen_mov_i32(reg2
, temp
);
3321 tcg_temp_free(temp
);
3326 /* exchange Dx and Dy */
3327 do_exg(DREG(insn
, 9), DREG(insn
, 0));
3332 /* exchange Ax and Ay */
3333 do_exg(AREG(insn
, 9), AREG(insn
, 0));
3338 /* exchange Dx and Ay */
3339 do_exg(DREG(insn
, 9), AREG(insn
, 0));
3350 dest
= tcg_temp_new();
3352 opsize
= insn_opsize(insn
);
3353 reg
= DREG(insn
, 9);
3355 SRC_EA(env
, src
, opsize
, 0, &addr
);
3356 tcg_gen_and_i32(dest
, src
, reg
);
3357 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3359 SRC_EA(env
, src
, opsize
, 0, NULL
);
3360 tcg_gen_and_i32(dest
, src
, reg
);
3361 gen_partset_reg(opsize
, reg
, dest
);
3363 gen_logic_cc(s
, dest
, opsize
);
3364 tcg_temp_free(dest
);
3372 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3373 reg
= AREG(insn
, 9);
3374 tcg_gen_add_i32(reg
, reg
, src
);
3377 static inline void gen_addx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3381 gen_flush_flags(s
); /* compute old Z */
3384 * Perform addition with carry.
3385 * (X, N) = src + dest + X;
3388 tmp
= tcg_const_i32(0);
3389 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_X
, tmp
, dest
, tmp
);
3390 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_N
, QREG_CC_X
, src
, tmp
);
3391 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3393 /* Compute signed-overflow for addition. */
3395 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3396 tcg_gen_xor_i32(tmp
, dest
, src
);
3397 tcg_gen_andc_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3400 /* Copy the rest of the results into place. */
3401 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3402 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3404 set_cc_op(s
, CC_OP_FLAGS
);
3406 /* result is in QREG_CC_N */
3409 DISAS_INSN(addx_reg
)
3415 opsize
= insn_opsize(insn
);
3417 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3418 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3420 gen_addx(s
, src
, dest
, opsize
);
3422 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3425 DISAS_INSN(addx_mem
)
3433 opsize
= insn_opsize(insn
);
3435 addr_src
= AREG(insn
, 0);
3436 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3437 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3439 addr_dest
= AREG(insn
, 9);
3440 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3441 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3443 gen_addx(s
, src
, dest
, opsize
);
3445 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3447 tcg_temp_free(dest
);
3451 static inline void shift_im(DisasContext
*s
, uint16_t insn
, int opsize
)
3453 int count
= (insn
>> 9) & 7;
3454 int logical
= insn
& 8;
3455 int left
= insn
& 0x100;
3456 int bits
= opsize_bytes(opsize
) * 8;
3457 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3463 tcg_gen_movi_i32(QREG_CC_V
, 0);
3465 tcg_gen_shri_i32(QREG_CC_C
, reg
, bits
- count
);
3466 tcg_gen_shli_i32(QREG_CC_N
, reg
, count
);
3469 * Note that ColdFire always clears V (done above),
3470 * while M68000 sets if the most significant bit is changed at
3471 * any time during the shift operation.
3473 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3474 /* if shift count >= bits, V is (reg != 0) */
3475 if (count
>= bits
) {
3476 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, reg
, QREG_CC_V
);
3478 TCGv t0
= tcg_temp_new();
3479 tcg_gen_sari_i32(QREG_CC_V
, reg
, bits
- 1);
3480 tcg_gen_sari_i32(t0
, reg
, bits
- count
- 1);
3481 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, t0
);
3484 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3487 tcg_gen_shri_i32(QREG_CC_C
, reg
, count
- 1);
3489 tcg_gen_shri_i32(QREG_CC_N
, reg
, count
);
3491 tcg_gen_sari_i32(QREG_CC_N
, reg
, count
);
3495 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3496 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3497 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3498 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3500 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3501 set_cc_op(s
, CC_OP_FLAGS
);
3504 static inline void shift_reg(DisasContext
*s
, uint16_t insn
, int opsize
)
3506 int logical
= insn
& 8;
3507 int left
= insn
& 0x100;
3508 int bits
= opsize_bytes(opsize
) * 8;
3509 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3513 t64
= tcg_temp_new_i64();
3514 s64
= tcg_temp_new_i64();
3515 s32
= tcg_temp_new();
3518 * Note that m68k truncates the shift count modulo 64, not 32.
3519 * In addition, a 64-bit shift makes it easy to find "the last
3520 * bit shifted out", for the carry flag.
3522 tcg_gen_andi_i32(s32
, DREG(insn
, 9), 63);
3523 tcg_gen_extu_i32_i64(s64
, s32
);
3524 tcg_gen_extu_i32_i64(t64
, reg
);
3526 /* Optimistically set V=0. Also used as a zero source below. */
3527 tcg_gen_movi_i32(QREG_CC_V
, 0);
3529 tcg_gen_shl_i64(t64
, t64
, s64
);
3531 if (opsize
== OS_LONG
) {
3532 tcg_gen_extr_i64_i32(QREG_CC_N
, QREG_CC_C
, t64
);
3533 /* Note that C=0 if shift count is 0, and we get that for free. */
3535 TCGv zero
= tcg_const_i32(0);
3536 tcg_gen_extrl_i64_i32(QREG_CC_N
, t64
);
3537 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_N
, bits
);
3538 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3539 s32
, zero
, zero
, QREG_CC_C
);
3540 tcg_temp_free(zero
);
3542 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3544 /* X = C, but only if the shift count was non-zero. */
3545 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3546 QREG_CC_C
, QREG_CC_X
);
3549 * M68000 sets V if the most significant bit is changed at
3550 * any time during the shift operation. Do this via creating
3551 * an extension of the sign bit, comparing, and discarding
3552 * the bits below the sign bit. I.e.
3553 * int64_t s = (intN_t)reg;
3554 * int64_t t = (int64_t)(intN_t)reg << count;
3555 * V = ((s ^ t) & (-1 << (bits - 1))) != 0
3557 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3558 TCGv_i64 tt
= tcg_const_i64(32);
3559 /* if shift is greater than 32, use 32 */
3560 tcg_gen_movcond_i64(TCG_COND_GT
, s64
, s64
, tt
, tt
, s64
);
3561 tcg_temp_free_i64(tt
);
3562 /* Sign extend the input to 64 bits; re-do the shift. */
3563 tcg_gen_ext_i32_i64(t64
, reg
);
3564 tcg_gen_shl_i64(s64
, t64
, s64
);
3565 /* Clear all bits that are unchanged. */
3566 tcg_gen_xor_i64(t64
, t64
, s64
);
3567 /* Ignore the bits below the sign bit. */
3568 tcg_gen_andi_i64(t64
, t64
, -1ULL << (bits
- 1));
3569 /* If any bits remain set, we have overflow. */
3570 tcg_gen_setcondi_i64(TCG_COND_NE
, t64
, t64
, 0);
3571 tcg_gen_extrl_i64_i32(QREG_CC_V
, t64
);
3572 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3575 tcg_gen_shli_i64(t64
, t64
, 32);
3577 tcg_gen_shr_i64(t64
, t64
, s64
);
3579 tcg_gen_sar_i64(t64
, t64
, s64
);
3581 tcg_gen_extr_i64_i32(QREG_CC_C
, QREG_CC_N
, t64
);
3583 /* Note that C=0 if shift count is 0, and we get that for free. */
3584 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_C
, 31);
3586 /* X = C, but only if the shift count was non-zero. */
3587 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3588 QREG_CC_C
, QREG_CC_X
);
3590 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3591 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3594 tcg_temp_free_i64(s64
);
3595 tcg_temp_free_i64(t64
);
3597 /* Write back the result. */
3598 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3599 set_cc_op(s
, CC_OP_FLAGS
);
3602 DISAS_INSN(shift8_im
)
3604 shift_im(s
, insn
, OS_BYTE
);
3607 DISAS_INSN(shift16_im
)
3609 shift_im(s
, insn
, OS_WORD
);
3612 DISAS_INSN(shift_im
)
3614 shift_im(s
, insn
, OS_LONG
);
3617 DISAS_INSN(shift8_reg
)
3619 shift_reg(s
, insn
, OS_BYTE
);
3622 DISAS_INSN(shift16_reg
)
3624 shift_reg(s
, insn
, OS_WORD
);
3627 DISAS_INSN(shift_reg
)
3629 shift_reg(s
, insn
, OS_LONG
);
3632 DISAS_INSN(shift_mem
)
3634 int logical
= insn
& 8;
3635 int left
= insn
& 0x100;
3639 SRC_EA(env
, src
, OS_WORD
, !logical
, &addr
);
3640 tcg_gen_movi_i32(QREG_CC_V
, 0);
3642 tcg_gen_shri_i32(QREG_CC_C
, src
, 15);
3643 tcg_gen_shli_i32(QREG_CC_N
, src
, 1);
3646 * Note that ColdFire always clears V,
3647 * while M68000 sets if the most significant bit is changed at
3648 * any time during the shift operation
3650 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3651 src
= gen_extend(s
, src
, OS_WORD
, 1);
3652 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3655 tcg_gen_mov_i32(QREG_CC_C
, src
);
3657 tcg_gen_shri_i32(QREG_CC_N
, src
, 1);
3659 tcg_gen_sari_i32(QREG_CC_N
, src
, 1);
3663 gen_ext(QREG_CC_N
, QREG_CC_N
, OS_WORD
, 1);
3664 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3665 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3666 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3668 DEST_EA(env
, insn
, OS_WORD
, QREG_CC_N
, &addr
);
3669 set_cc_op(s
, CC_OP_FLAGS
);
3672 static void rotate(TCGv reg
, TCGv shift
, int left
, int size
)
3676 /* Replicate the 8-bit input so that a 32-bit rotate works. */
3677 tcg_gen_ext8u_i32(reg
, reg
);
3678 tcg_gen_muli_i32(reg
, reg
, 0x01010101);
3681 /* Replicate the 16-bit input so that a 32-bit rotate works. */
3682 tcg_gen_deposit_i32(reg
, reg
, reg
, 16, 16);
3687 tcg_gen_rotl_i32(reg
, reg
, shift
);
3689 tcg_gen_rotr_i32(reg
, reg
, shift
);
3697 tcg_gen_ext8s_i32(reg
, reg
);
3700 tcg_gen_ext16s_i32(reg
, reg
);
3706 /* QREG_CC_X is not affected */
3708 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3709 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3712 tcg_gen_andi_i32(QREG_CC_C
, reg
, 1);
3714 tcg_gen_shri_i32(QREG_CC_C
, reg
, 31);
3717 tcg_gen_movi_i32(QREG_CC_V
, 0); /* always cleared */
3720 static void rotate_x_flags(TCGv reg
, TCGv X
, int size
)
3724 tcg_gen_ext8s_i32(reg
, reg
);
3727 tcg_gen_ext16s_i32(reg
, reg
);
3732 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3733 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3734 tcg_gen_mov_i32(QREG_CC_X
, X
);
3735 tcg_gen_mov_i32(QREG_CC_C
, X
);
3736 tcg_gen_movi_i32(QREG_CC_V
, 0);
3739 /* Result of rotate_x() is valid if 0 <= shift <= size */
3740 static TCGv
rotate_x(TCGv reg
, TCGv shift
, int left
, int size
)
3742 TCGv X
, shl
, shr
, shx
, sz
, zero
;
3744 sz
= tcg_const_i32(size
);
3746 shr
= tcg_temp_new();
3747 shl
= tcg_temp_new();
3748 shx
= tcg_temp_new();
3750 tcg_gen_mov_i32(shl
, shift
); /* shl = shift */
3751 tcg_gen_movi_i32(shr
, size
+ 1);
3752 tcg_gen_sub_i32(shr
, shr
, shift
); /* shr = size + 1 - shift */
3753 tcg_gen_subi_i32(shx
, shift
, 1); /* shx = shift - 1 */
3754 /* shx = shx < 0 ? size : shx; */
3755 zero
= tcg_const_i32(0);
3756 tcg_gen_movcond_i32(TCG_COND_LT
, shx
, shx
, zero
, sz
, shx
);
3757 tcg_temp_free(zero
);
3759 tcg_gen_mov_i32(shr
, shift
); /* shr = shift */
3760 tcg_gen_movi_i32(shl
, size
+ 1);
3761 tcg_gen_sub_i32(shl
, shl
, shift
); /* shl = size + 1 - shift */
3762 tcg_gen_sub_i32(shx
, sz
, shift
); /* shx = size - shift */
3764 tcg_temp_free_i32(sz
);
3766 /* reg = (reg << shl) | (reg >> shr) | (x << shx); */
3768 tcg_gen_shl_i32(shl
, reg
, shl
);
3769 tcg_gen_shr_i32(shr
, reg
, shr
);
3770 tcg_gen_or_i32(reg
, shl
, shr
);
3773 tcg_gen_shl_i32(shx
, QREG_CC_X
, shx
);
3774 tcg_gen_or_i32(reg
, reg
, shx
);
3777 /* X = (reg >> size) & 1 */
3780 tcg_gen_extract_i32(X
, reg
, size
, 1);
3785 /* Result of rotate32_x() is valid if 0 <= shift < 33 */
3786 static TCGv
rotate32_x(TCGv reg
, TCGv shift
, int left
)
3788 TCGv_i64 t0
, shift64
;
3789 TCGv X
, lo
, hi
, zero
;
3791 shift64
= tcg_temp_new_i64();
3792 tcg_gen_extu_i32_i64(shift64
, shift
);
3794 t0
= tcg_temp_new_i64();
3797 lo
= tcg_temp_new();
3798 hi
= tcg_temp_new();
3801 /* create [reg:X:..] */
3803 tcg_gen_shli_i32(lo
, QREG_CC_X
, 31);
3804 tcg_gen_concat_i32_i64(t0
, lo
, reg
);
3808 tcg_gen_rotl_i64(t0
, t0
, shift64
);
3809 tcg_temp_free_i64(shift64
);
3811 /* result is [reg:..:reg:X] */
3813 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3814 tcg_gen_andi_i32(X
, lo
, 1);
3816 tcg_gen_shri_i32(lo
, lo
, 1);
3818 /* create [..:X:reg] */
3820 tcg_gen_concat_i32_i64(t0
, reg
, QREG_CC_X
);
3822 tcg_gen_rotr_i64(t0
, t0
, shift64
);
3823 tcg_temp_free_i64(shift64
);
3825 /* result is value: [X:reg:..:reg] */
3827 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3831 tcg_gen_shri_i32(X
, hi
, 31);
3833 /* extract result */
3835 tcg_gen_shli_i32(hi
, hi
, 1);
3837 tcg_temp_free_i64(t0
);
3838 tcg_gen_or_i32(lo
, lo
, hi
);
3841 /* if shift == 0, register and X are not affected */
3843 zero
= tcg_const_i32(0);
3844 tcg_gen_movcond_i32(TCG_COND_EQ
, X
, shift
, zero
, QREG_CC_X
, X
);
3845 tcg_gen_movcond_i32(TCG_COND_EQ
, reg
, shift
, zero
, reg
, lo
);
3846 tcg_temp_free(zero
);
3852 DISAS_INSN(rotate_im
)
3856 int left
= (insn
& 0x100);
3858 tmp
= (insn
>> 9) & 7;
3863 shift
= tcg_const_i32(tmp
);
3865 rotate(DREG(insn
, 0), shift
, left
, 32);
3867 TCGv X
= rotate32_x(DREG(insn
, 0), shift
, left
);
3868 rotate_x_flags(DREG(insn
, 0), X
, 32);
3871 tcg_temp_free(shift
);
3873 set_cc_op(s
, CC_OP_FLAGS
);
3876 DISAS_INSN(rotate8_im
)
3878 int left
= (insn
& 0x100);
3883 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3885 tmp
= (insn
>> 9) & 7;
3890 shift
= tcg_const_i32(tmp
);
3892 rotate(reg
, shift
, left
, 8);
3894 TCGv X
= rotate_x(reg
, shift
, left
, 8);
3895 rotate_x_flags(reg
, X
, 8);
3898 tcg_temp_free(shift
);
3899 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3900 set_cc_op(s
, CC_OP_FLAGS
);
3903 DISAS_INSN(rotate16_im
)
3905 int left
= (insn
& 0x100);
3910 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
3911 tmp
= (insn
>> 9) & 7;
3916 shift
= tcg_const_i32(tmp
);
3918 rotate(reg
, shift
, left
, 16);
3920 TCGv X
= rotate_x(reg
, shift
, left
, 16);
3921 rotate_x_flags(reg
, X
, 16);
3924 tcg_temp_free(shift
);
3925 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3926 set_cc_op(s
, CC_OP_FLAGS
);
3929 DISAS_INSN(rotate_reg
)
3934 int left
= (insn
& 0x100);
3936 reg
= DREG(insn
, 0);
3937 src
= DREG(insn
, 9);
3938 /* shift in [0..63] */
3939 t0
= tcg_temp_new();
3940 tcg_gen_andi_i32(t0
, src
, 63);
3941 t1
= tcg_temp_new_i32();
3943 tcg_gen_andi_i32(t1
, src
, 31);
3944 rotate(reg
, t1
, left
, 32);
3945 /* if shift == 0, clear C */
3946 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3947 t0
, QREG_CC_V
/* 0 */,
3948 QREG_CC_V
/* 0 */, QREG_CC_C
);
3952 tcg_gen_movi_i32(t1
, 33);
3953 tcg_gen_remu_i32(t1
, t0
, t1
);
3954 X
= rotate32_x(DREG(insn
, 0), t1
, left
);
3955 rotate_x_flags(DREG(insn
, 0), X
, 32);
3960 set_cc_op(s
, CC_OP_FLAGS
);
3963 DISAS_INSN(rotate8_reg
)
3968 int left
= (insn
& 0x100);
3970 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3971 src
= DREG(insn
, 9);
3972 /* shift in [0..63] */
3973 t0
= tcg_temp_new_i32();
3974 tcg_gen_andi_i32(t0
, src
, 63);
3975 t1
= tcg_temp_new_i32();
3977 tcg_gen_andi_i32(t1
, src
, 7);
3978 rotate(reg
, t1
, left
, 8);
3979 /* if shift == 0, clear C */
3980 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3981 t0
, QREG_CC_V
/* 0 */,
3982 QREG_CC_V
/* 0 */, QREG_CC_C
);
3986 tcg_gen_movi_i32(t1
, 9);
3987 tcg_gen_remu_i32(t1
, t0
, t1
);
3988 X
= rotate_x(reg
, t1
, left
, 8);
3989 rotate_x_flags(reg
, X
, 8);
3994 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3995 set_cc_op(s
, CC_OP_FLAGS
);
3998 DISAS_INSN(rotate16_reg
)
4003 int left
= (insn
& 0x100);
4005 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
4006 src
= DREG(insn
, 9);
4007 /* shift in [0..63] */
4008 t0
= tcg_temp_new_i32();
4009 tcg_gen_andi_i32(t0
, src
, 63);
4010 t1
= tcg_temp_new_i32();
4012 tcg_gen_andi_i32(t1
, src
, 15);
4013 rotate(reg
, t1
, left
, 16);
4014 /* if shift == 0, clear C */
4015 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
4016 t0
, QREG_CC_V
/* 0 */,
4017 QREG_CC_V
/* 0 */, QREG_CC_C
);
4021 tcg_gen_movi_i32(t1
, 17);
4022 tcg_gen_remu_i32(t1
, t0
, t1
);
4023 X
= rotate_x(reg
, t1
, left
, 16);
4024 rotate_x_flags(reg
, X
, 16);
4029 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
4030 set_cc_op(s
, CC_OP_FLAGS
);
4033 DISAS_INSN(rotate_mem
)
4038 int left
= (insn
& 0x100);
4040 SRC_EA(env
, src
, OS_WORD
, 0, &addr
);
4042 shift
= tcg_const_i32(1);
4043 if (insn
& 0x0200) {
4044 rotate(src
, shift
, left
, 16);
4046 TCGv X
= rotate_x(src
, shift
, left
, 16);
4047 rotate_x_flags(src
, X
, 16);
4050 tcg_temp_free(shift
);
4051 DEST_EA(env
, insn
, OS_WORD
, src
, &addr
);
4052 set_cc_op(s
, CC_OP_FLAGS
);
4055 DISAS_INSN(bfext_reg
)
4057 int ext
= read_im16(env
, s
);
4058 int is_sign
= insn
& 0x200;
4059 TCGv src
= DREG(insn
, 0);
4060 TCGv dst
= DREG(ext
, 12);
4061 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4062 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4063 int pos
= 32 - ofs
- len
; /* little bit-endian */
4064 TCGv tmp
= tcg_temp_new();
4068 * In general, we're going to rotate the field so that it's at the
4069 * top of the word and then right-shift by the complement of the
4070 * width to extend the field.
4073 /* Variable width. */
4075 /* Variable offset. */
4076 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4077 tcg_gen_rotl_i32(tmp
, src
, tmp
);
4079 tcg_gen_rotli_i32(tmp
, src
, ofs
);
4082 shift
= tcg_temp_new();
4083 tcg_gen_neg_i32(shift
, DREG(ext
, 0));
4084 tcg_gen_andi_i32(shift
, shift
, 31);
4085 tcg_gen_sar_i32(QREG_CC_N
, tmp
, shift
);
4087 tcg_gen_mov_i32(dst
, QREG_CC_N
);
4089 tcg_gen_shr_i32(dst
, tmp
, shift
);
4091 tcg_temp_free(shift
);
4093 /* Immediate width. */
4095 /* Variable offset */
4096 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4097 tcg_gen_rotl_i32(tmp
, src
, tmp
);
4102 * Immediate offset. If the field doesn't wrap around the
4103 * end of the word, rely on (s)extract completely.
4106 tcg_gen_rotli_i32(tmp
, src
, ofs
);
4112 tcg_gen_sextract_i32(QREG_CC_N
, src
, pos
, len
);
4114 tcg_gen_mov_i32(dst
, QREG_CC_N
);
4116 tcg_gen_extract_i32(dst
, src
, pos
, len
);
4121 set_cc_op(s
, CC_OP_LOGIC
);
4124 DISAS_INSN(bfext_mem
)
4126 int ext
= read_im16(env
, s
);
4127 int is_sign
= insn
& 0x200;
4128 TCGv dest
= DREG(ext
, 12);
4129 TCGv addr
, len
, ofs
;
4131 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4132 if (IS_NULL_QREG(addr
)) {
4140 len
= tcg_const_i32(extract32(ext
, 0, 5));
4145 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4149 gen_helper_bfexts_mem(dest
, cpu_env
, addr
, ofs
, len
);
4150 tcg_gen_mov_i32(QREG_CC_N
, dest
);
4152 TCGv_i64 tmp
= tcg_temp_new_i64();
4153 gen_helper_bfextu_mem(tmp
, cpu_env
, addr
, ofs
, len
);
4154 tcg_gen_extr_i64_i32(dest
, QREG_CC_N
, tmp
);
4155 tcg_temp_free_i64(tmp
);
4157 set_cc_op(s
, CC_OP_LOGIC
);
4159 if (!(ext
& 0x20)) {
4162 if (!(ext
& 0x800)) {
4167 DISAS_INSN(bfop_reg
)
4169 int ext
= read_im16(env
, s
);
4170 TCGv src
= DREG(insn
, 0);
4171 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4172 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4173 TCGv mask
, tofs
, tlen
;
4177 if ((insn
& 0x0f00) == 0x0d00) { /* bfffo */
4178 tofs
= tcg_temp_new();
4179 tlen
= tcg_temp_new();
4182 if ((ext
& 0x820) == 0) {
4183 /* Immediate width and offset. */
4184 uint32_t maski
= 0x7fffffffu
>> (len
- 1);
4185 if (ofs
+ len
<= 32) {
4186 tcg_gen_shli_i32(QREG_CC_N
, src
, ofs
);
4188 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4190 tcg_gen_andi_i32(QREG_CC_N
, QREG_CC_N
, ~maski
);
4191 mask
= tcg_const_i32(ror32(maski
, ofs
));
4193 tcg_gen_movi_i32(tofs
, ofs
);
4194 tcg_gen_movi_i32(tlen
, len
);
4197 TCGv tmp
= tcg_temp_new();
4199 /* Variable width */
4200 tcg_gen_subi_i32(tmp
, DREG(ext
, 0), 1);
4201 tcg_gen_andi_i32(tmp
, tmp
, 31);
4202 mask
= tcg_const_i32(0x7fffffffu
);
4203 tcg_gen_shr_i32(mask
, mask
, tmp
);
4205 tcg_gen_addi_i32(tlen
, tmp
, 1);
4208 /* Immediate width */
4209 mask
= tcg_const_i32(0x7fffffffu
>> (len
- 1));
4211 tcg_gen_movi_i32(tlen
, len
);
4215 /* Variable offset */
4216 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4217 tcg_gen_rotl_i32(QREG_CC_N
, src
, tmp
);
4218 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4219 tcg_gen_rotr_i32(mask
, mask
, tmp
);
4221 tcg_gen_mov_i32(tofs
, tmp
);
4224 /* Immediate offset (and variable width) */
4225 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4226 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4227 tcg_gen_rotri_i32(mask
, mask
, ofs
);
4229 tcg_gen_movi_i32(tofs
, ofs
);
4234 set_cc_op(s
, CC_OP_LOGIC
);
4236 switch (insn
& 0x0f00) {
4237 case 0x0a00: /* bfchg */
4238 tcg_gen_eqv_i32(src
, src
, mask
);
4240 case 0x0c00: /* bfclr */
4241 tcg_gen_and_i32(src
, src
, mask
);
4243 case 0x0d00: /* bfffo */
4244 gen_helper_bfffo_reg(DREG(ext
, 12), QREG_CC_N
, tofs
, tlen
);
4245 tcg_temp_free(tlen
);
4246 tcg_temp_free(tofs
);
4248 case 0x0e00: /* bfset */
4249 tcg_gen_orc_i32(src
, src
, mask
);
4251 case 0x0800: /* bftst */
4252 /* flags already set; no other work to do. */
4255 g_assert_not_reached();
4257 tcg_temp_free(mask
);
4260 DISAS_INSN(bfop_mem
)
4262 int ext
= read_im16(env
, s
);
4263 TCGv addr
, len
, ofs
;
4266 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4267 if (IS_NULL_QREG(addr
)) {
4275 len
= tcg_const_i32(extract32(ext
, 0, 5));
4280 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4283 switch (insn
& 0x0f00) {
4284 case 0x0a00: /* bfchg */
4285 gen_helper_bfchg_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4287 case 0x0c00: /* bfclr */
4288 gen_helper_bfclr_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4290 case 0x0d00: /* bfffo */
4291 t64
= tcg_temp_new_i64();
4292 gen_helper_bfffo_mem(t64
, cpu_env
, addr
, ofs
, len
);
4293 tcg_gen_extr_i64_i32(DREG(ext
, 12), QREG_CC_N
, t64
);
4294 tcg_temp_free_i64(t64
);
4296 case 0x0e00: /* bfset */
4297 gen_helper_bfset_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4299 case 0x0800: /* bftst */
4300 gen_helper_bfexts_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4303 g_assert_not_reached();
4305 set_cc_op(s
, CC_OP_LOGIC
);
4307 if (!(ext
& 0x20)) {
4310 if (!(ext
& 0x800)) {
4315 DISAS_INSN(bfins_reg
)
4317 int ext
= read_im16(env
, s
);
4318 TCGv dst
= DREG(insn
, 0);
4319 TCGv src
= DREG(ext
, 12);
4320 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4321 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4322 int pos
= 32 - ofs
- len
; /* little bit-endian */
4325 tmp
= tcg_temp_new();
4328 /* Variable width */
4329 tcg_gen_neg_i32(tmp
, DREG(ext
, 0));
4330 tcg_gen_andi_i32(tmp
, tmp
, 31);
4331 tcg_gen_shl_i32(QREG_CC_N
, src
, tmp
);
4333 /* Immediate width */
4334 tcg_gen_shli_i32(QREG_CC_N
, src
, 32 - len
);
4336 set_cc_op(s
, CC_OP_LOGIC
);
4338 /* Immediate width and offset */
4339 if ((ext
& 0x820) == 0) {
4340 /* Check for suitability for deposit. */
4342 tcg_gen_deposit_i32(dst
, dst
, src
, pos
, len
);
4344 uint32_t maski
= -2U << (len
- 1);
4345 uint32_t roti
= (ofs
+ len
) & 31;
4346 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4347 tcg_gen_rotri_i32(tmp
, tmp
, roti
);
4348 tcg_gen_andi_i32(dst
, dst
, ror32(maski
, roti
));
4349 tcg_gen_or_i32(dst
, dst
, tmp
);
4352 TCGv mask
= tcg_temp_new();
4353 TCGv rot
= tcg_temp_new();
4356 /* Variable width */
4357 tcg_gen_subi_i32(rot
, DREG(ext
, 0), 1);
4358 tcg_gen_andi_i32(rot
, rot
, 31);
4359 tcg_gen_movi_i32(mask
, -2);
4360 tcg_gen_shl_i32(mask
, mask
, rot
);
4361 tcg_gen_mov_i32(rot
, DREG(ext
, 0));
4362 tcg_gen_andc_i32(tmp
, src
, mask
);
4364 /* Immediate width (variable offset) */
4365 uint32_t maski
= -2U << (len
- 1);
4366 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4367 tcg_gen_movi_i32(mask
, maski
);
4368 tcg_gen_movi_i32(rot
, len
& 31);
4371 /* Variable offset */
4372 tcg_gen_add_i32(rot
, rot
, DREG(ext
, 6));
4374 /* Immediate offset (variable width) */
4375 tcg_gen_addi_i32(rot
, rot
, ofs
);
4377 tcg_gen_andi_i32(rot
, rot
, 31);
4378 tcg_gen_rotr_i32(mask
, mask
, rot
);
4379 tcg_gen_rotr_i32(tmp
, tmp
, rot
);
4380 tcg_gen_and_i32(dst
, dst
, mask
);
4381 tcg_gen_or_i32(dst
, dst
, tmp
);
4384 tcg_temp_free(mask
);
4389 DISAS_INSN(bfins_mem
)
4391 int ext
= read_im16(env
, s
);
4392 TCGv src
= DREG(ext
, 12);
4393 TCGv addr
, len
, ofs
;
4395 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4396 if (IS_NULL_QREG(addr
)) {
4404 len
= tcg_const_i32(extract32(ext
, 0, 5));
4409 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4412 gen_helper_bfins_mem(QREG_CC_N
, cpu_env
, addr
, src
, ofs
, len
);
4413 set_cc_op(s
, CC_OP_LOGIC
);
4415 if (!(ext
& 0x20)) {
4418 if (!(ext
& 0x800)) {
4426 reg
= DREG(insn
, 0);
4427 gen_logic_cc(s
, reg
, OS_LONG
);
4428 gen_helper_ff1(reg
, reg
);
4436 switch ((insn
>> 7) & 3) {
4441 if (m68k_feature(env
, M68K_FEATURE_CHK2
)) {
4447 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4450 SRC_EA(env
, src
, opsize
, 1, NULL
);
4451 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
4454 gen_helper_chk(cpu_env
, reg
, src
);
4460 TCGv addr1
, addr2
, bound1
, bound2
, reg
;
4463 switch ((insn
>> 9) & 3) {
4474 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4478 ext
= read_im16(env
, s
);
4479 if ((ext
& 0x0800) == 0) {
4480 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4484 addr1
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4485 addr2
= tcg_temp_new();
4486 tcg_gen_addi_i32(addr2
, addr1
, opsize_bytes(opsize
));
4488 bound1
= gen_load(s
, opsize
, addr1
, 1, IS_USER(s
));
4489 tcg_temp_free(addr1
);
4490 bound2
= gen_load(s
, opsize
, addr2
, 1, IS_USER(s
));
4491 tcg_temp_free(addr2
);
4493 reg
= tcg_temp_new();
4495 tcg_gen_mov_i32(reg
, AREG(ext
, 12));
4497 gen_ext(reg
, DREG(ext
, 12), opsize
, 1);
4501 gen_helper_chk2(cpu_env
, reg
, bound1
, bound2
);
4503 tcg_temp_free(bound1
);
4504 tcg_temp_free(bound2
);
4507 static void m68k_copy_line(TCGv dst
, TCGv src
, int index
)
4512 addr
= tcg_temp_new();
4514 t0
= tcg_temp_new_i64();
4515 t1
= tcg_temp_new_i64();
4517 tcg_gen_andi_i32(addr
, src
, ~15);
4518 tcg_gen_qemu_ld64(t0
, addr
, index
);
4519 tcg_gen_addi_i32(addr
, addr
, 8);
4520 tcg_gen_qemu_ld64(t1
, addr
, index
);
4522 tcg_gen_andi_i32(addr
, dst
, ~15);
4523 tcg_gen_qemu_st64(t0
, addr
, index
);
4524 tcg_gen_addi_i32(addr
, addr
, 8);
4525 tcg_gen_qemu_st64(t1
, addr
, index
);
4527 tcg_temp_free_i64(t0
);
4528 tcg_temp_free_i64(t1
);
4529 tcg_temp_free(addr
);
4532 DISAS_INSN(move16_reg
)
4534 int index
= IS_USER(s
);
4538 ext
= read_im16(env
, s
);
4539 if ((ext
& (1 << 15)) == 0) {
4540 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4543 m68k_copy_line(AREG(ext
, 12), AREG(insn
, 0), index
);
4545 /* Ax can be Ay, so save Ay before incrementing Ax */
4546 tmp
= tcg_temp_new();
4547 tcg_gen_mov_i32(tmp
, AREG(ext
, 12));
4548 tcg_gen_addi_i32(AREG(insn
, 0), AREG(insn
, 0), 16);
4549 tcg_gen_addi_i32(AREG(ext
, 12), tmp
, 16);
4553 DISAS_INSN(move16_mem
)
4555 int index
= IS_USER(s
);
4558 reg
= AREG(insn
, 0);
4559 addr
= tcg_const_i32(read_im32(env
, s
));
4561 if ((insn
>> 3) & 1) {
4562 /* MOVE16 (xxx).L, (Ay) */
4563 m68k_copy_line(reg
, addr
, index
);
4565 /* MOVE16 (Ay), (xxx).L */
4566 m68k_copy_line(addr
, reg
, index
);
4569 tcg_temp_free(addr
);
4571 if (((insn
>> 3) & 2) == 0) {
4573 tcg_gen_addi_i32(reg
, reg
, 16);
4583 ext
= read_im16(env
, s
);
4584 if (ext
!= 0x46FC) {
4585 gen_exception(s
, addr
, EXCP_ILLEGAL
);
4588 ext
= read_im16(env
, s
);
4589 if (IS_USER(s
) || (ext
& SR_S
) == 0) {
4590 gen_exception(s
, addr
, EXCP_PRIVILEGE
);
4593 gen_push(s
, gen_get_sr(s
));
4594 gen_set_sr_im(s
, ext
, 0);
4597 DISAS_INSN(move_from_sr
)
4601 if (IS_USER(s
) && !m68k_feature(env
, M68K_FEATURE_M68000
)) {
4602 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4606 DEST_EA(env
, insn
, OS_WORD
, sr
, NULL
);
4609 #if defined(CONFIG_SOFTMMU)
4619 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4623 ext
= read_im16(env
, s
);
4625 opsize
= insn_opsize(insn
);
4628 /* address register */
4629 reg
= AREG(ext
, 12);
4633 reg
= DREG(ext
, 12);
4637 addr
= gen_lea(env
, s
, insn
, opsize
);
4638 if (IS_NULL_QREG(addr
)) {
4644 /* from reg to ea */
4645 gen_store(s
, opsize
, addr
, reg
, DFC_INDEX(s
));
4647 /* from ea to reg */
4648 TCGv tmp
= gen_load(s
, opsize
, addr
, 0, SFC_INDEX(s
));
4650 gen_ext(reg
, tmp
, opsize
, 1);
4652 gen_partset_reg(opsize
, reg
, tmp
);
4656 switch (extract32(insn
, 3, 3)) {
4657 case 3: /* Indirect postincrement. */
4658 tcg_gen_addi_i32(AREG(insn
, 0), addr
,
4659 REG(insn
, 0) == 7 && opsize
== OS_BYTE
4661 : opsize_bytes(opsize
));
4663 case 4: /* Indirect predecrememnt. */
4664 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4669 DISAS_INSN(move_to_sr
)
4672 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4675 gen_move_to_sr(env
, s
, insn
, false);
4679 DISAS_INSN(move_from_usp
)
4682 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4685 tcg_gen_ld_i32(AREG(insn
, 0), cpu_env
,
4686 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4689 DISAS_INSN(move_to_usp
)
4692 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4695 tcg_gen_st_i32(AREG(insn
, 0), cpu_env
,
4696 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4702 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4706 gen_exception(s
, s
->pc
, EXCP_HALT_INSN
);
4714 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4718 ext
= read_im16(env
, s
);
4720 gen_set_sr_im(s
, ext
, 0);
4721 tcg_gen_movi_i32(cpu_halted
, 1);
4722 gen_exception(s
, s
->pc
, EXCP_HLT
);
4728 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4731 gen_exception(s
, s
->base
.pc_next
, EXCP_RTE
);
4734 DISAS_INSN(cf_movec
)
4740 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4744 ext
= read_im16(env
, s
);
4747 reg
= AREG(ext
, 12);
4749 reg
= DREG(ext
, 12);
4751 gen_helper_cf_movec_to(cpu_env
, tcg_const_i32(ext
& 0xfff), reg
);
4755 DISAS_INSN(m68k_movec
)
4761 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4765 ext
= read_im16(env
, s
);
4768 reg
= AREG(ext
, 12);
4770 reg
= DREG(ext
, 12);
4773 gen_helper_m68k_movec_to(cpu_env
, tcg_const_i32(ext
& 0xfff), reg
);
4775 gen_helper_m68k_movec_from(reg
, cpu_env
, tcg_const_i32(ext
& 0xfff));
4783 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4786 /* ICache fetch. Implement as no-op. */
4792 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4795 /* Cache push/invalidate. Implement as no-op. */
4801 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4804 /* Cache push/invalidate. Implement as no-op. */
4810 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4813 /* Invalidate cache line. Implement as no-op. */
4816 #if defined(CONFIG_SOFTMMU)
4822 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4826 opmode
= tcg_const_i32((insn
>> 3) & 3);
4827 gen_helper_pflush(cpu_env
, AREG(insn
, 0), opmode
);
4828 tcg_temp_free(opmode
);
4836 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4839 is_read
= tcg_const_i32((insn
>> 5) & 1);
4840 gen_helper_ptest(cpu_env
, AREG(insn
, 0), is_read
);
4841 tcg_temp_free(is_read
);
4847 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4853 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4856 /* TODO: Implement wdebug. */
4857 cpu_abort(env_cpu(env
), "WDEBUG not implemented");
4863 gen_exception(s
, s
->base
.pc_next
, EXCP_TRAP0
+ (insn
& 0xf));
4866 static void gen_load_fcr(DisasContext
*s
, TCGv res
, int reg
)
4870 tcg_gen_movi_i32(res
, 0);
4873 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4876 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpcr
));
4881 static void gen_store_fcr(DisasContext
*s
, TCGv val
, int reg
)
4887 tcg_gen_st_i32(val
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4890 gen_helper_set_fpcr(cpu_env
, val
);
4895 static void gen_qemu_store_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4897 int index
= IS_USER(s
);
4900 tmp
= tcg_temp_new();
4901 gen_load_fcr(s
, tmp
, reg
);
4902 tcg_gen_qemu_st32(tmp
, addr
, index
);
4906 static void gen_qemu_load_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4908 int index
= IS_USER(s
);
4911 tmp
= tcg_temp_new();
4912 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
4913 gen_store_fcr(s
, tmp
, reg
);
4918 static void gen_op_fmove_fcr(CPUM68KState
*env
, DisasContext
*s
,
4919 uint32_t insn
, uint32_t ext
)
4921 int mask
= (ext
>> 10) & 7;
4922 int is_write
= (ext
>> 13) & 1;
4923 int mode
= extract32(insn
, 3, 3);
4929 if (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&& mask
!= M68K_FPCR
) {
4930 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4934 gen_load_fcr(s
, DREG(insn
, 0), mask
);
4936 gen_store_fcr(s
, DREG(insn
, 0), mask
);
4939 case 1: /* An, only with FPIAR */
4940 if (mask
!= M68K_FPIAR
) {
4941 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4945 gen_load_fcr(s
, AREG(insn
, 0), mask
);
4947 gen_store_fcr(s
, AREG(insn
, 0), mask
);
4950 case 7: /* Immediate */
4951 if (REG(insn
, 0) == 4) {
4953 (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&&
4954 mask
!= M68K_FPCR
)) {
4955 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4958 tmp
= tcg_const_i32(read_im32(env
, s
));
4959 gen_store_fcr(s
, tmp
, mask
);
4968 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
4969 if (IS_NULL_QREG(tmp
)) {
4974 addr
= tcg_temp_new();
4975 tcg_gen_mov_i32(addr
, tmp
);
4980 * 0b100 Floating-Point Control Register
4981 * 0b010 Floating-Point Status Register
4982 * 0b001 Floating-Point Instruction Address Register
4986 if (is_write
&& mode
== 4) {
4987 for (i
= 2; i
>= 0; i
--, mask
>>= 1) {
4989 gen_qemu_store_fcr(s
, addr
, 1 << i
);
4991 tcg_gen_subi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
4995 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4997 for (i
= 0; i
< 3; i
++, mask
>>= 1) {
5000 gen_qemu_store_fcr(s
, addr
, 1 << i
);
5002 gen_qemu_load_fcr(s
, addr
, 1 << i
);
5004 if (mask
!= 1 || mode
== 3) {
5005 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
5010 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5013 tcg_temp_free_i32(addr
);
5016 static void gen_op_fmovem(CPUM68KState
*env
, DisasContext
*s
,
5017 uint32_t insn
, uint32_t ext
)
5021 int mode
= (ext
>> 11) & 0x3;
5022 int is_load
= ((ext
& 0x2000) == 0);
5024 if (m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
5025 opsize
= OS_EXTENDED
;
5027 opsize
= OS_DOUBLE
; /* FIXME */
5030 addr
= gen_lea(env
, s
, insn
, opsize
);
5031 if (IS_NULL_QREG(addr
)) {
5036 tmp
= tcg_temp_new();
5038 /* Dynamic register list */
5039 tcg_gen_ext8u_i32(tmp
, DREG(ext
, 4));
5041 /* Static register list */
5042 tcg_gen_movi_i32(tmp
, ext
& 0xff);
5045 if (!is_load
&& (mode
& 2) == 0) {
5047 * predecrement addressing mode
5048 * only available to store register to memory
5050 if (opsize
== OS_EXTENDED
) {
5051 gen_helper_fmovemx_st_predec(tmp
, cpu_env
, addr
, tmp
);
5053 gen_helper_fmovemd_st_predec(tmp
, cpu_env
, addr
, tmp
);
5056 /* postincrement addressing mode */
5057 if (opsize
== OS_EXTENDED
) {
5059 gen_helper_fmovemx_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
5061 gen_helper_fmovemx_st_postinc(tmp
, cpu_env
, addr
, tmp
);
5065 gen_helper_fmovemd_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
5067 gen_helper_fmovemd_st_postinc(tmp
, cpu_env
, addr
, tmp
);
5071 if ((insn
& 070) == 030 || (insn
& 070) == 040) {
5072 tcg_gen_mov_i32(AREG(insn
, 0), tmp
);
5078 * ??? FP exceptions are not implemented. Most exceptions are deferred until
5079 * immediately before the next FP instruction is executed.
5086 TCGv_ptr cpu_src
, cpu_dest
;
5088 ext
= read_im16(env
, s
);
5089 opmode
= ext
& 0x7f;
5090 switch ((ext
>> 13) & 7) {
5096 if (insn
== 0xf200 && (ext
& 0xfc00) == 0x5c00) {
5098 TCGv rom_offset
= tcg_const_i32(opmode
);
5099 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
5100 gen_helper_fconst(cpu_env
, cpu_dest
, rom_offset
);
5101 tcg_temp_free_ptr(cpu_dest
);
5102 tcg_temp_free(rom_offset
);
5106 case 3: /* fmove out */
5107 cpu_src
= gen_fp_ptr(REG(ext
, 7));
5108 opsize
= ext_opsize(ext
, 10);
5109 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
5110 EA_STORE
, IS_USER(s
)) == -1) {
5113 gen_helper_ftst(cpu_env
, cpu_src
);
5114 tcg_temp_free_ptr(cpu_src
);
5116 case 4: /* fmove to control register. */
5117 case 5: /* fmove from control register. */
5118 gen_op_fmove_fcr(env
, s
, insn
, ext
);
5120 case 6: /* fmovem */
5122 if ((ext
& 0x1000) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
5125 gen_op_fmovem(env
, s
, insn
, ext
);
5128 if (ext
& (1 << 14)) {
5129 /* Source effective address. */
5130 opsize
= ext_opsize(ext
, 10);
5131 cpu_src
= gen_fp_result_ptr();
5132 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
5133 EA_LOADS
, IS_USER(s
)) == -1) {
5138 /* Source register. */
5139 opsize
= OS_EXTENDED
;
5140 cpu_src
= gen_fp_ptr(REG(ext
, 10));
5142 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
5145 gen_fp_move(cpu_dest
, cpu_src
);
5147 case 0x40: /* fsmove */
5148 gen_helper_fsround(cpu_env
, cpu_dest
, cpu_src
);
5150 case 0x44: /* fdmove */
5151 gen_helper_fdround(cpu_env
, cpu_dest
, cpu_src
);
5154 gen_helper_firound(cpu_env
, cpu_dest
, cpu_src
);
5157 gen_helper_fsinh(cpu_env
, cpu_dest
, cpu_src
);
5159 case 3: /* fintrz */
5160 gen_helper_fitrunc(cpu_env
, cpu_dest
, cpu_src
);
5163 gen_helper_fsqrt(cpu_env
, cpu_dest
, cpu_src
);
5165 case 0x41: /* fssqrt */
5166 gen_helper_fssqrt(cpu_env
, cpu_dest
, cpu_src
);
5168 case 0x45: /* fdsqrt */
5169 gen_helper_fdsqrt(cpu_env
, cpu_dest
, cpu_src
);
5171 case 0x06: /* flognp1 */
5172 gen_helper_flognp1(cpu_env
, cpu_dest
, cpu_src
);
5174 case 0x08: /* fetoxm1 */
5175 gen_helper_fetoxm1(cpu_env
, cpu_dest
, cpu_src
);
5177 case 0x09: /* ftanh */
5178 gen_helper_ftanh(cpu_env
, cpu_dest
, cpu_src
);
5180 case 0x0a: /* fatan */
5181 gen_helper_fatan(cpu_env
, cpu_dest
, cpu_src
);
5183 case 0x0c: /* fasin */
5184 gen_helper_fasin(cpu_env
, cpu_dest
, cpu_src
);
5186 case 0x0d: /* fatanh */
5187 gen_helper_fatanh(cpu_env
, cpu_dest
, cpu_src
);
5189 case 0x0e: /* fsin */
5190 gen_helper_fsin(cpu_env
, cpu_dest
, cpu_src
);
5192 case 0x0f: /* ftan */
5193 gen_helper_ftan(cpu_env
, cpu_dest
, cpu_src
);
5195 case 0x10: /* fetox */
5196 gen_helper_fetox(cpu_env
, cpu_dest
, cpu_src
);
5198 case 0x11: /* ftwotox */
5199 gen_helper_ftwotox(cpu_env
, cpu_dest
, cpu_src
);
5201 case 0x12: /* ftentox */
5202 gen_helper_ftentox(cpu_env
, cpu_dest
, cpu_src
);
5204 case 0x14: /* flogn */
5205 gen_helper_flogn(cpu_env
, cpu_dest
, cpu_src
);
5207 case 0x15: /* flog10 */
5208 gen_helper_flog10(cpu_env
, cpu_dest
, cpu_src
);
5210 case 0x16: /* flog2 */
5211 gen_helper_flog2(cpu_env
, cpu_dest
, cpu_src
);
5213 case 0x18: /* fabs */
5214 gen_helper_fabs(cpu_env
, cpu_dest
, cpu_src
);
5216 case 0x58: /* fsabs */
5217 gen_helper_fsabs(cpu_env
, cpu_dest
, cpu_src
);
5219 case 0x5c: /* fdabs */
5220 gen_helper_fdabs(cpu_env
, cpu_dest
, cpu_src
);
5222 case 0x19: /* fcosh */
5223 gen_helper_fcosh(cpu_env
, cpu_dest
, cpu_src
);
5225 case 0x1a: /* fneg */
5226 gen_helper_fneg(cpu_env
, cpu_dest
, cpu_src
);
5228 case 0x5a: /* fsneg */
5229 gen_helper_fsneg(cpu_env
, cpu_dest
, cpu_src
);
5231 case 0x5e: /* fdneg */
5232 gen_helper_fdneg(cpu_env
, cpu_dest
, cpu_src
);
5234 case 0x1c: /* facos */
5235 gen_helper_facos(cpu_env
, cpu_dest
, cpu_src
);
5237 case 0x1d: /* fcos */
5238 gen_helper_fcos(cpu_env
, cpu_dest
, cpu_src
);
5240 case 0x1e: /* fgetexp */
5241 gen_helper_fgetexp(cpu_env
, cpu_dest
, cpu_src
);
5243 case 0x1f: /* fgetman */
5244 gen_helper_fgetman(cpu_env
, cpu_dest
, cpu_src
);
5246 case 0x20: /* fdiv */
5247 gen_helper_fdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5249 case 0x60: /* fsdiv */
5250 gen_helper_fsdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5252 case 0x64: /* fddiv */
5253 gen_helper_fddiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5255 case 0x21: /* fmod */
5256 gen_helper_fmod(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5258 case 0x22: /* fadd */
5259 gen_helper_fadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5261 case 0x62: /* fsadd */
5262 gen_helper_fsadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5264 case 0x66: /* fdadd */
5265 gen_helper_fdadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5267 case 0x23: /* fmul */
5268 gen_helper_fmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5270 case 0x63: /* fsmul */
5271 gen_helper_fsmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5273 case 0x67: /* fdmul */
5274 gen_helper_fdmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5276 case 0x24: /* fsgldiv */
5277 gen_helper_fsgldiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5279 case 0x25: /* frem */
5280 gen_helper_frem(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5282 case 0x26: /* fscale */
5283 gen_helper_fscale(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5285 case 0x27: /* fsglmul */
5286 gen_helper_fsglmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5288 case 0x28: /* fsub */
5289 gen_helper_fsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5291 case 0x68: /* fssub */
5292 gen_helper_fssub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5294 case 0x6c: /* fdsub */
5295 gen_helper_fdsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5297 case 0x30: case 0x31: case 0x32:
5298 case 0x33: case 0x34: case 0x35:
5299 case 0x36: case 0x37: {
5300 TCGv_ptr cpu_dest2
= gen_fp_ptr(REG(ext
, 0));
5301 gen_helper_fsincos(cpu_env
, cpu_dest
, cpu_dest2
, cpu_src
);
5302 tcg_temp_free_ptr(cpu_dest2
);
5305 case 0x38: /* fcmp */
5306 gen_helper_fcmp(cpu_env
, cpu_src
, cpu_dest
);
5308 case 0x3a: /* ftst */
5309 gen_helper_ftst(cpu_env
, cpu_src
);
5314 tcg_temp_free_ptr(cpu_src
);
5315 gen_helper_ftst(cpu_env
, cpu_dest
);
5316 tcg_temp_free_ptr(cpu_dest
);
5319 /* FIXME: Is this right for offset addressing modes? */
5321 disas_undef_fpu(env
, s
, insn
);
5324 static void gen_fcc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
5329 c
->v2
= tcg_const_i32(0);
5331 /* TODO: Raise BSUN exception. */
5332 fpsr
= tcg_temp_new();
5333 gen_load_fcr(s
, fpsr
, M68K_FPSR
);
5336 case 16: /* Signaling False */
5338 c
->tcond
= TCG_COND_NEVER
;
5340 case 1: /* EQual Z */
5341 case 17: /* Signaling EQual Z */
5342 c
->v1
= tcg_temp_new();
5344 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5345 c
->tcond
= TCG_COND_NE
;
5347 case 2: /* Ordered Greater Than !(A || Z || N) */
5348 case 18: /* Greater Than !(A || Z || N) */
5349 c
->v1
= tcg_temp_new();
5351 tcg_gen_andi_i32(c
->v1
, fpsr
,
5352 FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5353 c
->tcond
= TCG_COND_EQ
;
5355 case 3: /* Ordered Greater than or Equal Z || !(A || N) */
5356 case 19: /* Greater than or Equal Z || !(A || N) */
5357 c
->v1
= tcg_temp_new();
5359 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5360 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
5361 tcg_gen_andi_i32(fpsr
, fpsr
, FPSR_CC_Z
| FPSR_CC_N
);
5362 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5363 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5364 c
->tcond
= TCG_COND_NE
;
5366 case 4: /* Ordered Less Than !(!N || A || Z); */
5367 case 20: /* Less Than !(!N || A || Z); */
5368 c
->v1
= tcg_temp_new();
5370 tcg_gen_xori_i32(c
->v1
, fpsr
, FPSR_CC_N
);
5371 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_N
| FPSR_CC_A
| FPSR_CC_Z
);
5372 c
->tcond
= TCG_COND_EQ
;
5374 case 5: /* Ordered Less than or Equal Z || (N && !A) */
5375 case 21: /* Less than or Equal Z || (N && !A) */
5376 c
->v1
= tcg_temp_new();
5378 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5379 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
5380 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5381 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_Z
| FPSR_CC_N
);
5382 c
->tcond
= TCG_COND_NE
;
5384 case 6: /* Ordered Greater or Less than !(A || Z) */
5385 case 22: /* Greater or Less than !(A || Z) */
5386 c
->v1
= tcg_temp_new();
5388 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
5389 c
->tcond
= TCG_COND_EQ
;
5391 case 7: /* Ordered !A */
5392 case 23: /* Greater, Less or Equal !A */
5393 c
->v1
= tcg_temp_new();
5395 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5396 c
->tcond
= TCG_COND_EQ
;
5398 case 8: /* Unordered A */
5399 case 24: /* Not Greater, Less or Equal A */
5400 c
->v1
= tcg_temp_new();
5402 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5403 c
->tcond
= TCG_COND_NE
;
5405 case 9: /* Unordered or Equal A || Z */
5406 case 25: /* Not Greater or Less then A || Z */
5407 c
->v1
= tcg_temp_new();
5409 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
5410 c
->tcond
= TCG_COND_NE
;
5412 case 10: /* Unordered or Greater Than A || !(N || Z)) */
5413 case 26: /* Not Less or Equal A || !(N || Z)) */
5414 c
->v1
= tcg_temp_new();
5416 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5417 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
5418 tcg_gen_andi_i32(fpsr
, fpsr
, FPSR_CC_A
| FPSR_CC_N
);
5419 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5420 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5421 c
->tcond
= TCG_COND_NE
;
5423 case 11: /* Unordered or Greater or Equal A || Z || !N */
5424 case 27: /* Not Less Than A || Z || !N */
5425 c
->v1
= tcg_temp_new();
5427 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5428 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5429 c
->tcond
= TCG_COND_NE
;
5431 case 12: /* Unordered or Less Than A || (N && !Z) */
5432 case 28: /* Not Greater than or Equal A || (N && !Z) */
5433 c
->v1
= tcg_temp_new();
5435 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5436 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
5437 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5438 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_A
| FPSR_CC_N
);
5439 c
->tcond
= TCG_COND_NE
;
5441 case 13: /* Unordered or Less or Equal A || Z || N */
5442 case 29: /* Not Greater Than A || Z || N */
5443 c
->v1
= tcg_temp_new();
5445 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5446 c
->tcond
= TCG_COND_NE
;
5448 case 14: /* Not Equal !Z */
5449 case 30: /* Signaling Not Equal !Z */
5450 c
->v1
= tcg_temp_new();
5452 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5453 c
->tcond
= TCG_COND_EQ
;
5456 case 31: /* Signaling True */
5458 c
->tcond
= TCG_COND_ALWAYS
;
5461 tcg_temp_free(fpsr
);
5464 static void gen_fjmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
5468 gen_fcc_cond(&c
, s
, cond
);
5470 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
5481 offset
= (int16_t)read_im16(env
, s
);
5482 if (insn
& (1 << 6)) {
5483 offset
= (offset
<< 16) | read_im16(env
, s
);
5486 l1
= gen_new_label();
5488 gen_fjmpcc(s
, insn
& 0x3f, l1
);
5489 gen_jmp_tb(s
, 0, s
->pc
);
5491 gen_jmp_tb(s
, 1, base
+ offset
);
5501 ext
= read_im16(env
, s
);
5503 gen_fcc_cond(&c
, s
, cond
);
5505 tmp
= tcg_temp_new();
5506 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
5509 tcg_gen_neg_i32(tmp
, tmp
);
5510 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
5514 #if defined(CONFIG_SOFTMMU)
5515 DISAS_INSN(frestore
)
5520 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5523 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5524 SRC_EA(env
, addr
, OS_LONG
, 0, NULL
);
5525 /* FIXME: check the state frame */
5527 disas_undef(env
, s
, insn
);
5534 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5538 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5539 /* always write IDLE */
5540 TCGv idle
= tcg_const_i32(0x41000000);
5541 DEST_EA(env
, insn
, OS_LONG
, idle
, NULL
);
5542 tcg_temp_free(idle
);
5544 disas_undef(env
, s
, insn
);
5549 static inline TCGv
gen_mac_extract_word(DisasContext
*s
, TCGv val
, int upper
)
5551 TCGv tmp
= tcg_temp_new();
5552 if (s
->env
->macsr
& MACSR_FI
) {
5554 tcg_gen_andi_i32(tmp
, val
, 0xffff0000);
5556 tcg_gen_shli_i32(tmp
, val
, 16);
5557 } else if (s
->env
->macsr
& MACSR_SU
) {
5559 tcg_gen_sari_i32(tmp
, val
, 16);
5561 tcg_gen_ext16s_i32(tmp
, val
);
5564 tcg_gen_shri_i32(tmp
, val
, 16);
5566 tcg_gen_ext16u_i32(tmp
, val
);
5571 static void gen_mac_clear_flags(void)
5573 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
,
5574 ~(MACSR_V
| MACSR_Z
| MACSR_N
| MACSR_EV
));
5590 s
->mactmp
= tcg_temp_new_i64();
5594 ext
= read_im16(env
, s
);
5596 acc
= ((insn
>> 7) & 1) | ((ext
>> 3) & 2);
5597 dual
= ((insn
& 0x30) != 0 && (ext
& 3) != 0);
5598 if (dual
&& !m68k_feature(s
->env
, M68K_FEATURE_CF_EMAC_B
)) {
5599 disas_undef(env
, s
, insn
);
5603 /* MAC with load. */
5604 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
5605 addr
= tcg_temp_new();
5606 tcg_gen_and_i32(addr
, tmp
, QREG_MAC_MASK
);
5608 * Load the value now to ensure correct exception behavior.
5609 * Perform writeback after reading the MAC inputs.
5611 loadval
= gen_load(s
, OS_LONG
, addr
, 0, IS_USER(s
));
5614 rx
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(insn
, 12);
5615 ry
= (ext
& 8) ? AREG(ext
, 0) : DREG(ext
, 0);
5617 loadval
= addr
= NULL_QREG
;
5618 rx
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5619 ry
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5622 gen_mac_clear_flags();
5625 /* Disabled because conditional branches clobber temporary vars. */
5626 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && !dual
) {
5627 /* Skip the multiply if we know we will ignore it. */
5628 l1
= gen_new_label();
5629 tmp
= tcg_temp_new();
5630 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 1 << (acc
+ 8));
5631 gen_op_jmp_nz32(tmp
, l1
);
5635 if ((ext
& 0x0800) == 0) {
5637 rx
= gen_mac_extract_word(s
, rx
, (ext
& 0x80) != 0);
5638 ry
= gen_mac_extract_word(s
, ry
, (ext
& 0x40) != 0);
5640 if (s
->env
->macsr
& MACSR_FI
) {
5641 gen_helper_macmulf(s
->mactmp
, cpu_env
, rx
, ry
);
5643 if (s
->env
->macsr
& MACSR_SU
)
5644 gen_helper_macmuls(s
->mactmp
, cpu_env
, rx
, ry
);
5646 gen_helper_macmulu(s
->mactmp
, cpu_env
, rx
, ry
);
5647 switch ((ext
>> 9) & 3) {
5649 tcg_gen_shli_i64(s
->mactmp
, s
->mactmp
, 1);
5652 tcg_gen_shri_i64(s
->mactmp
, s
->mactmp
, 1);
5658 /* Save the overflow flag from the multiply. */
5659 saved_flags
= tcg_temp_new();
5660 tcg_gen_mov_i32(saved_flags
, QREG_MACSR
);
5662 saved_flags
= NULL_QREG
;
5666 /* Disabled because conditional branches clobber temporary vars. */
5667 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && dual
) {
5668 /* Skip the accumulate if the value is already saturated. */
5669 l1
= gen_new_label();
5670 tmp
= tcg_temp_new();
5671 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
5672 gen_op_jmp_nz32(tmp
, l1
);
5677 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5679 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5681 if (s
->env
->macsr
& MACSR_FI
)
5682 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
5683 else if (s
->env
->macsr
& MACSR_SU
)
5684 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
5686 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
5689 /* Disabled because conditional branches clobber temporary vars. */
5695 /* Dual accumulate variant. */
5696 acc
= (ext
>> 2) & 3;
5697 /* Restore the overflow flag from the multiplier. */
5698 tcg_gen_mov_i32(QREG_MACSR
, saved_flags
);
5700 /* Disabled because conditional branches clobber temporary vars. */
5701 if ((s
->env
->macsr
& MACSR_OMC
) != 0) {
5702 /* Skip the accumulate if the value is already saturated. */
5703 l1
= gen_new_label();
5704 tmp
= tcg_temp_new();
5705 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
5706 gen_op_jmp_nz32(tmp
, l1
);
5710 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5712 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5713 if (s
->env
->macsr
& MACSR_FI
)
5714 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
5715 else if (s
->env
->macsr
& MACSR_SU
)
5716 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
5718 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
5720 /* Disabled because conditional branches clobber temporary vars. */
5725 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(acc
));
5729 rw
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5730 tcg_gen_mov_i32(rw
, loadval
);
5732 * FIXME: Should address writeback happen with the masked or
5735 switch ((insn
>> 3) & 7) {
5736 case 3: /* Post-increment. */
5737 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 4);
5739 case 4: /* Pre-decrement. */
5740 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5742 tcg_temp_free(loadval
);
5746 DISAS_INSN(from_mac
)
5752 rx
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5753 accnum
= (insn
>> 9) & 3;
5754 acc
= MACREG(accnum
);
5755 if (s
->env
->macsr
& MACSR_FI
) {
5756 gen_helper_get_macf(rx
, cpu_env
, acc
);
5757 } else if ((s
->env
->macsr
& MACSR_OMC
) == 0) {
5758 tcg_gen_extrl_i64_i32(rx
, acc
);
5759 } else if (s
->env
->macsr
& MACSR_SU
) {
5760 gen_helper_get_macs(rx
, acc
);
5762 gen_helper_get_macu(rx
, acc
);
5765 tcg_gen_movi_i64(acc
, 0);
5766 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5770 DISAS_INSN(move_mac
)
5772 /* FIXME: This can be done without a helper. */
5776 dest
= tcg_const_i32((insn
>> 9) & 3);
5777 gen_helper_mac_move(cpu_env
, dest
, tcg_const_i32(src
));
5778 gen_mac_clear_flags();
5779 gen_helper_mac_set_flags(cpu_env
, dest
);
5782 DISAS_INSN(from_macsr
)
5786 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5787 tcg_gen_mov_i32(reg
, QREG_MACSR
);
5790 DISAS_INSN(from_mask
)
5793 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5794 tcg_gen_mov_i32(reg
, QREG_MAC_MASK
);
5797 DISAS_INSN(from_mext
)
5801 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5802 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
5803 if (s
->env
->macsr
& MACSR_FI
)
5804 gen_helper_get_mac_extf(reg
, cpu_env
, acc
);
5806 gen_helper_get_mac_exti(reg
, cpu_env
, acc
);
5809 DISAS_INSN(macsr_to_ccr
)
5811 TCGv tmp
= tcg_temp_new();
5812 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 0xf);
5813 gen_helper_set_sr(cpu_env
, tmp
);
5815 set_cc_op(s
, CC_OP_FLAGS
);
5823 accnum
= (insn
>> 9) & 3;
5824 acc
= MACREG(accnum
);
5825 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5826 if (s
->env
->macsr
& MACSR_FI
) {
5827 tcg_gen_ext_i32_i64(acc
, val
);
5828 tcg_gen_shli_i64(acc
, acc
, 8);
5829 } else if (s
->env
->macsr
& MACSR_SU
) {
5830 tcg_gen_ext_i32_i64(acc
, val
);
5832 tcg_gen_extu_i32_i64(acc
, val
);
5834 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5835 gen_mac_clear_flags();
5836 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(accnum
));
5839 DISAS_INSN(to_macsr
)
5842 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5843 gen_helper_set_macsr(cpu_env
, val
);
5850 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5851 tcg_gen_ori_i32(QREG_MAC_MASK
, val
, 0xffff0000);
5858 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5859 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
5860 if (s
->env
->macsr
& MACSR_FI
)
5861 gen_helper_set_mac_extf(cpu_env
, val
, acc
);
5862 else if (s
->env
->macsr
& MACSR_SU
)
5863 gen_helper_set_mac_exts(cpu_env
, val
, acc
);
5865 gen_helper_set_mac_extu(cpu_env
, val
, acc
);
5868 static disas_proc opcode_table
[65536];
5871 register_opcode (disas_proc proc
, uint16_t opcode
, uint16_t mask
)
5877 /* Sanity check. All set bits must be included in the mask. */
5878 if (opcode
& ~mask
) {
5880 "qemu internal error: bogus opcode definition %04x/%04x\n",
5885 * This could probably be cleverer. For now just optimize the case where
5886 * the top bits are known.
5888 /* Find the first zero bit in the mask. */
5890 while ((i
& mask
) != 0)
5892 /* Iterate over all combinations of this and lower bits. */
5897 from
= opcode
& ~(i
- 1);
5899 for (i
= from
; i
< to
; i
++) {
5900 if ((i
& mask
) == opcode
)
5901 opcode_table
[i
] = proc
;
5906 * Register m68k opcode handlers. Order is important.
5907 * Later insn override earlier ones.
5909 void register_m68k_insns (CPUM68KState
*env
)
5912 * Build the opcode table only once to avoid
5913 * multithreading issues.
5915 if (opcode_table
[0] != NULL
) {
5920 * use BASE() for instruction available
5921 * for CF_ISA_A and M68000.
5923 #define BASE(name, opcode, mask) \
5924 register_opcode(disas_##name, 0x##opcode, 0x##mask)
5925 #define INSN(name, opcode, mask, feature) do { \
5926 if (m68k_feature(env, M68K_FEATURE_##feature)) \
5927 BASE(name, opcode, mask); \
5929 BASE(undef
, 0000, 0000);
5930 INSN(arith_im
, 0080, fff8
, CF_ISA_A
);
5931 INSN(arith_im
, 0000, ff00
, M68000
);
5932 INSN(chk2
, 00c0
, f9c0
, CHK2
);
5933 INSN(bitrev
, 00c0
, fff8
, CF_ISA_APLUSC
);
5934 BASE(bitop_reg
, 0100, f1c0
);
5935 BASE(bitop_reg
, 0140, f1c0
);
5936 BASE(bitop_reg
, 0180, f1c0
);
5937 BASE(bitop_reg
, 01c0
, f1c0
);
5938 INSN(movep
, 0108, f138
, MOVEP
);
5939 INSN(arith_im
, 0280, fff8
, CF_ISA_A
);
5940 INSN(arith_im
, 0200, ff00
, M68000
);
5941 INSN(undef
, 02c0
, ffc0
, M68000
);
5942 INSN(byterev
, 02c0
, fff8
, CF_ISA_APLUSC
);
5943 INSN(arith_im
, 0480, fff8
, CF_ISA_A
);
5944 INSN(arith_im
, 0400, ff00
, M68000
);
5945 INSN(undef
, 04c0
, ffc0
, M68000
);
5946 INSN(arith_im
, 0600, ff00
, M68000
);
5947 INSN(undef
, 06c0
, ffc0
, M68000
);
5948 INSN(ff1
, 04c0
, fff8
, CF_ISA_APLUSC
);
5949 INSN(arith_im
, 0680, fff8
, CF_ISA_A
);
5950 INSN(arith_im
, 0c00
, ff38
, CF_ISA_A
);
5951 INSN(arith_im
, 0c00
, ff00
, M68000
);
5952 BASE(bitop_im
, 0800, ffc0
);
5953 BASE(bitop_im
, 0840, ffc0
);
5954 BASE(bitop_im
, 0880, ffc0
);
5955 BASE(bitop_im
, 08c0
, ffc0
);
5956 INSN(arith_im
, 0a80
, fff8
, CF_ISA_A
);
5957 INSN(arith_im
, 0a00
, ff00
, M68000
);
5958 #if defined(CONFIG_SOFTMMU)
5959 INSN(moves
, 0e00
, ff00
, M68000
);
5961 INSN(cas
, 0ac0
, ffc0
, CAS
);
5962 INSN(cas
, 0cc0
, ffc0
, CAS
);
5963 INSN(cas
, 0ec0
, ffc0
, CAS
);
5964 INSN(cas2w
, 0cfc
, ffff
, CAS
);
5965 INSN(cas2l
, 0efc
, ffff
, CAS
);
5966 BASE(move
, 1000, f000
);
5967 BASE(move
, 2000, f000
);
5968 BASE(move
, 3000, f000
);
5969 INSN(chk
, 4000, f040
, M68000
);
5970 INSN(strldsr
, 40e7
, ffff
, CF_ISA_APLUSC
);
5971 INSN(negx
, 4080, fff8
, CF_ISA_A
);
5972 INSN(negx
, 4000, ff00
, M68000
);
5973 INSN(undef
, 40c0
, ffc0
, M68000
);
5974 INSN(move_from_sr
, 40c0
, fff8
, CF_ISA_A
);
5975 INSN(move_from_sr
, 40c0
, ffc0
, M68000
);
5976 BASE(lea
, 41c0
, f1c0
);
5977 BASE(clr
, 4200, ff00
);
5978 BASE(undef
, 42c0
, ffc0
);
5979 INSN(move_from_ccr
, 42c0
, fff8
, CF_ISA_A
);
5980 INSN(move_from_ccr
, 42c0
, ffc0
, M68000
);
5981 INSN(neg
, 4480, fff8
, CF_ISA_A
);
5982 INSN(neg
, 4400, ff00
, M68000
);
5983 INSN(undef
, 44c0
, ffc0
, M68000
);
5984 BASE(move_to_ccr
, 44c0
, ffc0
);
5985 INSN(not, 4680, fff8
, CF_ISA_A
);
5986 INSN(not, 4600, ff00
, M68000
);
5987 #if defined(CONFIG_SOFTMMU)
5988 BASE(move_to_sr
, 46c0
, ffc0
);
5990 INSN(nbcd
, 4800, ffc0
, M68000
);
5991 INSN(linkl
, 4808, fff8
, M68000
);
5992 BASE(pea
, 4840, ffc0
);
5993 BASE(swap
, 4840, fff8
);
5994 INSN(bkpt
, 4848, fff8
, BKPT
);
5995 INSN(movem
, 48d0
, fbf8
, CF_ISA_A
);
5996 INSN(movem
, 48e8
, fbf8
, CF_ISA_A
);
5997 INSN(movem
, 4880, fb80
, M68000
);
5998 BASE(ext
, 4880, fff8
);
5999 BASE(ext
, 48c0
, fff8
);
6000 BASE(ext
, 49c0
, fff8
);
6001 BASE(tst
, 4a00
, ff00
);
6002 INSN(tas
, 4ac0
, ffc0
, CF_ISA_B
);
6003 INSN(tas
, 4ac0
, ffc0
, M68000
);
6004 #if defined(CONFIG_SOFTMMU)
6005 INSN(halt
, 4ac8
, ffff
, CF_ISA_A
);
6007 INSN(pulse
, 4acc
, ffff
, CF_ISA_A
);
6008 BASE(illegal
, 4afc
, ffff
);
6009 INSN(mull
, 4c00
, ffc0
, CF_ISA_A
);
6010 INSN(mull
, 4c00
, ffc0
, LONG_MULDIV
);
6011 INSN(divl
, 4c40
, ffc0
, CF_ISA_A
);
6012 INSN(divl
, 4c40
, ffc0
, LONG_MULDIV
);
6013 INSN(sats
, 4c80
, fff8
, CF_ISA_B
);
6014 BASE(trap
, 4e40
, fff0
);
6015 BASE(link
, 4e50
, fff8
);
6016 BASE(unlk
, 4e58
, fff8
);
6017 #if defined(CONFIG_SOFTMMU)
6018 INSN(move_to_usp
, 4e60
, fff8
, USP
);
6019 INSN(move_from_usp
, 4e68
, fff8
, USP
);
6020 INSN(reset
, 4e70
, ffff
, M68000
);
6021 BASE(stop
, 4e72
, ffff
);
6022 BASE(rte
, 4e73
, ffff
);
6023 INSN(cf_movec
, 4e7b
, ffff
, CF_ISA_A
);
6024 INSN(m68k_movec
, 4e7a
, fffe
, MOVEC
);
6026 BASE(nop
, 4e71
, ffff
);
6027 INSN(rtd
, 4e74
, ffff
, RTD
);
6028 BASE(rts
, 4e75
, ffff
);
6029 INSN(rtr
, 4e77
, ffff
, M68000
);
6030 BASE(jump
, 4e80
, ffc0
);
6031 BASE(jump
, 4ec0
, ffc0
);
6032 INSN(addsubq
, 5000, f080
, M68000
);
6033 BASE(addsubq
, 5080, f0c0
);
6034 INSN(scc
, 50c0
, f0f8
, CF_ISA_A
); /* Scc.B Dx */
6035 INSN(scc
, 50c0
, f0c0
, M68000
); /* Scc.B <EA> */
6036 INSN(dbcc
, 50c8
, f0f8
, M68000
);
6037 INSN(tpf
, 51f8
, fff8
, CF_ISA_A
);
6039 /* Branch instructions. */
6040 BASE(branch
, 6000, f000
);
6041 /* Disable long branch instructions, then add back the ones we want. */
6042 BASE(undef
, 60ff
, f0ff
); /* All long branches. */
6043 INSN(branch
, 60ff
, f0ff
, CF_ISA_B
);
6044 INSN(undef
, 60ff
, ffff
, CF_ISA_B
); /* bra.l */
6045 INSN(branch
, 60ff
, ffff
, BRAL
);
6046 INSN(branch
, 60ff
, f0ff
, BCCL
);
6048 BASE(moveq
, 7000, f100
);
6049 INSN(mvzs
, 7100, f100
, CF_ISA_B
);
6050 BASE(or, 8000, f000
);
6051 BASE(divw
, 80c0
, f0c0
);
6052 INSN(sbcd_reg
, 8100, f1f8
, M68000
);
6053 INSN(sbcd_mem
, 8108, f1f8
, M68000
);
6054 BASE(addsub
, 9000, f000
);
6055 INSN(undef
, 90c0
, f0c0
, CF_ISA_A
);
6056 INSN(subx_reg
, 9180, f1f8
, CF_ISA_A
);
6057 INSN(subx_reg
, 9100, f138
, M68000
);
6058 INSN(subx_mem
, 9108, f138
, M68000
);
6059 INSN(suba
, 91c0
, f1c0
, CF_ISA_A
);
6060 INSN(suba
, 90c0
, f0c0
, M68000
);
6062 BASE(undef_mac
, a000
, f000
);
6063 INSN(mac
, a000
, f100
, CF_EMAC
);
6064 INSN(from_mac
, a180
, f9b0
, CF_EMAC
);
6065 INSN(move_mac
, a110
, f9fc
, CF_EMAC
);
6066 INSN(from_macsr
,a980
, f9f0
, CF_EMAC
);
6067 INSN(from_mask
, ad80
, fff0
, CF_EMAC
);
6068 INSN(from_mext
, ab80
, fbf0
, CF_EMAC
);
6069 INSN(macsr_to_ccr
, a9c0
, ffff
, CF_EMAC
);
6070 INSN(to_mac
, a100
, f9c0
, CF_EMAC
);
6071 INSN(to_macsr
, a900
, ffc0
, CF_EMAC
);
6072 INSN(to_mext
, ab00
, fbc0
, CF_EMAC
);
6073 INSN(to_mask
, ad00
, ffc0
, CF_EMAC
);
6075 INSN(mov3q
, a140
, f1c0
, CF_ISA_B
);
6076 INSN(cmp
, b000
, f1c0
, CF_ISA_B
); /* cmp.b */
6077 INSN(cmp
, b040
, f1c0
, CF_ISA_B
); /* cmp.w */
6078 INSN(cmpa
, b0c0
, f1c0
, CF_ISA_B
); /* cmpa.w */
6079 INSN(cmp
, b080
, f1c0
, CF_ISA_A
);
6080 INSN(cmpa
, b1c0
, f1c0
, CF_ISA_A
);
6081 INSN(cmp
, b000
, f100
, M68000
);
6082 INSN(eor
, b100
, f100
, M68000
);
6083 INSN(cmpm
, b108
, f138
, M68000
);
6084 INSN(cmpa
, b0c0
, f0c0
, M68000
);
6085 INSN(eor
, b180
, f1c0
, CF_ISA_A
);
6086 BASE(and, c000
, f000
);
6087 INSN(exg_dd
, c140
, f1f8
, M68000
);
6088 INSN(exg_aa
, c148
, f1f8
, M68000
);
6089 INSN(exg_da
, c188
, f1f8
, M68000
);
6090 BASE(mulw
, c0c0
, f0c0
);
6091 INSN(abcd_reg
, c100
, f1f8
, M68000
);
6092 INSN(abcd_mem
, c108
, f1f8
, M68000
);
6093 BASE(addsub
, d000
, f000
);
6094 INSN(undef
, d0c0
, f0c0
, CF_ISA_A
);
6095 INSN(addx_reg
, d180
, f1f8
, CF_ISA_A
);
6096 INSN(addx_reg
, d100
, f138
, M68000
);
6097 INSN(addx_mem
, d108
, f138
, M68000
);
6098 INSN(adda
, d1c0
, f1c0
, CF_ISA_A
);
6099 INSN(adda
, d0c0
, f0c0
, M68000
);
6100 INSN(shift_im
, e080
, f0f0
, CF_ISA_A
);
6101 INSN(shift_reg
, e0a0
, f0f0
, CF_ISA_A
);
6102 INSN(shift8_im
, e000
, f0f0
, M68000
);
6103 INSN(shift16_im
, e040
, f0f0
, M68000
);
6104 INSN(shift_im
, e080
, f0f0
, M68000
);
6105 INSN(shift8_reg
, e020
, f0f0
, M68000
);
6106 INSN(shift16_reg
, e060
, f0f0
, M68000
);
6107 INSN(shift_reg
, e0a0
, f0f0
, M68000
);
6108 INSN(shift_mem
, e0c0
, fcc0
, M68000
);
6109 INSN(rotate_im
, e090
, f0f0
, M68000
);
6110 INSN(rotate8_im
, e010
, f0f0
, M68000
);
6111 INSN(rotate16_im
, e050
, f0f0
, M68000
);
6112 INSN(rotate_reg
, e0b0
, f0f0
, M68000
);
6113 INSN(rotate8_reg
, e030
, f0f0
, M68000
);
6114 INSN(rotate16_reg
, e070
, f0f0
, M68000
);
6115 INSN(rotate_mem
, e4c0
, fcc0
, M68000
);
6116 INSN(bfext_mem
, e9c0
, fdc0
, BITFIELD
); /* bfextu & bfexts */
6117 INSN(bfext_reg
, e9c0
, fdf8
, BITFIELD
);
6118 INSN(bfins_mem
, efc0
, ffc0
, BITFIELD
);
6119 INSN(bfins_reg
, efc0
, fff8
, BITFIELD
);
6120 INSN(bfop_mem
, eac0
, ffc0
, BITFIELD
); /* bfchg */
6121 INSN(bfop_reg
, eac0
, fff8
, BITFIELD
); /* bfchg */
6122 INSN(bfop_mem
, ecc0
, ffc0
, BITFIELD
); /* bfclr */
6123 INSN(bfop_reg
, ecc0
, fff8
, BITFIELD
); /* bfclr */
6124 INSN(bfop_mem
, edc0
, ffc0
, BITFIELD
); /* bfffo */
6125 INSN(bfop_reg
, edc0
, fff8
, BITFIELD
); /* bfffo */
6126 INSN(bfop_mem
, eec0
, ffc0
, BITFIELD
); /* bfset */
6127 INSN(bfop_reg
, eec0
, fff8
, BITFIELD
); /* bfset */
6128 INSN(bfop_mem
, e8c0
, ffc0
, BITFIELD
); /* bftst */
6129 INSN(bfop_reg
, e8c0
, fff8
, BITFIELD
); /* bftst */
6130 BASE(undef_fpu
, f000
, f000
);
6131 INSN(fpu
, f200
, ffc0
, CF_FPU
);
6132 INSN(fbcc
, f280
, ffc0
, CF_FPU
);
6133 INSN(fpu
, f200
, ffc0
, FPU
);
6134 INSN(fscc
, f240
, ffc0
, FPU
);
6135 INSN(fbcc
, f280
, ff80
, FPU
);
6136 #if defined(CONFIG_SOFTMMU)
6137 INSN(frestore
, f340
, ffc0
, CF_FPU
);
6138 INSN(fsave
, f300
, ffc0
, CF_FPU
);
6139 INSN(frestore
, f340
, ffc0
, FPU
);
6140 INSN(fsave
, f300
, ffc0
, FPU
);
6141 INSN(intouch
, f340
, ffc0
, CF_ISA_A
);
6142 INSN(cpushl
, f428
, ff38
, CF_ISA_A
);
6143 INSN(cpush
, f420
, ff20
, M68040
);
6144 INSN(cinv
, f400
, ff20
, M68040
);
6145 INSN(pflush
, f500
, ffe0
, M68040
);
6146 INSN(ptest
, f548
, ffd8
, M68040
);
6147 INSN(wddata
, fb00
, ff00
, CF_ISA_A
);
6148 INSN(wdebug
, fbc0
, ffc0
, CF_ISA_A
);
6150 INSN(move16_mem
, f600
, ffe0
, M68040
);
6151 INSN(move16_reg
, f620
, fff8
, M68040
);
6155 static void m68k_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cpu
)
6157 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6158 CPUM68KState
*env
= cpu
->env_ptr
;
6161 dc
->pc
= dc
->base
.pc_first
;
6162 dc
->cc_op
= CC_OP_DYNAMIC
;
6163 dc
->cc_op_synced
= 1;
6165 dc
->writeback_mask
= 0;
6166 init_release_array(dc
);
6168 dc
->ss_active
= (M68K_SR_TRACE(env
->sr
) == M68K_SR_TRACE_ANY_INS
);
6169 /* If architectural single step active, limit to 1 */
6170 if (dc
->ss_active
) {
6171 dc
->base
.max_insns
= 1;
6175 static void m68k_tr_tb_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6179 static void m68k_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6181 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6182 tcg_gen_insn_start(dc
->base
.pc_next
, dc
->cc_op
);
6185 static void m68k_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
6187 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6188 CPUM68KState
*env
= cpu
->env_ptr
;
6189 uint16_t insn
= read_im16(env
, dc
);
6191 opcode_table
[insn
](env
, dc
, insn
);
6195 dc
->base
.pc_next
= dc
->pc
;
6197 if (dc
->base
.is_jmp
== DISAS_NEXT
) {
6199 * Stop translation when the next insn might touch a new page.
6200 * This ensures that prefetch aborts at the right place.
6202 * We cannot determine the size of the next insn without
6203 * completely decoding it. However, the maximum insn size
6204 * is 32 bytes, so end if we do not have that much remaining.
6205 * This may produce several small TBs at the end of each page,
6206 * but they will all be linked with goto_tb.
6208 * ??? ColdFire maximum is 4 bytes; MC68000's maximum is also
6209 * smaller than MC68020's.
6211 target_ulong start_page_offset
6212 = dc
->pc
- (dc
->base
.pc_first
& TARGET_PAGE_MASK
);
6214 if (start_page_offset
>= TARGET_PAGE_SIZE
- 32) {
6215 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
6220 static void m68k_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
6222 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6224 switch (dc
->base
.is_jmp
) {
6225 case DISAS_NORETURN
:
6227 case DISAS_TOO_MANY
:
6229 if (dc
->ss_active
) {
6230 tcg_gen_movi_i32(QREG_PC
, dc
->pc
);
6231 gen_raise_exception(EXCP_TRACE
);
6233 gen_jmp_tb(dc
, 0, dc
->pc
);
6237 /* We updated CC_OP and PC in gen_jmp/gen_jmp_im. */
6238 if (dc
->ss_active
) {
6239 gen_raise_exception(EXCP_TRACE
);
6241 tcg_gen_lookup_and_goto_ptr();
6246 * We updated CC_OP and PC in gen_exit_tb, but also modified
6247 * other state that may require returning to the main loop.
6249 if (dc
->ss_active
) {
6250 gen_raise_exception(EXCP_TRACE
);
6252 tcg_gen_exit_tb(NULL
, 0);
6256 g_assert_not_reached();
6260 static void m68k_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cpu
)
6262 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
6263 log_target_disas(cpu
, dcbase
->pc_first
, dcbase
->tb
->size
);
6266 static const TranslatorOps m68k_tr_ops
= {
6267 .init_disas_context
= m68k_tr_init_disas_context
,
6268 .tb_start
= m68k_tr_tb_start
,
6269 .insn_start
= m68k_tr_insn_start
,
6270 .translate_insn
= m68k_tr_translate_insn
,
6271 .tb_stop
= m68k_tr_tb_stop
,
6272 .disas_log
= m68k_tr_disas_log
,
6275 void gen_intermediate_code(CPUState
*cpu
, TranslationBlock
*tb
, int max_insns
)
6278 translator_loop(&m68k_tr_ops
, &dc
.base
, cpu
, tb
, max_insns
);
6281 static double floatx80_to_double(CPUM68KState
*env
, uint16_t high
, uint64_t low
)
6283 floatx80 a
= { .high
= high
, .low
= low
};
6289 u
.f64
= floatx80_to_float64(a
, &env
->fp_status
);
6293 void m68k_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
6295 M68kCPU
*cpu
= M68K_CPU(cs
);
6296 CPUM68KState
*env
= &cpu
->env
;
6299 for (i
= 0; i
< 8; i
++) {
6300 qemu_fprintf(f
, "D%d = %08x A%d = %08x "
6301 "F%d = %04x %016"PRIx64
" (%12g)\n",
6302 i
, env
->dregs
[i
], i
, env
->aregs
[i
],
6303 i
, env
->fregs
[i
].l
.upper
, env
->fregs
[i
].l
.lower
,
6304 floatx80_to_double(env
, env
->fregs
[i
].l
.upper
,
6305 env
->fregs
[i
].l
.lower
));
6307 qemu_fprintf(f
, "PC = %08x ", env
->pc
);
6308 sr
= env
->sr
| cpu_m68k_get_ccr(env
);
6309 qemu_fprintf(f
, "SR = %04x T:%x I:%x %c%c %c%c%c%c%c\n",
6310 sr
, (sr
& SR_T
) >> SR_T_SHIFT
, (sr
& SR_I
) >> SR_I_SHIFT
,
6311 (sr
& SR_S
) ? 'S' : 'U', (sr
& SR_M
) ? '%' : 'I',
6312 (sr
& CCF_X
) ? 'X' : '-', (sr
& CCF_N
) ? 'N' : '-',
6313 (sr
& CCF_Z
) ? 'Z' : '-', (sr
& CCF_V
) ? 'V' : '-',
6314 (sr
& CCF_C
) ? 'C' : '-');
6315 qemu_fprintf(f
, "FPSR = %08x %c%c%c%c ", env
->fpsr
,
6316 (env
->fpsr
& FPSR_CC_A
) ? 'A' : '-',
6317 (env
->fpsr
& FPSR_CC_I
) ? 'I' : '-',
6318 (env
->fpsr
& FPSR_CC_Z
) ? 'Z' : '-',
6319 (env
->fpsr
& FPSR_CC_N
) ? 'N' : '-');
6320 qemu_fprintf(f
, "\n "
6321 "FPCR = %04x ", env
->fpcr
);
6322 switch (env
->fpcr
& FPCR_PREC_MASK
) {
6324 qemu_fprintf(f
, "X ");
6327 qemu_fprintf(f
, "S ");
6330 qemu_fprintf(f
, "D ");
6333 switch (env
->fpcr
& FPCR_RND_MASK
) {
6335 qemu_fprintf(f
, "RN ");
6338 qemu_fprintf(f
, "RZ ");
6341 qemu_fprintf(f
, "RM ");
6344 qemu_fprintf(f
, "RP ");
6347 qemu_fprintf(f
, "\n");
6348 #ifdef CONFIG_SOFTMMU
6349 qemu_fprintf(f
, "%sA7(MSP) = %08x %sA7(USP) = %08x %sA7(ISP) = %08x\n",
6350 env
->current_sp
== M68K_SSP
? "->" : " ", env
->sp
[M68K_SSP
],
6351 env
->current_sp
== M68K_USP
? "->" : " ", env
->sp
[M68K_USP
],
6352 env
->current_sp
== M68K_ISP
? "->" : " ", env
->sp
[M68K_ISP
]);
6353 qemu_fprintf(f
, "VBR = 0x%08x\n", env
->vbr
);
6354 qemu_fprintf(f
, "SFC = %x DFC %x\n", env
->sfc
, env
->dfc
);
6355 qemu_fprintf(f
, "SSW %08x TCR %08x URP %08x SRP %08x\n",
6356 env
->mmu
.ssw
, env
->mmu
.tcr
, env
->mmu
.urp
, env
->mmu
.srp
);
6357 qemu_fprintf(f
, "DTTR0/1: %08x/%08x ITTR0/1: %08x/%08x\n",
6358 env
->mmu
.ttr
[M68K_DTTR0
], env
->mmu
.ttr
[M68K_DTTR1
],
6359 env
->mmu
.ttr
[M68K_ITTR0
], env
->mmu
.ttr
[M68K_ITTR1
]);
6360 qemu_fprintf(f
, "MMUSR %08x, fault at %08x\n",
6361 env
->mmu
.mmusr
, env
->mmu
.ar
);
6365 void restore_state_to_opc(CPUM68KState
*env
, TranslationBlock
*tb
,
6368 int cc_op
= data
[1];
6370 if (cc_op
!= CC_OP_DYNAMIC
) {