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"
34 #include "trace-tcg.h"
36 #include "fpu/softfloat.h"
39 //#define DEBUG_DISPATCH 1
41 #define DEFO32(name, offset) static TCGv QREG_##name;
42 #define DEFO64(name, offset) static TCGv_i64 QREG_##name;
47 static TCGv_i32 cpu_halted
;
48 static TCGv_i32 cpu_exception_index
;
50 static char cpu_reg_names
[2 * 8 * 3 + 5 * 4];
51 static TCGv cpu_dregs
[8];
52 static TCGv cpu_aregs
[8];
53 static TCGv_i64 cpu_macc
[4];
55 #define REG(insn, pos) (((insn) >> (pos)) & 7)
56 #define DREG(insn, pos) cpu_dregs[REG(insn, pos)]
57 #define AREG(insn, pos) get_areg(s, REG(insn, pos))
58 #define MACREG(acc) cpu_macc[acc]
59 #define QREG_SP get_areg(s, 7)
61 static TCGv NULL_QREG
;
62 #define IS_NULL_QREG(t) (t == NULL_QREG)
63 /* Used to distinguish stores from bad addressing modes. */
64 static TCGv store_dummy
;
66 #include "exec/gen-icount.h"
68 void m68k_tcg_init(void)
73 #define DEFO32(name, offset) \
74 QREG_##name = tcg_global_mem_new_i32(cpu_env, \
75 offsetof(CPUM68KState, offset), #name);
76 #define DEFO64(name, offset) \
77 QREG_##name = tcg_global_mem_new_i64(cpu_env, \
78 offsetof(CPUM68KState, offset), #name);
83 cpu_halted
= tcg_global_mem_new_i32(cpu_env
,
84 -offsetof(M68kCPU
, env
) +
85 offsetof(CPUState
, halted
), "HALTED");
86 cpu_exception_index
= tcg_global_mem_new_i32(cpu_env
,
87 -offsetof(M68kCPU
, env
) +
88 offsetof(CPUState
, exception_index
),
92 for (i
= 0; i
< 8; i
++) {
94 cpu_dregs
[i
] = tcg_global_mem_new(cpu_env
,
95 offsetof(CPUM68KState
, dregs
[i
]), p
);
98 cpu_aregs
[i
] = tcg_global_mem_new(cpu_env
,
99 offsetof(CPUM68KState
, aregs
[i
]), p
);
102 for (i
= 0; i
< 4; i
++) {
103 sprintf(p
, "ACC%d", i
);
104 cpu_macc
[i
] = tcg_global_mem_new_i64(cpu_env
,
105 offsetof(CPUM68KState
, macc
[i
]), p
);
109 NULL_QREG
= tcg_global_mem_new(cpu_env
, -4, "NULL");
110 store_dummy
= tcg_global_mem_new(cpu_env
, -8, "NULL");
113 /* internal defines */
114 typedef struct DisasContext
{
115 DisasContextBase base
;
118 CCOp cc_op
; /* Current CC operation */
124 #define MAX_TO_RELEASE 8
126 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 static bool is_singlestepping(DisasContext
*s
)
200 * Return true if we are singlestepping either because of QEMU gdbstub
201 * singlestep. This does not include the command line '-singlestep' mode
202 * which is rather misnamed as it only means "one instruction per TB" and
203 * doesn't affect the code we generate.
205 return s
->base
.singlestep_enabled
;
208 /* is_jmp field values */
209 #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
210 #define DISAS_EXIT DISAS_TARGET_1 /* cpu state was modified dynamically */
212 #if defined(CONFIG_USER_ONLY)
215 #define IS_USER(s) (!(s->base.tb->flags & TB_FLAGS_MSR_S))
216 #define SFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_SFC_S) ? \
217 MMU_KERNEL_IDX : MMU_USER_IDX)
218 #define DFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_DFC_S) ? \
219 MMU_KERNEL_IDX : MMU_USER_IDX)
222 typedef void (*disas_proc
)(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
);
224 #ifdef DEBUG_DISPATCH
225 #define DISAS_INSN(name) \
226 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
228 static void disas_##name(CPUM68KState *env, DisasContext *s, \
231 qemu_log("Dispatch " #name "\n"); \
232 real_disas_##name(env, s, insn); \
234 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
237 #define DISAS_INSN(name) \
238 static void disas_##name(CPUM68KState *env, DisasContext *s, \
242 static const uint8_t cc_op_live
[CC_OP_NB
] = {
243 [CC_OP_DYNAMIC
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
244 [CC_OP_FLAGS
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
245 [CC_OP_ADDB
... CC_OP_ADDL
] = CCF_X
| CCF_N
| CCF_V
,
246 [CC_OP_SUBB
... CC_OP_SUBL
] = CCF_X
| CCF_N
| CCF_V
,
247 [CC_OP_CMPB
... CC_OP_CMPL
] = CCF_X
| CCF_N
| CCF_V
,
248 [CC_OP_LOGIC
] = CCF_X
| CCF_N
251 static void set_cc_op(DisasContext
*s
, CCOp op
)
253 CCOp old_op
= s
->cc_op
;
263 * Discard CC computation that will no longer be used.
264 * Note that X and N are never dead.
266 dead
= cc_op_live
[old_op
] & ~cc_op_live
[op
];
268 tcg_gen_discard_i32(QREG_CC_C
);
271 tcg_gen_discard_i32(QREG_CC_Z
);
274 tcg_gen_discard_i32(QREG_CC_V
);
278 /* Update the CPU env CC_OP state. */
279 static void update_cc_op(DisasContext
*s
)
281 if (!s
->cc_op_synced
) {
283 tcg_gen_movi_i32(QREG_CC_OP
, s
->cc_op
);
287 /* Generate a jump to an immediate address. */
288 static void gen_jmp_im(DisasContext
*s
, uint32_t dest
)
291 tcg_gen_movi_i32(QREG_PC
, dest
);
292 s
->base
.is_jmp
= DISAS_JUMP
;
295 /* Generate a jump to the address in qreg DEST. */
296 static void gen_jmp(DisasContext
*s
, TCGv dest
)
299 tcg_gen_mov_i32(QREG_PC
, dest
);
300 s
->base
.is_jmp
= DISAS_JUMP
;
303 static void gen_raise_exception(int nr
)
307 tmp
= tcg_const_i32(nr
);
308 gen_helper_raise_exception(cpu_env
, tmp
);
309 tcg_temp_free_i32(tmp
);
312 static void gen_exception(DisasContext
*s
, uint32_t dest
, int nr
)
315 tcg_gen_movi_i32(QREG_PC
, dest
);
317 gen_raise_exception(nr
);
319 s
->base
.is_jmp
= DISAS_NORETURN
;
322 static inline void gen_addr_fault(DisasContext
*s
)
324 gen_exception(s
, s
->base
.pc_next
, EXCP_ADDRESS
);
328 * Generate a load from the specified address. Narrow values are
329 * sign extended to full register width.
331 static inline TCGv
gen_load(DisasContext
*s
, int opsize
, TCGv addr
,
335 tmp
= tcg_temp_new_i32();
339 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
341 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
345 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
347 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
350 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
353 g_assert_not_reached();
358 /* Generate a store. */
359 static inline void gen_store(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
364 tcg_gen_qemu_st8(val
, addr
, index
);
367 tcg_gen_qemu_st16(val
, addr
, index
);
370 tcg_gen_qemu_st32(val
, addr
, index
);
373 g_assert_not_reached();
384 * Generate an unsigned load if VAL is 0 a signed load if val is -1,
385 * otherwise generate a store.
387 static TCGv
gen_ldst(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
388 ea_what what
, int index
)
390 if (what
== EA_STORE
) {
391 gen_store(s
, opsize
, addr
, val
, index
);
394 return mark_to_release(s
, gen_load(s
, opsize
, addr
,
395 what
== EA_LOADS
, index
));
399 /* Read a 16-bit immediate constant */
400 static inline uint16_t read_im16(CPUM68KState
*env
, DisasContext
*s
)
403 im
= translator_lduw(env
, s
->pc
);
408 /* Read an 8-bit immediate constant */
409 static inline uint8_t read_im8(CPUM68KState
*env
, DisasContext
*s
)
411 return read_im16(env
, s
);
414 /* Read a 32-bit immediate constant. */
415 static inline uint32_t read_im32(CPUM68KState
*env
, DisasContext
*s
)
418 im
= read_im16(env
, s
) << 16;
419 im
|= 0xffff & read_im16(env
, s
);
423 /* Read a 64-bit immediate constant. */
424 static inline uint64_t read_im64(CPUM68KState
*env
, DisasContext
*s
)
427 im
= (uint64_t)read_im32(env
, s
) << 32;
428 im
|= (uint64_t)read_im32(env
, s
);
432 /* Calculate and address index. */
433 static TCGv
gen_addr_index(DisasContext
*s
, uint16_t ext
, TCGv tmp
)
438 add
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(ext
, 12);
439 if ((ext
& 0x800) == 0) {
440 tcg_gen_ext16s_i32(tmp
, add
);
443 scale
= (ext
>> 9) & 3;
445 tcg_gen_shli_i32(tmp
, add
, scale
);
452 * Handle a base + index + displacement effective address.
453 * A NULL_QREG base means pc-relative.
455 static TCGv
gen_lea_indexed(CPUM68KState
*env
, DisasContext
*s
, TCGv base
)
464 ext
= read_im16(env
, s
);
466 if ((ext
& 0x800) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_WORD_INDEX
))
469 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
) &&
470 !m68k_feature(s
->env
, M68K_FEATURE_SCALED_INDEX
)) {
475 /* full extension word format */
476 if (!m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
))
479 if ((ext
& 0x30) > 0x10) {
480 /* base displacement */
481 if ((ext
& 0x30) == 0x20) {
482 bd
= (int16_t)read_im16(env
, s
);
484 bd
= read_im32(env
, s
);
489 tmp
= mark_to_release(s
, tcg_temp_new());
490 if ((ext
& 0x44) == 0) {
492 add
= gen_addr_index(s
, ext
, tmp
);
496 if ((ext
& 0x80) == 0) {
497 /* base not suppressed */
498 if (IS_NULL_QREG(base
)) {
499 base
= mark_to_release(s
, tcg_const_i32(offset
+ bd
));
502 if (!IS_NULL_QREG(add
)) {
503 tcg_gen_add_i32(tmp
, add
, base
);
509 if (!IS_NULL_QREG(add
)) {
511 tcg_gen_addi_i32(tmp
, add
, bd
);
515 add
= mark_to_release(s
, tcg_const_i32(bd
));
517 if ((ext
& 3) != 0) {
518 /* memory indirect */
519 base
= mark_to_release(s
, gen_load(s
, OS_LONG
, add
, 0, IS_USER(s
)));
520 if ((ext
& 0x44) == 4) {
521 add
= gen_addr_index(s
, ext
, tmp
);
522 tcg_gen_add_i32(tmp
, add
, base
);
528 /* outer displacement */
529 if ((ext
& 3) == 2) {
530 od
= (int16_t)read_im16(env
, s
);
532 od
= read_im32(env
, s
);
538 tcg_gen_addi_i32(tmp
, add
, od
);
543 /* brief extension word format */
544 tmp
= mark_to_release(s
, tcg_temp_new());
545 add
= gen_addr_index(s
, ext
, tmp
);
546 if (!IS_NULL_QREG(base
)) {
547 tcg_gen_add_i32(tmp
, add
, base
);
549 tcg_gen_addi_i32(tmp
, tmp
, (int8_t)ext
);
551 tcg_gen_addi_i32(tmp
, add
, offset
+ (int8_t)ext
);
558 /* Sign or zero extend a value. */
560 static inline void gen_ext(TCGv res
, TCGv val
, int opsize
, int sign
)
565 tcg_gen_ext8s_i32(res
, val
);
567 tcg_gen_ext8u_i32(res
, val
);
572 tcg_gen_ext16s_i32(res
, val
);
574 tcg_gen_ext16u_i32(res
, val
);
578 tcg_gen_mov_i32(res
, val
);
581 g_assert_not_reached();
585 /* Evaluate all the CC flags. */
587 static void gen_flush_flags(DisasContext
*s
)
598 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
599 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
600 /* Compute signed overflow for addition. */
603 tcg_gen_sub_i32(t0
, QREG_CC_N
, QREG_CC_V
);
604 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_ADDB
, 1);
605 tcg_gen_xor_i32(t1
, QREG_CC_N
, QREG_CC_V
);
606 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
608 tcg_gen_andc_i32(QREG_CC_V
, t1
, QREG_CC_V
);
615 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
616 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
617 /* Compute signed overflow for subtraction. */
620 tcg_gen_add_i32(t0
, QREG_CC_N
, QREG_CC_V
);
621 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_SUBB
, 1);
622 tcg_gen_xor_i32(t1
, QREG_CC_N
, t0
);
623 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
625 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t1
);
632 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_C
, QREG_CC_N
, QREG_CC_V
);
633 tcg_gen_sub_i32(QREG_CC_Z
, QREG_CC_N
, QREG_CC_V
);
634 gen_ext(QREG_CC_Z
, QREG_CC_Z
, s
->cc_op
- CC_OP_CMPB
, 1);
635 /* Compute signed overflow for subtraction. */
637 tcg_gen_xor_i32(t0
, QREG_CC_Z
, QREG_CC_N
);
638 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, QREG_CC_N
);
639 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t0
);
641 tcg_gen_mov_i32(QREG_CC_N
, QREG_CC_Z
);
645 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
646 tcg_gen_movi_i32(QREG_CC_C
, 0);
647 tcg_gen_movi_i32(QREG_CC_V
, 0);
651 gen_helper_flush_flags(cpu_env
, QREG_CC_OP
);
656 t0
= tcg_const_i32(s
->cc_op
);
657 gen_helper_flush_flags(cpu_env
, t0
);
663 /* Note that flush_flags also assigned to env->cc_op. */
664 s
->cc_op
= CC_OP_FLAGS
;
667 static inline TCGv
gen_extend(DisasContext
*s
, TCGv val
, int opsize
, int sign
)
671 if (opsize
== OS_LONG
) {
674 tmp
= mark_to_release(s
, tcg_temp_new());
675 gen_ext(tmp
, val
, opsize
, sign
);
681 static void gen_logic_cc(DisasContext
*s
, TCGv val
, int opsize
)
683 gen_ext(QREG_CC_N
, val
, opsize
, 1);
684 set_cc_op(s
, CC_OP_LOGIC
);
687 static void gen_update_cc_cmp(DisasContext
*s
, TCGv dest
, TCGv src
, int opsize
)
689 tcg_gen_mov_i32(QREG_CC_N
, dest
);
690 tcg_gen_mov_i32(QREG_CC_V
, src
);
691 set_cc_op(s
, CC_OP_CMPB
+ opsize
);
694 static void gen_update_cc_add(TCGv dest
, TCGv src
, int opsize
)
696 gen_ext(QREG_CC_N
, dest
, opsize
, 1);
697 tcg_gen_mov_i32(QREG_CC_V
, src
);
700 static inline int opsize_bytes(int opsize
)
703 case OS_BYTE
: return 1;
704 case OS_WORD
: return 2;
705 case OS_LONG
: return 4;
706 case OS_SINGLE
: return 4;
707 case OS_DOUBLE
: return 8;
708 case OS_EXTENDED
: return 12;
709 case OS_PACKED
: return 12;
711 g_assert_not_reached();
715 static inline int insn_opsize(int insn
)
717 switch ((insn
>> 6) & 3) {
718 case 0: return OS_BYTE
;
719 case 1: return OS_WORD
;
720 case 2: return OS_LONG
;
722 g_assert_not_reached();
726 static inline int ext_opsize(int ext
, int pos
)
728 switch ((ext
>> pos
) & 7) {
729 case 0: return OS_LONG
;
730 case 1: return OS_SINGLE
;
731 case 2: return OS_EXTENDED
;
732 case 3: return OS_PACKED
;
733 case 4: return OS_WORD
;
734 case 5: return OS_DOUBLE
;
735 case 6: return OS_BYTE
;
737 g_assert_not_reached();
742 * Assign value to a register. If the width is less than the register width
743 * only the low part of the register is set.
745 static void gen_partset_reg(int opsize
, TCGv reg
, TCGv val
)
750 tcg_gen_andi_i32(reg
, reg
, 0xffffff00);
751 tmp
= tcg_temp_new();
752 tcg_gen_ext8u_i32(tmp
, val
);
753 tcg_gen_or_i32(reg
, reg
, tmp
);
757 tcg_gen_andi_i32(reg
, reg
, 0xffff0000);
758 tmp
= tcg_temp_new();
759 tcg_gen_ext16u_i32(tmp
, val
);
760 tcg_gen_or_i32(reg
, reg
, tmp
);
765 tcg_gen_mov_i32(reg
, val
);
768 g_assert_not_reached();
773 * Generate code for an "effective address". Does not adjust the base
774 * register for autoincrement addressing modes.
776 static TCGv
gen_lea_mode(CPUM68KState
*env
, DisasContext
*s
,
777 int mode
, int reg0
, int opsize
)
785 case 0: /* Data register direct. */
786 case 1: /* Address register direct. */
788 case 3: /* Indirect postincrement. */
789 if (opsize
== OS_UNSIZED
) {
793 case 2: /* Indirect register */
794 return get_areg(s
, reg0
);
795 case 4: /* Indirect predecrememnt. */
796 if (opsize
== OS_UNSIZED
) {
799 reg
= get_areg(s
, reg0
);
800 tmp
= mark_to_release(s
, tcg_temp_new());
801 if (reg0
== 7 && opsize
== OS_BYTE
&&
802 m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
803 tcg_gen_subi_i32(tmp
, reg
, 2);
805 tcg_gen_subi_i32(tmp
, reg
, opsize_bytes(opsize
));
808 case 5: /* Indirect displacement. */
809 reg
= get_areg(s
, reg0
);
810 tmp
= mark_to_release(s
, tcg_temp_new());
811 ext
= read_im16(env
, s
);
812 tcg_gen_addi_i32(tmp
, reg
, (int16_t)ext
);
814 case 6: /* Indirect index + displacement. */
815 reg
= get_areg(s
, reg0
);
816 return gen_lea_indexed(env
, s
, reg
);
819 case 0: /* Absolute short. */
820 offset
= (int16_t)read_im16(env
, s
);
821 return mark_to_release(s
, tcg_const_i32(offset
));
822 case 1: /* Absolute long. */
823 offset
= read_im32(env
, s
);
824 return mark_to_release(s
, tcg_const_i32(offset
));
825 case 2: /* pc displacement */
827 offset
+= (int16_t)read_im16(env
, s
);
828 return mark_to_release(s
, tcg_const_i32(offset
));
829 case 3: /* pc index+displacement. */
830 return gen_lea_indexed(env
, s
, NULL_QREG
);
831 case 4: /* Immediate. */
836 /* Should never happen. */
840 static TCGv
gen_lea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
843 int mode
= extract32(insn
, 3, 3);
844 int reg0
= REG(insn
, 0);
845 return gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
849 * Generate code to load/store a value from/into an EA. If WHAT > 0 this is
850 * a write otherwise it is a read (0 == sign extend, -1 == zero extend).
851 * ADDRP is non-null for readwrite operands.
853 static TCGv
gen_ea_mode(CPUM68KState
*env
, DisasContext
*s
, int mode
, int reg0
,
854 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
,
857 TCGv reg
, tmp
, result
;
861 case 0: /* Data register direct. */
862 reg
= cpu_dregs
[reg0
];
863 if (what
== EA_STORE
) {
864 gen_partset_reg(opsize
, reg
, val
);
867 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
869 case 1: /* Address register direct. */
870 reg
= get_areg(s
, reg0
);
871 if (what
== EA_STORE
) {
872 tcg_gen_mov_i32(reg
, val
);
875 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
877 case 2: /* Indirect register */
878 reg
= get_areg(s
, reg0
);
879 return gen_ldst(s
, opsize
, reg
, val
, what
, index
);
880 case 3: /* Indirect postincrement. */
881 reg
= get_areg(s
, reg0
);
882 result
= gen_ldst(s
, opsize
, reg
, val
, what
, index
);
883 if (what
== EA_STORE
|| !addrp
) {
884 TCGv tmp
= tcg_temp_new();
885 if (reg0
== 7 && opsize
== OS_BYTE
&&
886 m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
887 tcg_gen_addi_i32(tmp
, reg
, 2);
889 tcg_gen_addi_i32(tmp
, reg
, opsize_bytes(opsize
));
891 delay_set_areg(s
, reg0
, tmp
, true);
894 case 4: /* Indirect predecrememnt. */
895 if (addrp
&& what
== EA_STORE
) {
898 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
899 if (IS_NULL_QREG(tmp
)) {
906 result
= gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
907 if (what
== EA_STORE
|| !addrp
) {
908 delay_set_areg(s
, reg0
, tmp
, false);
911 case 5: /* Indirect displacement. */
912 case 6: /* Indirect index + displacement. */
914 if (addrp
&& what
== EA_STORE
) {
917 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
918 if (IS_NULL_QREG(tmp
)) {
925 return gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
928 case 0: /* Absolute short. */
929 case 1: /* Absolute long. */
930 case 2: /* pc displacement */
931 case 3: /* pc index+displacement. */
933 case 4: /* Immediate. */
934 /* Sign extend values for consistency. */
937 if (what
== EA_LOADS
) {
938 offset
= (int8_t)read_im8(env
, s
);
940 offset
= read_im8(env
, s
);
944 if (what
== EA_LOADS
) {
945 offset
= (int16_t)read_im16(env
, s
);
947 offset
= read_im16(env
, s
);
951 offset
= read_im32(env
, s
);
954 g_assert_not_reached();
956 return mark_to_release(s
, tcg_const_i32(offset
));
961 /* Should never happen. */
965 static TCGv
gen_ea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
966 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
, int index
)
968 int mode
= extract32(insn
, 3, 3);
969 int reg0
= REG(insn
, 0);
970 return gen_ea_mode(env
, s
, mode
, reg0
, opsize
, val
, addrp
, what
, index
);
973 static TCGv_ptr
gen_fp_ptr(int freg
)
975 TCGv_ptr fp
= tcg_temp_new_ptr();
976 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fregs
[freg
]));
980 static TCGv_ptr
gen_fp_result_ptr(void)
982 TCGv_ptr fp
= tcg_temp_new_ptr();
983 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fp_result
));
987 static void gen_fp_move(TCGv_ptr dest
, TCGv_ptr src
)
992 t32
= tcg_temp_new();
993 tcg_gen_ld16u_i32(t32
, src
, offsetof(FPReg
, l
.upper
));
994 tcg_gen_st16_i32(t32
, dest
, offsetof(FPReg
, l
.upper
));
997 t64
= tcg_temp_new_i64();
998 tcg_gen_ld_i64(t64
, src
, offsetof(FPReg
, l
.lower
));
999 tcg_gen_st_i64(t64
, dest
, offsetof(FPReg
, l
.lower
));
1000 tcg_temp_free_i64(t64
);
1003 static void gen_load_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
1009 t64
= tcg_temp_new_i64();
1010 tmp
= tcg_temp_new();
1013 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
1014 gen_helper_exts32(cpu_env
, fp
, tmp
);
1017 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
1018 gen_helper_exts32(cpu_env
, fp
, tmp
);
1021 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
1022 gen_helper_exts32(cpu_env
, fp
, tmp
);
1025 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
1026 gen_helper_extf32(cpu_env
, fp
, tmp
);
1029 tcg_gen_qemu_ld64(t64
, addr
, index
);
1030 gen_helper_extf64(cpu_env
, fp
, t64
);
1033 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1034 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1037 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
1038 tcg_gen_shri_i32(tmp
, tmp
, 16);
1039 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1040 tcg_gen_addi_i32(tmp
, addr
, 4);
1041 tcg_gen_qemu_ld64(t64
, tmp
, index
);
1042 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1046 * unimplemented data type on 68040/ColdFire
1047 * FIXME if needed for another FPU
1049 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1052 g_assert_not_reached();
1055 tcg_temp_free_i64(t64
);
1058 static void gen_store_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
1064 t64
= tcg_temp_new_i64();
1065 tmp
= tcg_temp_new();
1068 gen_helper_reds32(tmp
, cpu_env
, fp
);
1069 tcg_gen_qemu_st8(tmp
, addr
, index
);
1072 gen_helper_reds32(tmp
, cpu_env
, fp
);
1073 tcg_gen_qemu_st16(tmp
, addr
, index
);
1076 gen_helper_reds32(tmp
, cpu_env
, fp
);
1077 tcg_gen_qemu_st32(tmp
, addr
, index
);
1080 gen_helper_redf32(tmp
, cpu_env
, fp
);
1081 tcg_gen_qemu_st32(tmp
, addr
, index
);
1084 gen_helper_redf64(t64
, cpu_env
, fp
);
1085 tcg_gen_qemu_st64(t64
, addr
, index
);
1088 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1089 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1092 tcg_gen_ld16u_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1093 tcg_gen_shli_i32(tmp
, tmp
, 16);
1094 tcg_gen_qemu_st32(tmp
, addr
, index
);
1095 tcg_gen_addi_i32(tmp
, addr
, 4);
1096 tcg_gen_ld_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1097 tcg_gen_qemu_st64(t64
, tmp
, index
);
1101 * unimplemented data type on 68040/ColdFire
1102 * FIXME if needed for another FPU
1104 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1107 g_assert_not_reached();
1110 tcg_temp_free_i64(t64
);
1113 static void gen_ldst_fp(DisasContext
*s
, int opsize
, TCGv addr
,
1114 TCGv_ptr fp
, ea_what what
, int index
)
1116 if (what
== EA_STORE
) {
1117 gen_store_fp(s
, opsize
, addr
, fp
, index
);
1119 gen_load_fp(s
, opsize
, addr
, fp
, index
);
1123 static int gen_ea_mode_fp(CPUM68KState
*env
, DisasContext
*s
, int mode
,
1124 int reg0
, int opsize
, TCGv_ptr fp
, ea_what what
,
1127 TCGv reg
, addr
, tmp
;
1131 case 0: /* Data register direct. */
1132 reg
= cpu_dregs
[reg0
];
1133 if (what
== EA_STORE
) {
1138 gen_helper_reds32(reg
, cpu_env
, fp
);
1141 gen_helper_redf32(reg
, cpu_env
, fp
);
1144 g_assert_not_reached();
1147 tmp
= tcg_temp_new();
1150 tcg_gen_ext8s_i32(tmp
, reg
);
1151 gen_helper_exts32(cpu_env
, fp
, tmp
);
1154 tcg_gen_ext16s_i32(tmp
, reg
);
1155 gen_helper_exts32(cpu_env
, fp
, tmp
);
1158 gen_helper_exts32(cpu_env
, fp
, reg
);
1161 gen_helper_extf32(cpu_env
, fp
, reg
);
1164 g_assert_not_reached();
1169 case 1: /* Address register direct. */
1171 case 2: /* Indirect register */
1172 addr
= get_areg(s
, reg0
);
1173 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1175 case 3: /* Indirect postincrement. */
1176 addr
= cpu_aregs
[reg0
];
1177 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1178 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(opsize
));
1180 case 4: /* Indirect predecrememnt. */
1181 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1182 if (IS_NULL_QREG(addr
)) {
1185 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1186 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
1188 case 5: /* Indirect displacement. */
1189 case 6: /* Indirect index + displacement. */
1191 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1192 if (IS_NULL_QREG(addr
)) {
1195 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1199 case 0: /* Absolute short. */
1200 case 1: /* Absolute long. */
1201 case 2: /* pc displacement */
1202 case 3: /* pc index+displacement. */
1204 case 4: /* Immediate. */
1205 if (what
== EA_STORE
) {
1210 tmp
= tcg_const_i32((int8_t)read_im8(env
, s
));
1211 gen_helper_exts32(cpu_env
, fp
, tmp
);
1215 tmp
= tcg_const_i32((int16_t)read_im16(env
, s
));
1216 gen_helper_exts32(cpu_env
, fp
, tmp
);
1220 tmp
= tcg_const_i32(read_im32(env
, s
));
1221 gen_helper_exts32(cpu_env
, fp
, tmp
);
1225 tmp
= tcg_const_i32(read_im32(env
, s
));
1226 gen_helper_extf32(cpu_env
, fp
, tmp
);
1230 t64
= tcg_const_i64(read_im64(env
, s
));
1231 gen_helper_extf64(cpu_env
, fp
, t64
);
1232 tcg_temp_free_i64(t64
);
1235 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1236 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1239 tmp
= tcg_const_i32(read_im32(env
, s
) >> 16);
1240 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1242 t64
= tcg_const_i64(read_im64(env
, s
));
1243 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1244 tcg_temp_free_i64(t64
);
1248 * unimplemented data type on 68040/ColdFire
1249 * FIXME if needed for another FPU
1251 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1254 g_assert_not_reached();
1264 static int gen_ea_fp(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
1265 int opsize
, TCGv_ptr fp
, ea_what what
, int index
)
1267 int mode
= extract32(insn
, 3, 3);
1268 int reg0
= REG(insn
, 0);
1269 return gen_ea_mode_fp(env
, s
, mode
, reg0
, opsize
, fp
, what
, index
);
1280 static void gen_cc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
1286 /* The CC_OP_CMP form can handle most normal comparisons directly. */
1287 if (op
== CC_OP_CMPB
|| op
== CC_OP_CMPW
|| op
== CC_OP_CMPL
) {
1294 tcond
= TCG_COND_LEU
;
1298 tcond
= TCG_COND_LTU
;
1302 tcond
= TCG_COND_EQ
;
1307 c
->v2
= tcg_const_i32(0);
1308 c
->v1
= tmp
= tcg_temp_new();
1309 tcg_gen_sub_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1310 gen_ext(tmp
, tmp
, op
- CC_OP_CMPB
, 1);
1314 tcond
= TCG_COND_LT
;
1318 tcond
= TCG_COND_LE
;
1325 c
->v2
= tcg_const_i32(0);
1331 tcond
= TCG_COND_NEVER
;
1333 case 14: /* GT (!(Z || (N ^ V))) */
1334 case 15: /* LE (Z || (N ^ V)) */
1336 * Logic operations clear V, which simplifies LE to (Z || N),
1337 * and since Z and N are co-located, this becomes a normal
1340 if (op
== CC_OP_LOGIC
) {
1342 tcond
= TCG_COND_LE
;
1346 case 12: /* GE (!(N ^ V)) */
1347 case 13: /* LT (N ^ V) */
1348 /* Logic operations clear V, which simplifies this to N. */
1349 if (op
!= CC_OP_LOGIC
) {
1353 case 10: /* PL (!N) */
1354 case 11: /* MI (N) */
1355 /* Several cases represent N normally. */
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
) {
1360 tcond
= TCG_COND_LT
;
1364 case 6: /* NE (!Z) */
1365 case 7: /* EQ (Z) */
1366 /* Some cases fold Z into N. */
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 op
== CC_OP_LOGIC
) {
1370 tcond
= TCG_COND_EQ
;
1375 case 4: /* CC (!C) */
1376 case 5: /* CS (C) */
1377 /* Some cases fold C into X. */
1378 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1379 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
) {
1380 tcond
= TCG_COND_NE
;
1385 case 8: /* VC (!V) */
1386 case 9: /* VS (V) */
1387 /* Logic operations clear V and C. */
1388 if (op
== CC_OP_LOGIC
) {
1389 tcond
= TCG_COND_NEVER
;
1396 /* Otherwise, flush flag state to CC_OP_FLAGS. */
1403 /* Invalid, or handled above. */
1405 case 2: /* HI (!C && !Z) -> !(C || Z)*/
1406 case 3: /* LS (C || Z) */
1407 c
->v1
= tmp
= tcg_temp_new();
1409 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1410 tcg_gen_or_i32(tmp
, tmp
, QREG_CC_C
);
1411 tcond
= TCG_COND_NE
;
1413 case 4: /* CC (!C) */
1414 case 5: /* CS (C) */
1416 tcond
= TCG_COND_NE
;
1418 case 6: /* NE (!Z) */
1419 case 7: /* EQ (Z) */
1421 tcond
= TCG_COND_EQ
;
1423 case 8: /* VC (!V) */
1424 case 9: /* VS (V) */
1426 tcond
= TCG_COND_LT
;
1428 case 10: /* PL (!N) */
1429 case 11: /* MI (N) */
1431 tcond
= TCG_COND_LT
;
1433 case 12: /* GE (!(N ^ V)) */
1434 case 13: /* LT (N ^ V) */
1435 c
->v1
= tmp
= tcg_temp_new();
1437 tcg_gen_xor_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1438 tcond
= TCG_COND_LT
;
1440 case 14: /* GT (!(Z || (N ^ V))) */
1441 case 15: /* LE (Z || (N ^ V)) */
1442 c
->v1
= tmp
= tcg_temp_new();
1444 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1445 tcg_gen_neg_i32(tmp
, tmp
);
1446 tmp2
= tcg_temp_new();
1447 tcg_gen_xor_i32(tmp2
, QREG_CC_N
, QREG_CC_V
);
1448 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1449 tcg_temp_free(tmp2
);
1450 tcond
= TCG_COND_LT
;
1455 if ((cond
& 1) == 0) {
1456 tcond
= tcg_invert_cond(tcond
);
1461 static void free_cond(DisasCompare
*c
)
1464 tcg_temp_free(c
->v1
);
1467 tcg_temp_free(c
->v2
);
1471 static void gen_jmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
1475 gen_cc_cond(&c
, s
, cond
);
1477 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
1481 /* Force a TB lookup after an instruction that changes the CPU state. */
1482 static void gen_exit_tb(DisasContext
*s
)
1485 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
1486 s
->base
.is_jmp
= DISAS_EXIT
;
1489 #define SRC_EA(env, result, opsize, op_sign, addrp) do { \
1490 result = gen_ea(env, s, insn, opsize, NULL_QREG, addrp, \
1491 op_sign ? EA_LOADS : EA_LOADU, IS_USER(s)); \
1492 if (IS_NULL_QREG(result)) { \
1493 gen_addr_fault(s); \
1498 #define DEST_EA(env, insn, opsize, val, addrp) do { \
1499 TCGv ea_result = gen_ea(env, s, insn, opsize, val, addrp, \
1500 EA_STORE, IS_USER(s)); \
1501 if (IS_NULL_QREG(ea_result)) { \
1502 gen_addr_fault(s); \
1507 static inline bool use_goto_tb(DisasContext
*s
, uint32_t dest
)
1509 #ifndef CONFIG_USER_ONLY
1510 return (s
->base
.pc_first
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)
1511 || (s
->base
.pc_next
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
1517 /* Generate a jump to an immediate address. */
1518 static void gen_jmp_tb(DisasContext
*s
, int n
, uint32_t dest
)
1520 if (unlikely(is_singlestepping(s
))) {
1521 gen_exception(s
, dest
, EXCP_DEBUG
);
1522 } else if (use_goto_tb(s
, dest
)) {
1524 tcg_gen_movi_i32(QREG_PC
, dest
);
1525 tcg_gen_exit_tb(s
->base
.tb
, n
);
1527 gen_jmp_im(s
, dest
);
1528 tcg_gen_exit_tb(NULL
, 0);
1530 s
->base
.is_jmp
= DISAS_NORETURN
;
1539 cond
= (insn
>> 8) & 0xf;
1540 gen_cc_cond(&c
, s
, cond
);
1542 tmp
= tcg_temp_new();
1543 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
1546 tcg_gen_neg_i32(tmp
, tmp
);
1547 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
1559 reg
= DREG(insn
, 0);
1561 offset
= (int16_t)read_im16(env
, s
);
1562 l1
= gen_new_label();
1563 gen_jmpcc(s
, (insn
>> 8) & 0xf, l1
);
1565 tmp
= tcg_temp_new();
1566 tcg_gen_ext16s_i32(tmp
, reg
);
1567 tcg_gen_addi_i32(tmp
, tmp
, -1);
1568 gen_partset_reg(OS_WORD
, reg
, tmp
);
1569 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, -1, l1
);
1570 gen_jmp_tb(s
, 1, base
+ offset
);
1572 gen_jmp_tb(s
, 0, s
->pc
);
1575 DISAS_INSN(undef_mac
)
1577 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEA
);
1580 DISAS_INSN(undef_fpu
)
1582 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEF
);
1588 * ??? This is both instructions that are as yet unimplemented
1589 * for the 680x0 series, as well as those that are implemented
1590 * but actually illegal for CPU32 or pre-68020.
1592 qemu_log_mask(LOG_UNIMP
, "Illegal instruction: %04x @ %08x\n",
1593 insn
, s
->base
.pc_next
);
1594 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1604 sign
= (insn
& 0x100) != 0;
1605 reg
= DREG(insn
, 9);
1606 tmp
= tcg_temp_new();
1608 tcg_gen_ext16s_i32(tmp
, reg
);
1610 tcg_gen_ext16u_i32(tmp
, reg
);
1611 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1612 tcg_gen_mul_i32(tmp
, tmp
, src
);
1613 tcg_gen_mov_i32(reg
, tmp
);
1614 gen_logic_cc(s
, tmp
, OS_LONG
);
1624 /* divX.w <EA>,Dn 32/16 -> 16r:16q */
1626 sign
= (insn
& 0x100) != 0;
1628 /* dest.l / src.w */
1630 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1631 destr
= tcg_const_i32(REG(insn
, 9));
1633 gen_helper_divsw(cpu_env
, destr
, src
);
1635 gen_helper_divuw(cpu_env
, destr
, src
);
1637 tcg_temp_free(destr
);
1639 set_cc_op(s
, CC_OP_FLAGS
);
1648 ext
= read_im16(env
, s
);
1650 sign
= (ext
& 0x0800) != 0;
1653 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
1654 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1658 /* divX.l <EA>, Dr:Dq 64/32 -> 32r:32q */
1660 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1661 num
= tcg_const_i32(REG(ext
, 12));
1662 reg
= tcg_const_i32(REG(ext
, 0));
1664 gen_helper_divsll(cpu_env
, num
, reg
, den
);
1666 gen_helper_divull(cpu_env
, num
, reg
, den
);
1670 set_cc_op(s
, CC_OP_FLAGS
);
1674 /* divX.l <EA>, Dq 32/32 -> 32q */
1675 /* divXl.l <EA>, Dr:Dq 32/32 -> 32r:32q */
1677 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1678 num
= tcg_const_i32(REG(ext
, 12));
1679 reg
= tcg_const_i32(REG(ext
, 0));
1681 gen_helper_divsl(cpu_env
, num
, reg
, den
);
1683 gen_helper_divul(cpu_env
, num
, reg
, den
);
1688 set_cc_op(s
, CC_OP_FLAGS
);
1691 static void bcd_add(TCGv dest
, TCGv src
)
1696 * dest10 = dest10 + src10 + X
1700 * t3 = t2 + dest + X
1704 * t7 = (t6 >> 2) | (t6 >> 3)
1709 * t1 = (src + 0x066) + dest + X
1710 * = result with some possible exceeding 0x6
1713 t0
= tcg_const_i32(0x066);
1714 tcg_gen_add_i32(t0
, t0
, src
);
1716 t1
= tcg_temp_new();
1717 tcg_gen_add_i32(t1
, t0
, dest
);
1718 tcg_gen_add_i32(t1
, t1
, QREG_CC_X
);
1720 /* we will remove exceeding 0x6 where there is no carry */
1723 * t0 = (src + 0x0066) ^ dest
1724 * = t1 without carries
1727 tcg_gen_xor_i32(t0
, t0
, dest
);
1730 * extract the carries
1732 * = only the carries
1735 tcg_gen_xor_i32(t0
, t0
, t1
);
1738 * generate 0x1 where there is no carry
1739 * and for each 0x10, generate a 0x6
1742 tcg_gen_shri_i32(t0
, t0
, 3);
1743 tcg_gen_not_i32(t0
, t0
);
1744 tcg_gen_andi_i32(t0
, t0
, 0x22);
1745 tcg_gen_add_i32(dest
, t0
, t0
);
1746 tcg_gen_add_i32(dest
, dest
, t0
);
1750 * remove the exceeding 0x6
1751 * for digits that have not generated a carry
1754 tcg_gen_sub_i32(dest
, t1
, dest
);
1758 static void bcd_sub(TCGv dest
, TCGv src
)
1763 * dest10 = dest10 - src10 - X
1764 * = bcd_add(dest + 1 - X, 0x199 - src)
1767 /* t0 = 0x066 + (0x199 - src) */
1769 t0
= tcg_temp_new();
1770 tcg_gen_subfi_i32(t0
, 0x1ff, src
);
1772 /* t1 = t0 + dest + 1 - X*/
1774 t1
= tcg_temp_new();
1775 tcg_gen_add_i32(t1
, t0
, dest
);
1776 tcg_gen_addi_i32(t1
, t1
, 1);
1777 tcg_gen_sub_i32(t1
, t1
, QREG_CC_X
);
1779 /* t2 = t0 ^ dest */
1781 t2
= tcg_temp_new();
1782 tcg_gen_xor_i32(t2
, t0
, dest
);
1786 tcg_gen_xor_i32(t0
, t1
, t2
);
1790 * t0 = (t2 >> 2) | (t2 >> 3)
1792 * to fit on 8bit operands, changed in:
1794 * t2 = ~(t0 >> 3) & 0x22
1799 tcg_gen_shri_i32(t2
, t0
, 3);
1800 tcg_gen_not_i32(t2
, t2
);
1801 tcg_gen_andi_i32(t2
, t2
, 0x22);
1802 tcg_gen_add_i32(t0
, t2
, t2
);
1803 tcg_gen_add_i32(t0
, t0
, t2
);
1806 /* return t1 - t0 */
1808 tcg_gen_sub_i32(dest
, t1
, t0
);
1813 static void bcd_flags(TCGv val
)
1815 tcg_gen_andi_i32(QREG_CC_C
, val
, 0x0ff);
1816 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_C
);
1818 tcg_gen_extract_i32(QREG_CC_C
, val
, 8, 1);
1820 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
1823 DISAS_INSN(abcd_reg
)
1828 gen_flush_flags(s
); /* !Z is sticky */
1830 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1831 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1833 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1838 DISAS_INSN(abcd_mem
)
1840 TCGv src
, dest
, addr
;
1842 gen_flush_flags(s
); /* !Z is sticky */
1844 /* Indirect pre-decrement load (mode 4) */
1846 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1847 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1848 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1849 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1853 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1854 EA_STORE
, IS_USER(s
));
1859 DISAS_INSN(sbcd_reg
)
1863 gen_flush_flags(s
); /* !Z is sticky */
1865 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1866 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1870 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1875 DISAS_INSN(sbcd_mem
)
1877 TCGv src
, dest
, addr
;
1879 gen_flush_flags(s
); /* !Z is sticky */
1881 /* Indirect pre-decrement load (mode 4) */
1883 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1884 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1885 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1886 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1890 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1891 EA_STORE
, IS_USER(s
));
1901 gen_flush_flags(s
); /* !Z is sticky */
1903 SRC_EA(env
, src
, OS_BYTE
, 0, &addr
);
1905 dest
= tcg_const_i32(0);
1908 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
1912 tcg_temp_free(dest
);
1925 add
= (insn
& 0x4000) != 0;
1926 opsize
= insn_opsize(insn
);
1927 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
1928 dest
= tcg_temp_new();
1930 SRC_EA(env
, tmp
, opsize
, 1, &addr
);
1934 SRC_EA(env
, src
, opsize
, 1, NULL
);
1937 tcg_gen_add_i32(dest
, tmp
, src
);
1938 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, src
);
1939 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
1941 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, tmp
, src
);
1942 tcg_gen_sub_i32(dest
, tmp
, src
);
1943 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
1945 gen_update_cc_add(dest
, src
, opsize
);
1947 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1949 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
1951 tcg_temp_free(dest
);
1954 /* Reverse the order of the bits in REG. */
1958 reg
= DREG(insn
, 0);
1959 gen_helper_bitrev(reg
, reg
);
1962 DISAS_INSN(bitop_reg
)
1972 if ((insn
& 0x38) != 0)
1976 op
= (insn
>> 6) & 3;
1977 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
1980 src2
= tcg_temp_new();
1981 if (opsize
== OS_BYTE
)
1982 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 7);
1984 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 31);
1986 tmp
= tcg_const_i32(1);
1987 tcg_gen_shl_i32(tmp
, tmp
, src2
);
1988 tcg_temp_free(src2
);
1990 tcg_gen_and_i32(QREG_CC_Z
, src1
, tmp
);
1992 dest
= tcg_temp_new();
1995 tcg_gen_xor_i32(dest
, src1
, tmp
);
1998 tcg_gen_andc_i32(dest
, src1
, tmp
);
2001 tcg_gen_or_i32(dest
, src1
, tmp
);
2008 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2010 tcg_temp_free(dest
);
2016 reg
= DREG(insn
, 0);
2018 gen_helper_sats(reg
, reg
, QREG_CC_V
);
2019 gen_logic_cc(s
, reg
, OS_LONG
);
2022 static void gen_push(DisasContext
*s
, TCGv val
)
2026 tmp
= tcg_temp_new();
2027 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
2028 gen_store(s
, OS_LONG
, tmp
, val
, IS_USER(s
));
2029 tcg_gen_mov_i32(QREG_SP
, tmp
);
2033 static TCGv
mreg(int reg
)
2037 return cpu_dregs
[reg
];
2040 return cpu_aregs
[reg
& 7];
2045 TCGv addr
, incr
, tmp
, r
[16];
2046 int is_load
= (insn
& 0x0400) != 0;
2047 int opsize
= (insn
& 0x40) != 0 ? OS_LONG
: OS_WORD
;
2048 uint16_t mask
= read_im16(env
, s
);
2049 int mode
= extract32(insn
, 3, 3);
2050 int reg0
= REG(insn
, 0);
2053 tmp
= cpu_aregs
[reg0
];
2056 case 0: /* data register direct */
2057 case 1: /* addr register direct */
2062 case 2: /* indirect */
2065 case 3: /* indirect post-increment */
2067 /* post-increment is not allowed */
2072 case 4: /* indirect pre-decrement */
2074 /* pre-decrement is not allowed */
2078 * We want a bare copy of the address reg, without any pre-decrement
2079 * adjustment, as gen_lea would provide.
2084 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
2085 if (IS_NULL_QREG(tmp
)) {
2091 addr
= tcg_temp_new();
2092 tcg_gen_mov_i32(addr
, tmp
);
2093 incr
= tcg_const_i32(opsize_bytes(opsize
));
2096 /* memory to register */
2097 for (i
= 0; i
< 16; i
++) {
2098 if (mask
& (1 << i
)) {
2099 r
[i
] = gen_load(s
, opsize
, addr
, 1, IS_USER(s
));
2100 tcg_gen_add_i32(addr
, addr
, incr
);
2103 for (i
= 0; i
< 16; i
++) {
2104 if (mask
& (1 << i
)) {
2105 tcg_gen_mov_i32(mreg(i
), r
[i
]);
2106 tcg_temp_free(r
[i
]);
2110 /* post-increment: movem (An)+,X */
2111 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2114 /* register to memory */
2116 /* pre-decrement: movem X,-(An) */
2117 for (i
= 15; i
>= 0; i
--) {
2118 if ((mask
<< i
) & 0x8000) {
2119 tcg_gen_sub_i32(addr
, addr
, incr
);
2120 if (reg0
+ 8 == i
&&
2121 m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
)) {
2123 * M68020+: if the addressing register is the
2124 * register moved to memory, the value written
2125 * is the initial value decremented by the size of
2126 * the operation, regardless of how many actual
2127 * stores have been performed until this point.
2128 * M68000/M68010: the value is the initial value.
2130 tmp
= tcg_temp_new();
2131 tcg_gen_sub_i32(tmp
, cpu_aregs
[reg0
], incr
);
2132 gen_store(s
, opsize
, addr
, tmp
, IS_USER(s
));
2135 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2139 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2141 for (i
= 0; i
< 16; i
++) {
2142 if (mask
& (1 << i
)) {
2143 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2144 tcg_gen_add_i32(addr
, addr
, incr
);
2150 tcg_temp_free(incr
);
2151 tcg_temp_free(addr
);
2163 displ
= read_im16(env
, s
);
2165 addr
= AREG(insn
, 0);
2166 reg
= DREG(insn
, 9);
2168 abuf
= tcg_temp_new();
2169 tcg_gen_addi_i32(abuf
, addr
, displ
);
2170 dbuf
= tcg_temp_new();
2179 for ( ; i
> 0 ; i
--) {
2180 tcg_gen_shri_i32(dbuf
, reg
, (i
- 1) * 8);
2181 tcg_gen_qemu_st8(dbuf
, abuf
, IS_USER(s
));
2183 tcg_gen_addi_i32(abuf
, abuf
, 2);
2187 for ( ; i
> 0 ; i
--) {
2188 tcg_gen_qemu_ld8u(dbuf
, abuf
, IS_USER(s
));
2189 tcg_gen_deposit_i32(reg
, reg
, dbuf
, (i
- 1) * 8, 8);
2191 tcg_gen_addi_i32(abuf
, abuf
, 2);
2195 tcg_temp_free(abuf
);
2196 tcg_temp_free(dbuf
);
2199 DISAS_INSN(bitop_im
)
2209 if ((insn
& 0x38) != 0)
2213 op
= (insn
>> 6) & 3;
2215 bitnum
= read_im16(env
, s
);
2216 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
2217 if (bitnum
& 0xfe00) {
2218 disas_undef(env
, s
, insn
);
2222 if (bitnum
& 0xff00) {
2223 disas_undef(env
, s
, insn
);
2228 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
2231 if (opsize
== OS_BYTE
)
2237 tcg_gen_andi_i32(QREG_CC_Z
, src1
, mask
);
2240 tmp
= tcg_temp_new();
2243 tcg_gen_xori_i32(tmp
, src1
, mask
);
2246 tcg_gen_andi_i32(tmp
, src1
, ~mask
);
2249 tcg_gen_ori_i32(tmp
, src1
, mask
);
2254 DEST_EA(env
, insn
, opsize
, tmp
, &addr
);
2259 static TCGv
gen_get_ccr(DisasContext
*s
)
2264 dest
= tcg_temp_new();
2265 gen_helper_get_ccr(dest
, cpu_env
);
2269 static TCGv
gen_get_sr(DisasContext
*s
)
2274 ccr
= gen_get_ccr(s
);
2275 sr
= tcg_temp_new();
2276 tcg_gen_andi_i32(sr
, QREG_SR
, 0xffe0);
2277 tcg_gen_or_i32(sr
, sr
, ccr
);
2282 static void gen_set_sr_im(DisasContext
*s
, uint16_t val
, int ccr_only
)
2285 tcg_gen_movi_i32(QREG_CC_C
, val
& CCF_C
? 1 : 0);
2286 tcg_gen_movi_i32(QREG_CC_V
, val
& CCF_V
? -1 : 0);
2287 tcg_gen_movi_i32(QREG_CC_Z
, val
& CCF_Z
? 0 : 1);
2288 tcg_gen_movi_i32(QREG_CC_N
, val
& CCF_N
? -1 : 0);
2289 tcg_gen_movi_i32(QREG_CC_X
, val
& CCF_X
? 1 : 0);
2291 TCGv sr
= tcg_const_i32(val
);
2292 gen_helper_set_sr(cpu_env
, sr
);
2295 set_cc_op(s
, CC_OP_FLAGS
);
2298 static void gen_set_sr(DisasContext
*s
, TCGv val
, int ccr_only
)
2301 gen_helper_set_ccr(cpu_env
, val
);
2303 gen_helper_set_sr(cpu_env
, val
);
2305 set_cc_op(s
, CC_OP_FLAGS
);
2308 static void gen_move_to_sr(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
2311 if ((insn
& 0x3f) == 0x3c) {
2313 val
= read_im16(env
, s
);
2314 gen_set_sr_im(s
, val
, ccr_only
);
2317 SRC_EA(env
, src
, OS_WORD
, 0, NULL
);
2318 gen_set_sr(s
, src
, ccr_only
);
2322 DISAS_INSN(arith_im
)
2330 bool with_SR
= ((insn
& 0x3f) == 0x3c);
2332 op
= (insn
>> 9) & 7;
2333 opsize
= insn_opsize(insn
);
2336 im
= tcg_const_i32((int8_t)read_im8(env
, s
));
2339 im
= tcg_const_i32((int16_t)read_im16(env
, s
));
2342 im
= tcg_const_i32(read_im32(env
, s
));
2345 g_assert_not_reached();
2349 /* SR/CCR can only be used with andi/eori/ori */
2350 if (op
== 2 || op
== 3 || op
== 6) {
2351 disas_undef(env
, s
, insn
);
2356 src1
= gen_get_ccr(s
);
2360 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2363 src1
= gen_get_sr(s
);
2366 /* OS_LONG; others already g_assert_not_reached. */
2367 disas_undef(env
, s
, insn
);
2371 SRC_EA(env
, src1
, opsize
, 1, (op
== 6) ? NULL
: &addr
);
2373 dest
= tcg_temp_new();
2376 tcg_gen_or_i32(dest
, src1
, im
);
2378 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2380 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2381 gen_logic_cc(s
, dest
, opsize
);
2385 tcg_gen_and_i32(dest
, src1
, im
);
2387 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2389 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2390 gen_logic_cc(s
, dest
, opsize
);
2394 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, src1
, im
);
2395 tcg_gen_sub_i32(dest
, src1
, im
);
2396 gen_update_cc_add(dest
, im
, opsize
);
2397 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2398 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2401 tcg_gen_add_i32(dest
, src1
, im
);
2402 gen_update_cc_add(dest
, im
, opsize
);
2403 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, im
);
2404 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2405 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2408 tcg_gen_xor_i32(dest
, src1
, im
);
2410 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2412 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2413 gen_logic_cc(s
, dest
, opsize
);
2417 gen_update_cc_cmp(s
, src1
, im
, opsize
);
2423 tcg_temp_free(dest
);
2435 switch ((insn
>> 9) & 3) {
2449 g_assert_not_reached();
2452 ext
= read_im16(env
, s
);
2454 /* cas Dc,Du,<EA> */
2456 addr
= gen_lea(env
, s
, insn
, opsize
);
2457 if (IS_NULL_QREG(addr
)) {
2462 cmp
= gen_extend(s
, DREG(ext
, 0), opsize
, 1);
2465 * if <EA> == Dc then
2467 * Dc = <EA> (because <EA> == Dc)
2472 load
= tcg_temp_new();
2473 tcg_gen_atomic_cmpxchg_i32(load
, addr
, cmp
, DREG(ext
, 6),
2475 /* update flags before setting cmp to load */
2476 gen_update_cc_cmp(s
, load
, cmp
, opsize
);
2477 gen_partset_reg(opsize
, DREG(ext
, 0), load
);
2479 tcg_temp_free(load
);
2481 switch (extract32(insn
, 3, 3)) {
2482 case 3: /* Indirect postincrement. */
2483 tcg_gen_addi_i32(AREG(insn
, 0), addr
, opsize_bytes(opsize
));
2485 case 4: /* Indirect predecrememnt. */
2486 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2493 uint16_t ext1
, ext2
;
2497 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2499 ext1
= read_im16(env
, s
);
2501 if (ext1
& 0x8000) {
2502 /* Address Register */
2503 addr1
= AREG(ext1
, 12);
2506 addr1
= DREG(ext1
, 12);
2509 ext2
= read_im16(env
, s
);
2510 if (ext2
& 0x8000) {
2511 /* Address Register */
2512 addr2
= AREG(ext2
, 12);
2515 addr2
= DREG(ext2
, 12);
2519 * if (R1) == Dc1 && (R2) == Dc2 then
2527 regs
= tcg_const_i32(REG(ext2
, 6) |
2528 (REG(ext1
, 6) << 3) |
2529 (REG(ext2
, 0) << 6) |
2530 (REG(ext1
, 0) << 9));
2531 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2532 gen_helper_exit_atomic(cpu_env
);
2534 gen_helper_cas2w(cpu_env
, regs
, addr1
, addr2
);
2536 tcg_temp_free(regs
);
2538 /* Note that cas2w also assigned to env->cc_op. */
2539 s
->cc_op
= CC_OP_CMPW
;
2540 s
->cc_op_synced
= 1;
2545 uint16_t ext1
, ext2
;
2546 TCGv addr1
, addr2
, regs
;
2548 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2550 ext1
= read_im16(env
, s
);
2552 if (ext1
& 0x8000) {
2553 /* Address Register */
2554 addr1
= AREG(ext1
, 12);
2557 addr1
= DREG(ext1
, 12);
2560 ext2
= read_im16(env
, s
);
2561 if (ext2
& 0x8000) {
2562 /* Address Register */
2563 addr2
= AREG(ext2
, 12);
2566 addr2
= DREG(ext2
, 12);
2570 * if (R1) == Dc1 && (R2) == Dc2 then
2578 regs
= tcg_const_i32(REG(ext2
, 6) |
2579 (REG(ext1
, 6) << 3) |
2580 (REG(ext2
, 0) << 6) |
2581 (REG(ext1
, 0) << 9));
2582 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2583 gen_helper_cas2l_parallel(cpu_env
, regs
, addr1
, addr2
);
2585 gen_helper_cas2l(cpu_env
, regs
, addr1
, addr2
);
2587 tcg_temp_free(regs
);
2589 /* Note that cas2l also assigned to env->cc_op. */
2590 s
->cc_op
= CC_OP_CMPL
;
2591 s
->cc_op_synced
= 1;
2598 reg
= DREG(insn
, 0);
2599 tcg_gen_bswap32_i32(reg
, reg
);
2609 switch (insn
>> 12) {
2610 case 1: /* move.b */
2613 case 2: /* move.l */
2616 case 3: /* move.w */
2622 SRC_EA(env
, src
, opsize
, 1, NULL
);
2623 op
= (insn
>> 6) & 7;
2626 /* The value will already have been sign extended. */
2627 dest
= AREG(insn
, 9);
2628 tcg_gen_mov_i32(dest
, src
);
2632 dest_ea
= ((insn
>> 9) & 7) | (op
<< 3);
2633 DEST_EA(env
, dest_ea
, opsize
, src
, NULL
);
2634 /* This will be correct because loads sign extend. */
2635 gen_logic_cc(s
, src
, opsize
);
2646 opsize
= insn_opsize(insn
);
2647 SRC_EA(env
, src
, opsize
, 1, &addr
);
2649 gen_flush_flags(s
); /* compute old Z */
2652 * Perform subtract with borrow.
2653 * (X, N) = -(src + X);
2656 z
= tcg_const_i32(0);
2657 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, z
, QREG_CC_X
, z
);
2658 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, z
, z
, QREG_CC_N
, QREG_CC_X
);
2660 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
2662 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
2665 * Compute signed-overflow for negation. The normal formula for
2666 * subtraction is (res ^ src) & (src ^ dest), but with dest==0
2667 * this simplifies to res & src.
2670 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_N
, src
);
2672 /* Copy the rest of the results into place. */
2673 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
2674 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
2676 set_cc_op(s
, CC_OP_FLAGS
);
2678 /* result is in QREG_CC_N */
2680 DEST_EA(env
, insn
, opsize
, QREG_CC_N
, &addr
);
2688 reg
= AREG(insn
, 9);
2689 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2690 if (IS_NULL_QREG(tmp
)) {
2694 tcg_gen_mov_i32(reg
, tmp
);
2702 zero
= tcg_const_i32(0);
2704 opsize
= insn_opsize(insn
);
2705 DEST_EA(env
, insn
, opsize
, zero
, NULL
);
2706 gen_logic_cc(s
, zero
, opsize
);
2707 tcg_temp_free(zero
);
2710 DISAS_INSN(move_from_ccr
)
2714 ccr
= gen_get_ccr(s
);
2715 DEST_EA(env
, insn
, OS_WORD
, ccr
, NULL
);
2725 opsize
= insn_opsize(insn
);
2726 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2727 dest
= tcg_temp_new();
2728 tcg_gen_neg_i32(dest
, src1
);
2729 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2730 gen_update_cc_add(dest
, src1
, opsize
);
2731 tcg_gen_setcondi_i32(TCG_COND_NE
, QREG_CC_X
, dest
, 0);
2732 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2733 tcg_temp_free(dest
);
2736 DISAS_INSN(move_to_ccr
)
2738 gen_move_to_sr(env
, s
, insn
, true);
2748 opsize
= insn_opsize(insn
);
2749 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2750 dest
= tcg_temp_new();
2751 tcg_gen_not_i32(dest
, src1
);
2752 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2753 gen_logic_cc(s
, dest
, opsize
);
2762 src1
= tcg_temp_new();
2763 src2
= tcg_temp_new();
2764 reg
= DREG(insn
, 0);
2765 tcg_gen_shli_i32(src1
, reg
, 16);
2766 tcg_gen_shri_i32(src2
, reg
, 16);
2767 tcg_gen_or_i32(reg
, src1
, src2
);
2768 tcg_temp_free(src2
);
2769 tcg_temp_free(src1
);
2770 gen_logic_cc(s
, reg
, OS_LONG
);
2775 gen_exception(s
, s
->base
.pc_next
, EXCP_DEBUG
);
2782 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2783 if (IS_NULL_QREG(tmp
)) {
2796 reg
= DREG(insn
, 0);
2797 op
= (insn
>> 6) & 7;
2798 tmp
= tcg_temp_new();
2800 tcg_gen_ext16s_i32(tmp
, reg
);
2802 tcg_gen_ext8s_i32(tmp
, reg
);
2804 gen_partset_reg(OS_WORD
, reg
, tmp
);
2806 tcg_gen_mov_i32(reg
, tmp
);
2807 gen_logic_cc(s
, tmp
, OS_LONG
);
2816 opsize
= insn_opsize(insn
);
2817 SRC_EA(env
, tmp
, opsize
, 1, NULL
);
2818 gen_logic_cc(s
, tmp
, opsize
);
2823 /* Implemented as a NOP. */
2828 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2831 /* ??? This should be atomic. */
2838 dest
= tcg_temp_new();
2839 SRC_EA(env
, src1
, OS_BYTE
, 1, &addr
);
2840 gen_logic_cc(s
, src1
, OS_BYTE
);
2841 tcg_gen_ori_i32(dest
, src1
, 0x80);
2842 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
2843 tcg_temp_free(dest
);
2852 ext
= read_im16(env
, s
);
2857 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
2858 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2862 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2865 tcg_gen_muls2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2867 tcg_gen_mulu2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2869 /* if Dl == Dh, 68040 returns low word */
2870 tcg_gen_mov_i32(DREG(ext
, 0), QREG_CC_N
);
2871 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_Z
);
2872 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
);
2874 tcg_gen_movi_i32(QREG_CC_V
, 0);
2875 tcg_gen_movi_i32(QREG_CC_C
, 0);
2877 set_cc_op(s
, CC_OP_FLAGS
);
2880 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2881 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
2882 tcg_gen_movi_i32(QREG_CC_C
, 0);
2884 tcg_gen_muls2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2885 /* QREG_CC_V is -(QREG_CC_V != (QREG_CC_N >> 31)) */
2886 tcg_gen_sari_i32(QREG_CC_Z
, QREG_CC_N
, 31);
2887 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_Z
);
2889 tcg_gen_mulu2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2890 /* QREG_CC_V is -(QREG_CC_V != 0), use QREG_CC_C as 0 */
2891 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_C
);
2893 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
2894 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_N
);
2896 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
2898 set_cc_op(s
, CC_OP_FLAGS
);
2901 * The upper 32 bits of the product are discarded, so
2902 * muls.l and mulu.l are functionally equivalent.
2904 tcg_gen_mul_i32(DREG(ext
, 12), src1
, DREG(ext
, 12));
2905 gen_logic_cc(s
, DREG(ext
, 12), OS_LONG
);
2909 static void gen_link(DisasContext
*s
, uint16_t insn
, int32_t offset
)
2914 reg
= AREG(insn
, 0);
2915 tmp
= tcg_temp_new();
2916 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
2917 gen_store(s
, OS_LONG
, tmp
, reg
, IS_USER(s
));
2918 if ((insn
& 7) != 7) {
2919 tcg_gen_mov_i32(reg
, tmp
);
2921 tcg_gen_addi_i32(QREG_SP
, tmp
, offset
);
2929 offset
= read_im16(env
, s
);
2930 gen_link(s
, insn
, offset
);
2937 offset
= read_im32(env
, s
);
2938 gen_link(s
, insn
, offset
);
2947 src
= tcg_temp_new();
2948 reg
= AREG(insn
, 0);
2949 tcg_gen_mov_i32(src
, reg
);
2950 tmp
= gen_load(s
, OS_LONG
, src
, 0, IS_USER(s
));
2951 tcg_gen_mov_i32(reg
, tmp
);
2952 tcg_gen_addi_i32(QREG_SP
, src
, 4);
2957 #if defined(CONFIG_SOFTMMU)
2961 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2965 gen_helper_reset(cpu_env
);
2976 int16_t offset
= read_im16(env
, s
);
2978 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
2979 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, offset
+ 4);
2989 sp
= tcg_temp_new();
2990 ccr
= gen_load(s
, OS_WORD
, QREG_SP
, 0, IS_USER(s
));
2991 tcg_gen_addi_i32(sp
, QREG_SP
, 2);
2992 tmp
= gen_load(s
, OS_LONG
, sp
, 0, IS_USER(s
));
2993 tcg_gen_addi_i32(QREG_SP
, sp
, 4);
2996 gen_set_sr(s
, ccr
, true);
3006 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
3007 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, 4);
3016 * Load the target address first to ensure correct exception
3019 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
3020 if (IS_NULL_QREG(tmp
)) {
3024 if ((insn
& 0x40) == 0) {
3026 gen_push(s
, tcg_const_i32(s
->pc
));
3040 if ((insn
& 070) == 010) {
3041 /* Operation on address register is always long. */
3044 opsize
= insn_opsize(insn
);
3046 SRC_EA(env
, src
, opsize
, 1, &addr
);
3047 imm
= (insn
>> 9) & 7;
3051 val
= tcg_const_i32(imm
);
3052 dest
= tcg_temp_new();
3053 tcg_gen_mov_i32(dest
, src
);
3054 if ((insn
& 0x38) == 0x08) {
3056 * Don't update condition codes if the destination is an
3059 if (insn
& 0x0100) {
3060 tcg_gen_sub_i32(dest
, dest
, val
);
3062 tcg_gen_add_i32(dest
, dest
, val
);
3065 if (insn
& 0x0100) {
3066 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
3067 tcg_gen_sub_i32(dest
, dest
, val
);
3068 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
3070 tcg_gen_add_i32(dest
, dest
, val
);
3071 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
3072 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
3074 gen_update_cc_add(dest
, val
, opsize
);
3077 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3078 tcg_temp_free(dest
);
3084 case 2: /* One extension word. */
3087 case 3: /* Two extension words. */
3090 case 4: /* No extension words. */
3093 disas_undef(env
, s
, insn
);
3104 op
= (insn
>> 8) & 0xf;
3105 offset
= (int8_t)insn
;
3107 offset
= (int16_t)read_im16(env
, s
);
3108 } else if (offset
== -1) {
3109 offset
= read_im32(env
, s
);
3113 gen_push(s
, tcg_const_i32(s
->pc
));
3117 TCGLabel
*l1
= gen_new_label();
3118 gen_jmpcc(s
, ((insn
>> 8) & 0xf) ^ 1, l1
);
3119 gen_jmp_tb(s
, 1, base
+ offset
);
3121 gen_jmp_tb(s
, 0, s
->pc
);
3123 /* Unconditional branch. */
3125 gen_jmp_tb(s
, 0, base
+ offset
);
3131 tcg_gen_movi_i32(DREG(insn
, 9), (int8_t)insn
);
3132 gen_logic_cc(s
, DREG(insn
, 9), OS_LONG
);
3145 SRC_EA(env
, src
, opsize
, (insn
& 0x80) == 0, NULL
);
3146 reg
= DREG(insn
, 9);
3147 tcg_gen_mov_i32(reg
, src
);
3148 gen_logic_cc(s
, src
, opsize
);
3159 opsize
= insn_opsize(insn
);
3160 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 0);
3161 dest
= tcg_temp_new();
3163 SRC_EA(env
, src
, opsize
, 0, &addr
);
3164 tcg_gen_or_i32(dest
, src
, reg
);
3165 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3167 SRC_EA(env
, src
, opsize
, 0, NULL
);
3168 tcg_gen_or_i32(dest
, src
, reg
);
3169 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
3171 gen_logic_cc(s
, dest
, opsize
);
3172 tcg_temp_free(dest
);
3180 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3181 reg
= AREG(insn
, 9);
3182 tcg_gen_sub_i32(reg
, reg
, src
);
3185 static inline void gen_subx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3189 gen_flush_flags(s
); /* compute old Z */
3192 * Perform subtract with borrow.
3193 * (X, N) = dest - (src + X);
3196 tmp
= tcg_const_i32(0);
3197 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, tmp
, QREG_CC_X
, tmp
);
3198 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, dest
, tmp
, QREG_CC_N
, QREG_CC_X
);
3199 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3200 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
3202 /* Compute signed-overflow for subtract. */
3204 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, dest
);
3205 tcg_gen_xor_i32(tmp
, dest
, src
);
3206 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3209 /* Copy the rest of the results into place. */
3210 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3211 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3213 set_cc_op(s
, CC_OP_FLAGS
);
3215 /* result is in QREG_CC_N */
3218 DISAS_INSN(subx_reg
)
3224 opsize
= insn_opsize(insn
);
3226 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3227 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3229 gen_subx(s
, src
, dest
, opsize
);
3231 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3234 DISAS_INSN(subx_mem
)
3242 opsize
= insn_opsize(insn
);
3244 addr_src
= AREG(insn
, 0);
3245 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3246 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3248 addr_dest
= AREG(insn
, 9);
3249 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3250 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3252 gen_subx(s
, src
, dest
, opsize
);
3254 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3256 tcg_temp_free(dest
);
3265 val
= (insn
>> 9) & 7;
3268 src
= tcg_const_i32(val
);
3269 gen_logic_cc(s
, src
, OS_LONG
);
3270 DEST_EA(env
, insn
, OS_LONG
, src
, NULL
);
3280 opsize
= insn_opsize(insn
);
3281 SRC_EA(env
, src
, opsize
, 1, NULL
);
3282 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3283 gen_update_cc_cmp(s
, reg
, src
, opsize
);
3297 SRC_EA(env
, src
, opsize
, 1, NULL
);
3298 reg
= AREG(insn
, 9);
3299 gen_update_cc_cmp(s
, reg
, src
, OS_LONG
);
3304 int opsize
= insn_opsize(insn
);
3307 /* Post-increment load (mode 3) from Ay. */
3308 src
= gen_ea_mode(env
, s
, 3, REG(insn
, 0), opsize
,
3309 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3310 /* Post-increment load (mode 3) from Ax. */
3311 dst
= gen_ea_mode(env
, s
, 3, REG(insn
, 9), opsize
,
3312 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3314 gen_update_cc_cmp(s
, dst
, src
, opsize
);
3324 opsize
= insn_opsize(insn
);
3326 SRC_EA(env
, src
, opsize
, 0, &addr
);
3327 dest
= tcg_temp_new();
3328 tcg_gen_xor_i32(dest
, src
, DREG(insn
, 9));
3329 gen_logic_cc(s
, dest
, opsize
);
3330 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3331 tcg_temp_free(dest
);
3334 static void do_exg(TCGv reg1
, TCGv reg2
)
3336 TCGv temp
= tcg_temp_new();
3337 tcg_gen_mov_i32(temp
, reg1
);
3338 tcg_gen_mov_i32(reg1
, reg2
);
3339 tcg_gen_mov_i32(reg2
, temp
);
3340 tcg_temp_free(temp
);
3345 /* exchange Dx and Dy */
3346 do_exg(DREG(insn
, 9), DREG(insn
, 0));
3351 /* exchange Ax and Ay */
3352 do_exg(AREG(insn
, 9), AREG(insn
, 0));
3357 /* exchange Dx and Ay */
3358 do_exg(DREG(insn
, 9), AREG(insn
, 0));
3369 dest
= tcg_temp_new();
3371 opsize
= insn_opsize(insn
);
3372 reg
= DREG(insn
, 9);
3374 SRC_EA(env
, src
, opsize
, 0, &addr
);
3375 tcg_gen_and_i32(dest
, src
, reg
);
3376 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3378 SRC_EA(env
, src
, opsize
, 0, NULL
);
3379 tcg_gen_and_i32(dest
, src
, reg
);
3380 gen_partset_reg(opsize
, reg
, dest
);
3382 gen_logic_cc(s
, dest
, opsize
);
3383 tcg_temp_free(dest
);
3391 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3392 reg
= AREG(insn
, 9);
3393 tcg_gen_add_i32(reg
, reg
, src
);
3396 static inline void gen_addx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3400 gen_flush_flags(s
); /* compute old Z */
3403 * Perform addition with carry.
3404 * (X, N) = src + dest + X;
3407 tmp
= tcg_const_i32(0);
3408 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_X
, tmp
, dest
, tmp
);
3409 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_N
, QREG_CC_X
, src
, tmp
);
3410 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3412 /* Compute signed-overflow for addition. */
3414 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3415 tcg_gen_xor_i32(tmp
, dest
, src
);
3416 tcg_gen_andc_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3419 /* Copy the rest of the results into place. */
3420 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3421 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3423 set_cc_op(s
, CC_OP_FLAGS
);
3425 /* result is in QREG_CC_N */
3428 DISAS_INSN(addx_reg
)
3434 opsize
= insn_opsize(insn
);
3436 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3437 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3439 gen_addx(s
, src
, dest
, opsize
);
3441 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3444 DISAS_INSN(addx_mem
)
3452 opsize
= insn_opsize(insn
);
3454 addr_src
= AREG(insn
, 0);
3455 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3456 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3458 addr_dest
= AREG(insn
, 9);
3459 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3460 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3462 gen_addx(s
, src
, dest
, opsize
);
3464 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3466 tcg_temp_free(dest
);
3470 static inline void shift_im(DisasContext
*s
, uint16_t insn
, int opsize
)
3472 int count
= (insn
>> 9) & 7;
3473 int logical
= insn
& 8;
3474 int left
= insn
& 0x100;
3475 int bits
= opsize_bytes(opsize
) * 8;
3476 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3482 tcg_gen_movi_i32(QREG_CC_V
, 0);
3484 tcg_gen_shri_i32(QREG_CC_C
, reg
, bits
- count
);
3485 tcg_gen_shli_i32(QREG_CC_N
, reg
, count
);
3488 * Note that ColdFire always clears V (done above),
3489 * while M68000 sets if the most significant bit is changed at
3490 * any time during the shift operation.
3492 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3493 /* if shift count >= bits, V is (reg != 0) */
3494 if (count
>= bits
) {
3495 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, reg
, QREG_CC_V
);
3497 TCGv t0
= tcg_temp_new();
3498 tcg_gen_sari_i32(QREG_CC_V
, reg
, bits
- 1);
3499 tcg_gen_sari_i32(t0
, reg
, bits
- count
- 1);
3500 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, t0
);
3503 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3506 tcg_gen_shri_i32(QREG_CC_C
, reg
, count
- 1);
3508 tcg_gen_shri_i32(QREG_CC_N
, reg
, count
);
3510 tcg_gen_sari_i32(QREG_CC_N
, reg
, count
);
3514 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3515 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3516 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3517 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3519 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3520 set_cc_op(s
, CC_OP_FLAGS
);
3523 static inline void shift_reg(DisasContext
*s
, uint16_t insn
, int opsize
)
3525 int logical
= insn
& 8;
3526 int left
= insn
& 0x100;
3527 int bits
= opsize_bytes(opsize
) * 8;
3528 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3532 t64
= tcg_temp_new_i64();
3533 s64
= tcg_temp_new_i64();
3534 s32
= tcg_temp_new();
3537 * Note that m68k truncates the shift count modulo 64, not 32.
3538 * In addition, a 64-bit shift makes it easy to find "the last
3539 * bit shifted out", for the carry flag.
3541 tcg_gen_andi_i32(s32
, DREG(insn
, 9), 63);
3542 tcg_gen_extu_i32_i64(s64
, s32
);
3543 tcg_gen_extu_i32_i64(t64
, reg
);
3545 /* Optimistically set V=0. Also used as a zero source below. */
3546 tcg_gen_movi_i32(QREG_CC_V
, 0);
3548 tcg_gen_shl_i64(t64
, t64
, s64
);
3550 if (opsize
== OS_LONG
) {
3551 tcg_gen_extr_i64_i32(QREG_CC_N
, QREG_CC_C
, t64
);
3552 /* Note that C=0 if shift count is 0, and we get that for free. */
3554 TCGv zero
= tcg_const_i32(0);
3555 tcg_gen_extrl_i64_i32(QREG_CC_N
, t64
);
3556 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_N
, bits
);
3557 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3558 s32
, zero
, zero
, QREG_CC_C
);
3559 tcg_temp_free(zero
);
3561 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3563 /* X = C, but only if the shift count was non-zero. */
3564 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3565 QREG_CC_C
, QREG_CC_X
);
3568 * M68000 sets V if the most significant bit is changed at
3569 * any time during the shift operation. Do this via creating
3570 * an extension of the sign bit, comparing, and discarding
3571 * the bits below the sign bit. I.e.
3572 * int64_t s = (intN_t)reg;
3573 * int64_t t = (int64_t)(intN_t)reg << count;
3574 * V = ((s ^ t) & (-1 << (bits - 1))) != 0
3576 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3577 TCGv_i64 tt
= tcg_const_i64(32);
3578 /* if shift is greater than 32, use 32 */
3579 tcg_gen_movcond_i64(TCG_COND_GT
, s64
, s64
, tt
, tt
, s64
);
3580 tcg_temp_free_i64(tt
);
3581 /* Sign extend the input to 64 bits; re-do the shift. */
3582 tcg_gen_ext_i32_i64(t64
, reg
);
3583 tcg_gen_shl_i64(s64
, t64
, s64
);
3584 /* Clear all bits that are unchanged. */
3585 tcg_gen_xor_i64(t64
, t64
, s64
);
3586 /* Ignore the bits below the sign bit. */
3587 tcg_gen_andi_i64(t64
, t64
, -1ULL << (bits
- 1));
3588 /* If any bits remain set, we have overflow. */
3589 tcg_gen_setcondi_i64(TCG_COND_NE
, t64
, t64
, 0);
3590 tcg_gen_extrl_i64_i32(QREG_CC_V
, t64
);
3591 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3594 tcg_gen_shli_i64(t64
, t64
, 32);
3596 tcg_gen_shr_i64(t64
, t64
, s64
);
3598 tcg_gen_sar_i64(t64
, t64
, s64
);
3600 tcg_gen_extr_i64_i32(QREG_CC_C
, QREG_CC_N
, t64
);
3602 /* Note that C=0 if shift count is 0, and we get that for free. */
3603 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_C
, 31);
3605 /* X = C, but only if the shift count was non-zero. */
3606 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3607 QREG_CC_C
, QREG_CC_X
);
3609 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3610 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3613 tcg_temp_free_i64(s64
);
3614 tcg_temp_free_i64(t64
);
3616 /* Write back the result. */
3617 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3618 set_cc_op(s
, CC_OP_FLAGS
);
3621 DISAS_INSN(shift8_im
)
3623 shift_im(s
, insn
, OS_BYTE
);
3626 DISAS_INSN(shift16_im
)
3628 shift_im(s
, insn
, OS_WORD
);
3631 DISAS_INSN(shift_im
)
3633 shift_im(s
, insn
, OS_LONG
);
3636 DISAS_INSN(shift8_reg
)
3638 shift_reg(s
, insn
, OS_BYTE
);
3641 DISAS_INSN(shift16_reg
)
3643 shift_reg(s
, insn
, OS_WORD
);
3646 DISAS_INSN(shift_reg
)
3648 shift_reg(s
, insn
, OS_LONG
);
3651 DISAS_INSN(shift_mem
)
3653 int logical
= insn
& 8;
3654 int left
= insn
& 0x100;
3658 SRC_EA(env
, src
, OS_WORD
, !logical
, &addr
);
3659 tcg_gen_movi_i32(QREG_CC_V
, 0);
3661 tcg_gen_shri_i32(QREG_CC_C
, src
, 15);
3662 tcg_gen_shli_i32(QREG_CC_N
, src
, 1);
3665 * Note that ColdFire always clears V,
3666 * while M68000 sets if the most significant bit is changed at
3667 * any time during the shift operation
3669 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3670 src
= gen_extend(s
, src
, OS_WORD
, 1);
3671 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3674 tcg_gen_mov_i32(QREG_CC_C
, src
);
3676 tcg_gen_shri_i32(QREG_CC_N
, src
, 1);
3678 tcg_gen_sari_i32(QREG_CC_N
, src
, 1);
3682 gen_ext(QREG_CC_N
, QREG_CC_N
, OS_WORD
, 1);
3683 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3684 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3685 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3687 DEST_EA(env
, insn
, OS_WORD
, QREG_CC_N
, &addr
);
3688 set_cc_op(s
, CC_OP_FLAGS
);
3691 static void rotate(TCGv reg
, TCGv shift
, int left
, int size
)
3695 /* Replicate the 8-bit input so that a 32-bit rotate works. */
3696 tcg_gen_ext8u_i32(reg
, reg
);
3697 tcg_gen_muli_i32(reg
, reg
, 0x01010101);
3700 /* Replicate the 16-bit input so that a 32-bit rotate works. */
3701 tcg_gen_deposit_i32(reg
, reg
, reg
, 16, 16);
3706 tcg_gen_rotl_i32(reg
, reg
, shift
);
3708 tcg_gen_rotr_i32(reg
, reg
, shift
);
3716 tcg_gen_ext8s_i32(reg
, reg
);
3719 tcg_gen_ext16s_i32(reg
, reg
);
3725 /* QREG_CC_X is not affected */
3727 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3728 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3731 tcg_gen_andi_i32(QREG_CC_C
, reg
, 1);
3733 tcg_gen_shri_i32(QREG_CC_C
, reg
, 31);
3736 tcg_gen_movi_i32(QREG_CC_V
, 0); /* always cleared */
3739 static void rotate_x_flags(TCGv reg
, TCGv X
, int size
)
3743 tcg_gen_ext8s_i32(reg
, reg
);
3746 tcg_gen_ext16s_i32(reg
, reg
);
3751 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3752 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3753 tcg_gen_mov_i32(QREG_CC_X
, X
);
3754 tcg_gen_mov_i32(QREG_CC_C
, X
);
3755 tcg_gen_movi_i32(QREG_CC_V
, 0);
3758 /* Result of rotate_x() is valid if 0 <= shift <= size */
3759 static TCGv
rotate_x(TCGv reg
, TCGv shift
, int left
, int size
)
3761 TCGv X
, shl
, shr
, shx
, sz
, zero
;
3763 sz
= tcg_const_i32(size
);
3765 shr
= tcg_temp_new();
3766 shl
= tcg_temp_new();
3767 shx
= tcg_temp_new();
3769 tcg_gen_mov_i32(shl
, shift
); /* shl = shift */
3770 tcg_gen_movi_i32(shr
, size
+ 1);
3771 tcg_gen_sub_i32(shr
, shr
, shift
); /* shr = size + 1 - shift */
3772 tcg_gen_subi_i32(shx
, shift
, 1); /* shx = shift - 1 */
3773 /* shx = shx < 0 ? size : shx; */
3774 zero
= tcg_const_i32(0);
3775 tcg_gen_movcond_i32(TCG_COND_LT
, shx
, shx
, zero
, sz
, shx
);
3776 tcg_temp_free(zero
);
3778 tcg_gen_mov_i32(shr
, shift
); /* shr = shift */
3779 tcg_gen_movi_i32(shl
, size
+ 1);
3780 tcg_gen_sub_i32(shl
, shl
, shift
); /* shl = size + 1 - shift */
3781 tcg_gen_sub_i32(shx
, sz
, shift
); /* shx = size - shift */
3783 tcg_temp_free_i32(sz
);
3785 /* reg = (reg << shl) | (reg >> shr) | (x << shx); */
3787 tcg_gen_shl_i32(shl
, reg
, shl
);
3788 tcg_gen_shr_i32(shr
, reg
, shr
);
3789 tcg_gen_or_i32(reg
, shl
, shr
);
3792 tcg_gen_shl_i32(shx
, QREG_CC_X
, shx
);
3793 tcg_gen_or_i32(reg
, reg
, shx
);
3796 /* X = (reg >> size) & 1 */
3799 tcg_gen_extract_i32(X
, reg
, size
, 1);
3804 /* Result of rotate32_x() is valid if 0 <= shift < 33 */
3805 static TCGv
rotate32_x(TCGv reg
, TCGv shift
, int left
)
3807 TCGv_i64 t0
, shift64
;
3808 TCGv X
, lo
, hi
, zero
;
3810 shift64
= tcg_temp_new_i64();
3811 tcg_gen_extu_i32_i64(shift64
, shift
);
3813 t0
= tcg_temp_new_i64();
3816 lo
= tcg_temp_new();
3817 hi
= tcg_temp_new();
3820 /* create [reg:X:..] */
3822 tcg_gen_shli_i32(lo
, QREG_CC_X
, 31);
3823 tcg_gen_concat_i32_i64(t0
, lo
, reg
);
3827 tcg_gen_rotl_i64(t0
, t0
, shift64
);
3828 tcg_temp_free_i64(shift64
);
3830 /* result is [reg:..:reg:X] */
3832 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3833 tcg_gen_andi_i32(X
, lo
, 1);
3835 tcg_gen_shri_i32(lo
, lo
, 1);
3837 /* create [..:X:reg] */
3839 tcg_gen_concat_i32_i64(t0
, reg
, QREG_CC_X
);
3841 tcg_gen_rotr_i64(t0
, t0
, shift64
);
3842 tcg_temp_free_i64(shift64
);
3844 /* result is value: [X:reg:..:reg] */
3846 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3850 tcg_gen_shri_i32(X
, hi
, 31);
3852 /* extract result */
3854 tcg_gen_shli_i32(hi
, hi
, 1);
3856 tcg_temp_free_i64(t0
);
3857 tcg_gen_or_i32(lo
, lo
, hi
);
3860 /* if shift == 0, register and X are not affected */
3862 zero
= tcg_const_i32(0);
3863 tcg_gen_movcond_i32(TCG_COND_EQ
, X
, shift
, zero
, QREG_CC_X
, X
);
3864 tcg_gen_movcond_i32(TCG_COND_EQ
, reg
, shift
, zero
, reg
, lo
);
3865 tcg_temp_free(zero
);
3871 DISAS_INSN(rotate_im
)
3875 int left
= (insn
& 0x100);
3877 tmp
= (insn
>> 9) & 7;
3882 shift
= tcg_const_i32(tmp
);
3884 rotate(DREG(insn
, 0), shift
, left
, 32);
3886 TCGv X
= rotate32_x(DREG(insn
, 0), shift
, left
);
3887 rotate_x_flags(DREG(insn
, 0), X
, 32);
3890 tcg_temp_free(shift
);
3892 set_cc_op(s
, CC_OP_FLAGS
);
3895 DISAS_INSN(rotate8_im
)
3897 int left
= (insn
& 0x100);
3902 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3904 tmp
= (insn
>> 9) & 7;
3909 shift
= tcg_const_i32(tmp
);
3911 rotate(reg
, shift
, left
, 8);
3913 TCGv X
= rotate_x(reg
, shift
, left
, 8);
3914 rotate_x_flags(reg
, X
, 8);
3917 tcg_temp_free(shift
);
3918 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3919 set_cc_op(s
, CC_OP_FLAGS
);
3922 DISAS_INSN(rotate16_im
)
3924 int left
= (insn
& 0x100);
3929 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
3930 tmp
= (insn
>> 9) & 7;
3935 shift
= tcg_const_i32(tmp
);
3937 rotate(reg
, shift
, left
, 16);
3939 TCGv X
= rotate_x(reg
, shift
, left
, 16);
3940 rotate_x_flags(reg
, X
, 16);
3943 tcg_temp_free(shift
);
3944 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3945 set_cc_op(s
, CC_OP_FLAGS
);
3948 DISAS_INSN(rotate_reg
)
3953 int left
= (insn
& 0x100);
3955 reg
= DREG(insn
, 0);
3956 src
= DREG(insn
, 9);
3957 /* shift in [0..63] */
3958 t0
= tcg_temp_new();
3959 tcg_gen_andi_i32(t0
, src
, 63);
3960 t1
= tcg_temp_new_i32();
3962 tcg_gen_andi_i32(t1
, src
, 31);
3963 rotate(reg
, t1
, left
, 32);
3964 /* if shift == 0, clear C */
3965 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3966 t0
, QREG_CC_V
/* 0 */,
3967 QREG_CC_V
/* 0 */, QREG_CC_C
);
3971 tcg_gen_movi_i32(t1
, 33);
3972 tcg_gen_remu_i32(t1
, t0
, t1
);
3973 X
= rotate32_x(DREG(insn
, 0), t1
, left
);
3974 rotate_x_flags(DREG(insn
, 0), X
, 32);
3979 set_cc_op(s
, CC_OP_FLAGS
);
3982 DISAS_INSN(rotate8_reg
)
3987 int left
= (insn
& 0x100);
3989 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3990 src
= DREG(insn
, 9);
3991 /* shift in [0..63] */
3992 t0
= tcg_temp_new_i32();
3993 tcg_gen_andi_i32(t0
, src
, 63);
3994 t1
= tcg_temp_new_i32();
3996 tcg_gen_andi_i32(t1
, src
, 7);
3997 rotate(reg
, t1
, left
, 8);
3998 /* if shift == 0, clear C */
3999 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
4000 t0
, QREG_CC_V
/* 0 */,
4001 QREG_CC_V
/* 0 */, QREG_CC_C
);
4005 tcg_gen_movi_i32(t1
, 9);
4006 tcg_gen_remu_i32(t1
, t0
, t1
);
4007 X
= rotate_x(reg
, t1
, left
, 8);
4008 rotate_x_flags(reg
, X
, 8);
4013 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
4014 set_cc_op(s
, CC_OP_FLAGS
);
4017 DISAS_INSN(rotate16_reg
)
4022 int left
= (insn
& 0x100);
4024 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
4025 src
= DREG(insn
, 9);
4026 /* shift in [0..63] */
4027 t0
= tcg_temp_new_i32();
4028 tcg_gen_andi_i32(t0
, src
, 63);
4029 t1
= tcg_temp_new_i32();
4031 tcg_gen_andi_i32(t1
, src
, 15);
4032 rotate(reg
, t1
, left
, 16);
4033 /* if shift == 0, clear C */
4034 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
4035 t0
, QREG_CC_V
/* 0 */,
4036 QREG_CC_V
/* 0 */, QREG_CC_C
);
4040 tcg_gen_movi_i32(t1
, 17);
4041 tcg_gen_remu_i32(t1
, t0
, t1
);
4042 X
= rotate_x(reg
, t1
, left
, 16);
4043 rotate_x_flags(reg
, X
, 16);
4048 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
4049 set_cc_op(s
, CC_OP_FLAGS
);
4052 DISAS_INSN(rotate_mem
)
4057 int left
= (insn
& 0x100);
4059 SRC_EA(env
, src
, OS_WORD
, 0, &addr
);
4061 shift
= tcg_const_i32(1);
4062 if (insn
& 0x0200) {
4063 rotate(src
, shift
, left
, 16);
4065 TCGv X
= rotate_x(src
, shift
, left
, 16);
4066 rotate_x_flags(src
, X
, 16);
4069 tcg_temp_free(shift
);
4070 DEST_EA(env
, insn
, OS_WORD
, src
, &addr
);
4071 set_cc_op(s
, CC_OP_FLAGS
);
4074 DISAS_INSN(bfext_reg
)
4076 int ext
= read_im16(env
, s
);
4077 int is_sign
= insn
& 0x200;
4078 TCGv src
= DREG(insn
, 0);
4079 TCGv dst
= DREG(ext
, 12);
4080 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4081 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4082 int pos
= 32 - ofs
- len
; /* little bit-endian */
4083 TCGv tmp
= tcg_temp_new();
4087 * In general, we're going to rotate the field so that it's at the
4088 * top of the word and then right-shift by the complement of the
4089 * width to extend the field.
4092 /* Variable width. */
4094 /* Variable offset. */
4095 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4096 tcg_gen_rotl_i32(tmp
, src
, tmp
);
4098 tcg_gen_rotli_i32(tmp
, src
, ofs
);
4101 shift
= tcg_temp_new();
4102 tcg_gen_neg_i32(shift
, DREG(ext
, 0));
4103 tcg_gen_andi_i32(shift
, shift
, 31);
4104 tcg_gen_sar_i32(QREG_CC_N
, tmp
, shift
);
4106 tcg_gen_mov_i32(dst
, QREG_CC_N
);
4108 tcg_gen_shr_i32(dst
, tmp
, shift
);
4110 tcg_temp_free(shift
);
4112 /* Immediate width. */
4114 /* Variable offset */
4115 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4116 tcg_gen_rotl_i32(tmp
, src
, tmp
);
4121 * Immediate offset. If the field doesn't wrap around the
4122 * end of the word, rely on (s)extract completely.
4125 tcg_gen_rotli_i32(tmp
, src
, ofs
);
4131 tcg_gen_sextract_i32(QREG_CC_N
, src
, pos
, len
);
4133 tcg_gen_mov_i32(dst
, QREG_CC_N
);
4135 tcg_gen_extract_i32(dst
, src
, pos
, len
);
4140 set_cc_op(s
, CC_OP_LOGIC
);
4143 DISAS_INSN(bfext_mem
)
4145 int ext
= read_im16(env
, s
);
4146 int is_sign
= insn
& 0x200;
4147 TCGv dest
= DREG(ext
, 12);
4148 TCGv addr
, len
, ofs
;
4150 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4151 if (IS_NULL_QREG(addr
)) {
4159 len
= tcg_const_i32(extract32(ext
, 0, 5));
4164 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4168 gen_helper_bfexts_mem(dest
, cpu_env
, addr
, ofs
, len
);
4169 tcg_gen_mov_i32(QREG_CC_N
, dest
);
4171 TCGv_i64 tmp
= tcg_temp_new_i64();
4172 gen_helper_bfextu_mem(tmp
, cpu_env
, addr
, ofs
, len
);
4173 tcg_gen_extr_i64_i32(dest
, QREG_CC_N
, tmp
);
4174 tcg_temp_free_i64(tmp
);
4176 set_cc_op(s
, CC_OP_LOGIC
);
4178 if (!(ext
& 0x20)) {
4181 if (!(ext
& 0x800)) {
4186 DISAS_INSN(bfop_reg
)
4188 int ext
= read_im16(env
, s
);
4189 TCGv src
= DREG(insn
, 0);
4190 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4191 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4192 TCGv mask
, tofs
, tlen
;
4196 if ((insn
& 0x0f00) == 0x0d00) { /* bfffo */
4197 tofs
= tcg_temp_new();
4198 tlen
= tcg_temp_new();
4201 if ((ext
& 0x820) == 0) {
4202 /* Immediate width and offset. */
4203 uint32_t maski
= 0x7fffffffu
>> (len
- 1);
4204 if (ofs
+ len
<= 32) {
4205 tcg_gen_shli_i32(QREG_CC_N
, src
, ofs
);
4207 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4209 tcg_gen_andi_i32(QREG_CC_N
, QREG_CC_N
, ~maski
);
4210 mask
= tcg_const_i32(ror32(maski
, ofs
));
4212 tcg_gen_movi_i32(tofs
, ofs
);
4213 tcg_gen_movi_i32(tlen
, len
);
4216 TCGv tmp
= tcg_temp_new();
4218 /* Variable width */
4219 tcg_gen_subi_i32(tmp
, DREG(ext
, 0), 1);
4220 tcg_gen_andi_i32(tmp
, tmp
, 31);
4221 mask
= tcg_const_i32(0x7fffffffu
);
4222 tcg_gen_shr_i32(mask
, mask
, tmp
);
4224 tcg_gen_addi_i32(tlen
, tmp
, 1);
4227 /* Immediate width */
4228 mask
= tcg_const_i32(0x7fffffffu
>> (len
- 1));
4230 tcg_gen_movi_i32(tlen
, len
);
4234 /* Variable offset */
4235 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4236 tcg_gen_rotl_i32(QREG_CC_N
, src
, tmp
);
4237 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4238 tcg_gen_rotr_i32(mask
, mask
, tmp
);
4240 tcg_gen_mov_i32(tofs
, tmp
);
4243 /* Immediate offset (and variable width) */
4244 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4245 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4246 tcg_gen_rotri_i32(mask
, mask
, ofs
);
4248 tcg_gen_movi_i32(tofs
, ofs
);
4253 set_cc_op(s
, CC_OP_LOGIC
);
4255 switch (insn
& 0x0f00) {
4256 case 0x0a00: /* bfchg */
4257 tcg_gen_eqv_i32(src
, src
, mask
);
4259 case 0x0c00: /* bfclr */
4260 tcg_gen_and_i32(src
, src
, mask
);
4262 case 0x0d00: /* bfffo */
4263 gen_helper_bfffo_reg(DREG(ext
, 12), QREG_CC_N
, tofs
, tlen
);
4264 tcg_temp_free(tlen
);
4265 tcg_temp_free(tofs
);
4267 case 0x0e00: /* bfset */
4268 tcg_gen_orc_i32(src
, src
, mask
);
4270 case 0x0800: /* bftst */
4271 /* flags already set; no other work to do. */
4274 g_assert_not_reached();
4276 tcg_temp_free(mask
);
4279 DISAS_INSN(bfop_mem
)
4281 int ext
= read_im16(env
, s
);
4282 TCGv addr
, len
, ofs
;
4285 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4286 if (IS_NULL_QREG(addr
)) {
4294 len
= tcg_const_i32(extract32(ext
, 0, 5));
4299 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4302 switch (insn
& 0x0f00) {
4303 case 0x0a00: /* bfchg */
4304 gen_helper_bfchg_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4306 case 0x0c00: /* bfclr */
4307 gen_helper_bfclr_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4309 case 0x0d00: /* bfffo */
4310 t64
= tcg_temp_new_i64();
4311 gen_helper_bfffo_mem(t64
, cpu_env
, addr
, ofs
, len
);
4312 tcg_gen_extr_i64_i32(DREG(ext
, 12), QREG_CC_N
, t64
);
4313 tcg_temp_free_i64(t64
);
4315 case 0x0e00: /* bfset */
4316 gen_helper_bfset_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4318 case 0x0800: /* bftst */
4319 gen_helper_bfexts_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4322 g_assert_not_reached();
4324 set_cc_op(s
, CC_OP_LOGIC
);
4326 if (!(ext
& 0x20)) {
4329 if (!(ext
& 0x800)) {
4334 DISAS_INSN(bfins_reg
)
4336 int ext
= read_im16(env
, s
);
4337 TCGv dst
= DREG(insn
, 0);
4338 TCGv src
= DREG(ext
, 12);
4339 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4340 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4341 int pos
= 32 - ofs
- len
; /* little bit-endian */
4344 tmp
= tcg_temp_new();
4347 /* Variable width */
4348 tcg_gen_neg_i32(tmp
, DREG(ext
, 0));
4349 tcg_gen_andi_i32(tmp
, tmp
, 31);
4350 tcg_gen_shl_i32(QREG_CC_N
, src
, tmp
);
4352 /* Immediate width */
4353 tcg_gen_shli_i32(QREG_CC_N
, src
, 32 - len
);
4355 set_cc_op(s
, CC_OP_LOGIC
);
4357 /* Immediate width and offset */
4358 if ((ext
& 0x820) == 0) {
4359 /* Check for suitability for deposit. */
4361 tcg_gen_deposit_i32(dst
, dst
, src
, pos
, len
);
4363 uint32_t maski
= -2U << (len
- 1);
4364 uint32_t roti
= (ofs
+ len
) & 31;
4365 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4366 tcg_gen_rotri_i32(tmp
, tmp
, roti
);
4367 tcg_gen_andi_i32(dst
, dst
, ror32(maski
, roti
));
4368 tcg_gen_or_i32(dst
, dst
, tmp
);
4371 TCGv mask
= tcg_temp_new();
4372 TCGv rot
= tcg_temp_new();
4375 /* Variable width */
4376 tcg_gen_subi_i32(rot
, DREG(ext
, 0), 1);
4377 tcg_gen_andi_i32(rot
, rot
, 31);
4378 tcg_gen_movi_i32(mask
, -2);
4379 tcg_gen_shl_i32(mask
, mask
, rot
);
4380 tcg_gen_mov_i32(rot
, DREG(ext
, 0));
4381 tcg_gen_andc_i32(tmp
, src
, mask
);
4383 /* Immediate width (variable offset) */
4384 uint32_t maski
= -2U << (len
- 1);
4385 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4386 tcg_gen_movi_i32(mask
, maski
);
4387 tcg_gen_movi_i32(rot
, len
& 31);
4390 /* Variable offset */
4391 tcg_gen_add_i32(rot
, rot
, DREG(ext
, 6));
4393 /* Immediate offset (variable width) */
4394 tcg_gen_addi_i32(rot
, rot
, ofs
);
4396 tcg_gen_andi_i32(rot
, rot
, 31);
4397 tcg_gen_rotr_i32(mask
, mask
, rot
);
4398 tcg_gen_rotr_i32(tmp
, tmp
, rot
);
4399 tcg_gen_and_i32(dst
, dst
, mask
);
4400 tcg_gen_or_i32(dst
, dst
, tmp
);
4403 tcg_temp_free(mask
);
4408 DISAS_INSN(bfins_mem
)
4410 int ext
= read_im16(env
, s
);
4411 TCGv src
= DREG(ext
, 12);
4412 TCGv addr
, len
, ofs
;
4414 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4415 if (IS_NULL_QREG(addr
)) {
4423 len
= tcg_const_i32(extract32(ext
, 0, 5));
4428 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4431 gen_helper_bfins_mem(QREG_CC_N
, cpu_env
, addr
, src
, ofs
, len
);
4432 set_cc_op(s
, CC_OP_LOGIC
);
4434 if (!(ext
& 0x20)) {
4437 if (!(ext
& 0x800)) {
4445 reg
= DREG(insn
, 0);
4446 gen_logic_cc(s
, reg
, OS_LONG
);
4447 gen_helper_ff1(reg
, reg
);
4455 switch ((insn
>> 7) & 3) {
4460 if (m68k_feature(env
, M68K_FEATURE_CHK2
)) {
4466 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4469 SRC_EA(env
, src
, opsize
, 1, NULL
);
4470 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
4473 gen_helper_chk(cpu_env
, reg
, src
);
4479 TCGv addr1
, addr2
, bound1
, bound2
, reg
;
4482 switch ((insn
>> 9) & 3) {
4493 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4497 ext
= read_im16(env
, s
);
4498 if ((ext
& 0x0800) == 0) {
4499 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4503 addr1
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4504 addr2
= tcg_temp_new();
4505 tcg_gen_addi_i32(addr2
, addr1
, opsize_bytes(opsize
));
4507 bound1
= gen_load(s
, opsize
, addr1
, 1, IS_USER(s
));
4508 tcg_temp_free(addr1
);
4509 bound2
= gen_load(s
, opsize
, addr2
, 1, IS_USER(s
));
4510 tcg_temp_free(addr2
);
4512 reg
= tcg_temp_new();
4514 tcg_gen_mov_i32(reg
, AREG(ext
, 12));
4516 gen_ext(reg
, DREG(ext
, 12), opsize
, 1);
4520 gen_helper_chk2(cpu_env
, reg
, bound1
, bound2
);
4522 tcg_temp_free(bound1
);
4523 tcg_temp_free(bound2
);
4526 static void m68k_copy_line(TCGv dst
, TCGv src
, int index
)
4531 addr
= tcg_temp_new();
4533 t0
= tcg_temp_new_i64();
4534 t1
= tcg_temp_new_i64();
4536 tcg_gen_andi_i32(addr
, src
, ~15);
4537 tcg_gen_qemu_ld64(t0
, addr
, index
);
4538 tcg_gen_addi_i32(addr
, addr
, 8);
4539 tcg_gen_qemu_ld64(t1
, addr
, index
);
4541 tcg_gen_andi_i32(addr
, dst
, ~15);
4542 tcg_gen_qemu_st64(t0
, addr
, index
);
4543 tcg_gen_addi_i32(addr
, addr
, 8);
4544 tcg_gen_qemu_st64(t1
, addr
, index
);
4546 tcg_temp_free_i64(t0
);
4547 tcg_temp_free_i64(t1
);
4548 tcg_temp_free(addr
);
4551 DISAS_INSN(move16_reg
)
4553 int index
= IS_USER(s
);
4557 ext
= read_im16(env
, s
);
4558 if ((ext
& (1 << 15)) == 0) {
4559 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4562 m68k_copy_line(AREG(ext
, 12), AREG(insn
, 0), index
);
4564 /* Ax can be Ay, so save Ay before incrementing Ax */
4565 tmp
= tcg_temp_new();
4566 tcg_gen_mov_i32(tmp
, AREG(ext
, 12));
4567 tcg_gen_addi_i32(AREG(insn
, 0), AREG(insn
, 0), 16);
4568 tcg_gen_addi_i32(AREG(ext
, 12), tmp
, 16);
4572 DISAS_INSN(move16_mem
)
4574 int index
= IS_USER(s
);
4577 reg
= AREG(insn
, 0);
4578 addr
= tcg_const_i32(read_im32(env
, s
));
4580 if ((insn
>> 3) & 1) {
4581 /* MOVE16 (xxx).L, (Ay) */
4582 m68k_copy_line(reg
, addr
, index
);
4584 /* MOVE16 (Ay), (xxx).L */
4585 m68k_copy_line(addr
, reg
, index
);
4588 tcg_temp_free(addr
);
4590 if (((insn
>> 3) & 2) == 0) {
4592 tcg_gen_addi_i32(reg
, reg
, 16);
4602 ext
= read_im16(env
, s
);
4603 if (ext
!= 0x46FC) {
4604 gen_exception(s
, addr
, EXCP_ILLEGAL
);
4607 ext
= read_im16(env
, s
);
4608 if (IS_USER(s
) || (ext
& SR_S
) == 0) {
4609 gen_exception(s
, addr
, EXCP_PRIVILEGE
);
4612 gen_push(s
, gen_get_sr(s
));
4613 gen_set_sr_im(s
, ext
, 0);
4616 DISAS_INSN(move_from_sr
)
4620 if (IS_USER(s
) && !m68k_feature(env
, M68K_FEATURE_M68000
)) {
4621 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4625 DEST_EA(env
, insn
, OS_WORD
, sr
, NULL
);
4628 #if defined(CONFIG_SOFTMMU)
4638 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4642 ext
= read_im16(env
, s
);
4644 opsize
= insn_opsize(insn
);
4647 /* address register */
4648 reg
= AREG(ext
, 12);
4652 reg
= DREG(ext
, 12);
4656 addr
= gen_lea(env
, s
, insn
, opsize
);
4657 if (IS_NULL_QREG(addr
)) {
4663 /* from reg to ea */
4664 gen_store(s
, opsize
, addr
, reg
, DFC_INDEX(s
));
4666 /* from ea to reg */
4667 TCGv tmp
= gen_load(s
, opsize
, addr
, 0, SFC_INDEX(s
));
4669 gen_ext(reg
, tmp
, opsize
, 1);
4671 gen_partset_reg(opsize
, reg
, tmp
);
4675 switch (extract32(insn
, 3, 3)) {
4676 case 3: /* Indirect postincrement. */
4677 tcg_gen_addi_i32(AREG(insn
, 0), addr
,
4678 REG(insn
, 0) == 7 && opsize
== OS_BYTE
4680 : opsize_bytes(opsize
));
4682 case 4: /* Indirect predecrememnt. */
4683 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4688 DISAS_INSN(move_to_sr
)
4691 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4694 gen_move_to_sr(env
, s
, insn
, false);
4698 DISAS_INSN(move_from_usp
)
4701 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4704 tcg_gen_ld_i32(AREG(insn
, 0), cpu_env
,
4705 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4708 DISAS_INSN(move_to_usp
)
4711 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4714 tcg_gen_st_i32(AREG(insn
, 0), cpu_env
,
4715 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4721 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4725 gen_exception(s
, s
->pc
, EXCP_HALT_INSN
);
4733 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4737 ext
= read_im16(env
, s
);
4739 gen_set_sr_im(s
, ext
, 0);
4740 tcg_gen_movi_i32(cpu_halted
, 1);
4741 gen_exception(s
, s
->pc
, EXCP_HLT
);
4747 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4750 gen_exception(s
, s
->base
.pc_next
, EXCP_RTE
);
4753 DISAS_INSN(cf_movec
)
4759 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4763 ext
= read_im16(env
, s
);
4766 reg
= AREG(ext
, 12);
4768 reg
= DREG(ext
, 12);
4770 gen_helper_cf_movec_to(cpu_env
, tcg_const_i32(ext
& 0xfff), reg
);
4774 DISAS_INSN(m68k_movec
)
4780 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4784 ext
= read_im16(env
, s
);
4787 reg
= AREG(ext
, 12);
4789 reg
= DREG(ext
, 12);
4792 gen_helper_m68k_movec_to(cpu_env
, tcg_const_i32(ext
& 0xfff), reg
);
4794 gen_helper_m68k_movec_from(reg
, cpu_env
, tcg_const_i32(ext
& 0xfff));
4802 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4805 /* ICache fetch. Implement as no-op. */
4811 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4814 /* Cache push/invalidate. Implement as no-op. */
4820 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4823 /* Cache push/invalidate. Implement as no-op. */
4829 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4832 /* Invalidate cache line. Implement as no-op. */
4835 #if defined(CONFIG_SOFTMMU)
4841 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4845 opmode
= tcg_const_i32((insn
>> 3) & 3);
4846 gen_helper_pflush(cpu_env
, AREG(insn
, 0), opmode
);
4847 tcg_temp_free(opmode
);
4855 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4858 is_read
= tcg_const_i32((insn
>> 5) & 1);
4859 gen_helper_ptest(cpu_env
, AREG(insn
, 0), is_read
);
4860 tcg_temp_free(is_read
);
4866 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4872 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4875 /* TODO: Implement wdebug. */
4876 cpu_abort(env_cpu(env
), "WDEBUG not implemented");
4882 gen_exception(s
, s
->base
.pc_next
, EXCP_TRAP0
+ (insn
& 0xf));
4885 static void gen_load_fcr(DisasContext
*s
, TCGv res
, int reg
)
4889 tcg_gen_movi_i32(res
, 0);
4892 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4895 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpcr
));
4900 static void gen_store_fcr(DisasContext
*s
, TCGv val
, int reg
)
4906 tcg_gen_st_i32(val
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4909 gen_helper_set_fpcr(cpu_env
, val
);
4914 static void gen_qemu_store_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4916 int index
= IS_USER(s
);
4919 tmp
= tcg_temp_new();
4920 gen_load_fcr(s
, tmp
, reg
);
4921 tcg_gen_qemu_st32(tmp
, addr
, index
);
4925 static void gen_qemu_load_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4927 int index
= IS_USER(s
);
4930 tmp
= tcg_temp_new();
4931 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
4932 gen_store_fcr(s
, tmp
, reg
);
4937 static void gen_op_fmove_fcr(CPUM68KState
*env
, DisasContext
*s
,
4938 uint32_t insn
, uint32_t ext
)
4940 int mask
= (ext
>> 10) & 7;
4941 int is_write
= (ext
>> 13) & 1;
4942 int mode
= extract32(insn
, 3, 3);
4948 if (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&& mask
!= M68K_FPCR
) {
4949 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4953 gen_load_fcr(s
, DREG(insn
, 0), mask
);
4955 gen_store_fcr(s
, DREG(insn
, 0), mask
);
4958 case 1: /* An, only with FPIAR */
4959 if (mask
!= M68K_FPIAR
) {
4960 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4964 gen_load_fcr(s
, AREG(insn
, 0), mask
);
4966 gen_store_fcr(s
, AREG(insn
, 0), mask
);
4969 case 7: /* Immediate */
4970 if (REG(insn
, 0) == 4) {
4972 (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&&
4973 mask
!= M68K_FPCR
)) {
4974 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4977 tmp
= tcg_const_i32(read_im32(env
, s
));
4978 gen_store_fcr(s
, tmp
, mask
);
4987 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
4988 if (IS_NULL_QREG(tmp
)) {
4993 addr
= tcg_temp_new();
4994 tcg_gen_mov_i32(addr
, tmp
);
4999 * 0b100 Floating-Point Control Register
5000 * 0b010 Floating-Point Status Register
5001 * 0b001 Floating-Point Instruction Address Register
5005 if (is_write
&& mode
== 4) {
5006 for (i
= 2; i
>= 0; i
--, mask
>>= 1) {
5008 gen_qemu_store_fcr(s
, addr
, 1 << i
);
5010 tcg_gen_subi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
5014 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5016 for (i
= 0; i
< 3; i
++, mask
>>= 1) {
5019 gen_qemu_store_fcr(s
, addr
, 1 << i
);
5021 gen_qemu_load_fcr(s
, addr
, 1 << i
);
5023 if (mask
!= 1 || mode
== 3) {
5024 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
5029 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5032 tcg_temp_free_i32(addr
);
5035 static void gen_op_fmovem(CPUM68KState
*env
, DisasContext
*s
,
5036 uint32_t insn
, uint32_t ext
)
5040 int mode
= (ext
>> 11) & 0x3;
5041 int is_load
= ((ext
& 0x2000) == 0);
5043 if (m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
5044 opsize
= OS_EXTENDED
;
5046 opsize
= OS_DOUBLE
; /* FIXME */
5049 addr
= gen_lea(env
, s
, insn
, opsize
);
5050 if (IS_NULL_QREG(addr
)) {
5055 tmp
= tcg_temp_new();
5057 /* Dynamic register list */
5058 tcg_gen_ext8u_i32(tmp
, DREG(ext
, 4));
5060 /* Static register list */
5061 tcg_gen_movi_i32(tmp
, ext
& 0xff);
5064 if (!is_load
&& (mode
& 2) == 0) {
5066 * predecrement addressing mode
5067 * only available to store register to memory
5069 if (opsize
== OS_EXTENDED
) {
5070 gen_helper_fmovemx_st_predec(tmp
, cpu_env
, addr
, tmp
);
5072 gen_helper_fmovemd_st_predec(tmp
, cpu_env
, addr
, tmp
);
5075 /* postincrement addressing mode */
5076 if (opsize
== OS_EXTENDED
) {
5078 gen_helper_fmovemx_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
5080 gen_helper_fmovemx_st_postinc(tmp
, cpu_env
, addr
, tmp
);
5084 gen_helper_fmovemd_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
5086 gen_helper_fmovemd_st_postinc(tmp
, cpu_env
, addr
, tmp
);
5090 if ((insn
& 070) == 030 || (insn
& 070) == 040) {
5091 tcg_gen_mov_i32(AREG(insn
, 0), tmp
);
5097 * ??? FP exceptions are not implemented. Most exceptions are deferred until
5098 * immediately before the next FP instruction is executed.
5105 TCGv_ptr cpu_src
, cpu_dest
;
5107 ext
= read_im16(env
, s
);
5108 opmode
= ext
& 0x7f;
5109 switch ((ext
>> 13) & 7) {
5115 if (insn
== 0xf200 && (ext
& 0xfc00) == 0x5c00) {
5117 TCGv rom_offset
= tcg_const_i32(opmode
);
5118 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
5119 gen_helper_fconst(cpu_env
, cpu_dest
, rom_offset
);
5120 tcg_temp_free_ptr(cpu_dest
);
5121 tcg_temp_free(rom_offset
);
5125 case 3: /* fmove out */
5126 cpu_src
= gen_fp_ptr(REG(ext
, 7));
5127 opsize
= ext_opsize(ext
, 10);
5128 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
5129 EA_STORE
, IS_USER(s
)) == -1) {
5132 gen_helper_ftst(cpu_env
, cpu_src
);
5133 tcg_temp_free_ptr(cpu_src
);
5135 case 4: /* fmove to control register. */
5136 case 5: /* fmove from control register. */
5137 gen_op_fmove_fcr(env
, s
, insn
, ext
);
5139 case 6: /* fmovem */
5141 if ((ext
& 0x1000) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
5144 gen_op_fmovem(env
, s
, insn
, ext
);
5147 if (ext
& (1 << 14)) {
5148 /* Source effective address. */
5149 opsize
= ext_opsize(ext
, 10);
5150 cpu_src
= gen_fp_result_ptr();
5151 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
5152 EA_LOADS
, IS_USER(s
)) == -1) {
5157 /* Source register. */
5158 opsize
= OS_EXTENDED
;
5159 cpu_src
= gen_fp_ptr(REG(ext
, 10));
5161 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
5164 gen_fp_move(cpu_dest
, cpu_src
);
5166 case 0x40: /* fsmove */
5167 gen_helper_fsround(cpu_env
, cpu_dest
, cpu_src
);
5169 case 0x44: /* fdmove */
5170 gen_helper_fdround(cpu_env
, cpu_dest
, cpu_src
);
5173 gen_helper_firound(cpu_env
, cpu_dest
, cpu_src
);
5176 gen_helper_fsinh(cpu_env
, cpu_dest
, cpu_src
);
5178 case 3: /* fintrz */
5179 gen_helper_fitrunc(cpu_env
, cpu_dest
, cpu_src
);
5182 gen_helper_fsqrt(cpu_env
, cpu_dest
, cpu_src
);
5184 case 0x41: /* fssqrt */
5185 gen_helper_fssqrt(cpu_env
, cpu_dest
, cpu_src
);
5187 case 0x45: /* fdsqrt */
5188 gen_helper_fdsqrt(cpu_env
, cpu_dest
, cpu_src
);
5190 case 0x06: /* flognp1 */
5191 gen_helper_flognp1(cpu_env
, cpu_dest
, cpu_src
);
5193 case 0x08: /* fetoxm1 */
5194 gen_helper_fetoxm1(cpu_env
, cpu_dest
, cpu_src
);
5196 case 0x09: /* ftanh */
5197 gen_helper_ftanh(cpu_env
, cpu_dest
, cpu_src
);
5199 case 0x0a: /* fatan */
5200 gen_helper_fatan(cpu_env
, cpu_dest
, cpu_src
);
5202 case 0x0c: /* fasin */
5203 gen_helper_fasin(cpu_env
, cpu_dest
, cpu_src
);
5205 case 0x0d: /* fatanh */
5206 gen_helper_fatanh(cpu_env
, cpu_dest
, cpu_src
);
5208 case 0x0e: /* fsin */
5209 gen_helper_fsin(cpu_env
, cpu_dest
, cpu_src
);
5211 case 0x0f: /* ftan */
5212 gen_helper_ftan(cpu_env
, cpu_dest
, cpu_src
);
5214 case 0x10: /* fetox */
5215 gen_helper_fetox(cpu_env
, cpu_dest
, cpu_src
);
5217 case 0x11: /* ftwotox */
5218 gen_helper_ftwotox(cpu_env
, cpu_dest
, cpu_src
);
5220 case 0x12: /* ftentox */
5221 gen_helper_ftentox(cpu_env
, cpu_dest
, cpu_src
);
5223 case 0x14: /* flogn */
5224 gen_helper_flogn(cpu_env
, cpu_dest
, cpu_src
);
5226 case 0x15: /* flog10 */
5227 gen_helper_flog10(cpu_env
, cpu_dest
, cpu_src
);
5229 case 0x16: /* flog2 */
5230 gen_helper_flog2(cpu_env
, cpu_dest
, cpu_src
);
5232 case 0x18: /* fabs */
5233 gen_helper_fabs(cpu_env
, cpu_dest
, cpu_src
);
5235 case 0x58: /* fsabs */
5236 gen_helper_fsabs(cpu_env
, cpu_dest
, cpu_src
);
5238 case 0x5c: /* fdabs */
5239 gen_helper_fdabs(cpu_env
, cpu_dest
, cpu_src
);
5241 case 0x19: /* fcosh */
5242 gen_helper_fcosh(cpu_env
, cpu_dest
, cpu_src
);
5244 case 0x1a: /* fneg */
5245 gen_helper_fneg(cpu_env
, cpu_dest
, cpu_src
);
5247 case 0x5a: /* fsneg */
5248 gen_helper_fsneg(cpu_env
, cpu_dest
, cpu_src
);
5250 case 0x5e: /* fdneg */
5251 gen_helper_fdneg(cpu_env
, cpu_dest
, cpu_src
);
5253 case 0x1c: /* facos */
5254 gen_helper_facos(cpu_env
, cpu_dest
, cpu_src
);
5256 case 0x1d: /* fcos */
5257 gen_helper_fcos(cpu_env
, cpu_dest
, cpu_src
);
5259 case 0x1e: /* fgetexp */
5260 gen_helper_fgetexp(cpu_env
, cpu_dest
, cpu_src
);
5262 case 0x1f: /* fgetman */
5263 gen_helper_fgetman(cpu_env
, cpu_dest
, cpu_src
);
5265 case 0x20: /* fdiv */
5266 gen_helper_fdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5268 case 0x60: /* fsdiv */
5269 gen_helper_fsdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5271 case 0x64: /* fddiv */
5272 gen_helper_fddiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5274 case 0x21: /* fmod */
5275 gen_helper_fmod(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5277 case 0x22: /* fadd */
5278 gen_helper_fadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5280 case 0x62: /* fsadd */
5281 gen_helper_fsadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5283 case 0x66: /* fdadd */
5284 gen_helper_fdadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5286 case 0x23: /* fmul */
5287 gen_helper_fmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5289 case 0x63: /* fsmul */
5290 gen_helper_fsmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5292 case 0x67: /* fdmul */
5293 gen_helper_fdmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5295 case 0x24: /* fsgldiv */
5296 gen_helper_fsgldiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5298 case 0x25: /* frem */
5299 gen_helper_frem(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5301 case 0x26: /* fscale */
5302 gen_helper_fscale(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5304 case 0x27: /* fsglmul */
5305 gen_helper_fsglmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5307 case 0x28: /* fsub */
5308 gen_helper_fsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5310 case 0x68: /* fssub */
5311 gen_helper_fssub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5313 case 0x6c: /* fdsub */
5314 gen_helper_fdsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
5316 case 0x30: case 0x31: case 0x32:
5317 case 0x33: case 0x34: case 0x35:
5318 case 0x36: case 0x37: {
5319 TCGv_ptr cpu_dest2
= gen_fp_ptr(REG(ext
, 0));
5320 gen_helper_fsincos(cpu_env
, cpu_dest
, cpu_dest2
, cpu_src
);
5321 tcg_temp_free_ptr(cpu_dest2
);
5324 case 0x38: /* fcmp */
5325 gen_helper_fcmp(cpu_env
, cpu_src
, cpu_dest
);
5327 case 0x3a: /* ftst */
5328 gen_helper_ftst(cpu_env
, cpu_src
);
5333 tcg_temp_free_ptr(cpu_src
);
5334 gen_helper_ftst(cpu_env
, cpu_dest
);
5335 tcg_temp_free_ptr(cpu_dest
);
5338 /* FIXME: Is this right for offset addressing modes? */
5340 disas_undef_fpu(env
, s
, insn
);
5343 static void gen_fcc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
5348 c
->v2
= tcg_const_i32(0);
5350 /* TODO: Raise BSUN exception. */
5351 fpsr
= tcg_temp_new();
5352 gen_load_fcr(s
, fpsr
, M68K_FPSR
);
5355 case 16: /* Signaling False */
5357 c
->tcond
= TCG_COND_NEVER
;
5359 case 1: /* EQual Z */
5360 case 17: /* Signaling EQual Z */
5361 c
->v1
= tcg_temp_new();
5363 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5364 c
->tcond
= TCG_COND_NE
;
5366 case 2: /* Ordered Greater Than !(A || Z || N) */
5367 case 18: /* Greater Than !(A || Z || N) */
5368 c
->v1
= tcg_temp_new();
5370 tcg_gen_andi_i32(c
->v1
, fpsr
,
5371 FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5372 c
->tcond
= TCG_COND_EQ
;
5374 case 3: /* Ordered Greater than or Equal Z || !(A || N) */
5375 case 19: /* Greater than or Equal Z || !(A || N) */
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_andi_i32(fpsr
, fpsr
, FPSR_CC_Z
| FPSR_CC_N
);
5381 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5382 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5383 c
->tcond
= TCG_COND_NE
;
5385 case 4: /* Ordered Less Than !(!N || A || Z); */
5386 case 20: /* Less Than !(!N || A || Z); */
5387 c
->v1
= tcg_temp_new();
5389 tcg_gen_xori_i32(c
->v1
, fpsr
, FPSR_CC_N
);
5390 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_N
| FPSR_CC_A
| FPSR_CC_Z
);
5391 c
->tcond
= TCG_COND_EQ
;
5393 case 5: /* Ordered Less than or Equal Z || (N && !A) */
5394 case 21: /* Less than or Equal Z || (N && !A) */
5395 c
->v1
= tcg_temp_new();
5397 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5398 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
5399 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5400 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_Z
| FPSR_CC_N
);
5401 c
->tcond
= TCG_COND_NE
;
5403 case 6: /* Ordered Greater or Less than !(A || Z) */
5404 case 22: /* Greater or Less than !(A || Z) */
5405 c
->v1
= tcg_temp_new();
5407 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
5408 c
->tcond
= TCG_COND_EQ
;
5410 case 7: /* Ordered !A */
5411 case 23: /* Greater, Less or Equal !A */
5412 c
->v1
= tcg_temp_new();
5414 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5415 c
->tcond
= TCG_COND_EQ
;
5417 case 8: /* Unordered A */
5418 case 24: /* Not Greater, Less or Equal A */
5419 c
->v1
= tcg_temp_new();
5421 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5422 c
->tcond
= TCG_COND_NE
;
5424 case 9: /* Unordered or Equal A || Z */
5425 case 25: /* Not Greater or Less then A || Z */
5426 c
->v1
= tcg_temp_new();
5428 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
5429 c
->tcond
= TCG_COND_NE
;
5431 case 10: /* Unordered or Greater Than A || !(N || Z)) */
5432 case 26: /* Not Less 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_andi_i32(fpsr
, fpsr
, FPSR_CC_A
| FPSR_CC_N
);
5438 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5439 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5440 c
->tcond
= TCG_COND_NE
;
5442 case 11: /* Unordered or Greater or Equal A || Z || !N */
5443 case 27: /* Not Less Than A || Z || !N */
5444 c
->v1
= tcg_temp_new();
5446 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5447 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5448 c
->tcond
= TCG_COND_NE
;
5450 case 12: /* Unordered or Less Than A || (N && !Z) */
5451 case 28: /* Not Greater than or Equal A || (N && !Z) */
5452 c
->v1
= tcg_temp_new();
5454 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5455 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
5456 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5457 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_A
| FPSR_CC_N
);
5458 c
->tcond
= TCG_COND_NE
;
5460 case 13: /* Unordered or Less or Equal A || Z || N */
5461 case 29: /* Not Greater Than A || Z || N */
5462 c
->v1
= tcg_temp_new();
5464 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
5465 c
->tcond
= TCG_COND_NE
;
5467 case 14: /* Not Equal !Z */
5468 case 30: /* Signaling Not Equal !Z */
5469 c
->v1
= tcg_temp_new();
5471 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5472 c
->tcond
= TCG_COND_EQ
;
5475 case 31: /* Signaling True */
5477 c
->tcond
= TCG_COND_ALWAYS
;
5480 tcg_temp_free(fpsr
);
5483 static void gen_fjmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
5487 gen_fcc_cond(&c
, s
, cond
);
5489 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
5500 offset
= (int16_t)read_im16(env
, s
);
5501 if (insn
& (1 << 6)) {
5502 offset
= (offset
<< 16) | read_im16(env
, s
);
5505 l1
= gen_new_label();
5507 gen_fjmpcc(s
, insn
& 0x3f, l1
);
5508 gen_jmp_tb(s
, 0, s
->pc
);
5510 gen_jmp_tb(s
, 1, base
+ offset
);
5520 ext
= read_im16(env
, s
);
5522 gen_fcc_cond(&c
, s
, cond
);
5524 tmp
= tcg_temp_new();
5525 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
5528 tcg_gen_neg_i32(tmp
, tmp
);
5529 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
5533 #if defined(CONFIG_SOFTMMU)
5534 DISAS_INSN(frestore
)
5539 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5542 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5543 SRC_EA(env
, addr
, OS_LONG
, 0, NULL
);
5544 /* FIXME: check the state frame */
5546 disas_undef(env
, s
, insn
);
5553 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5557 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5558 /* always write IDLE */
5559 TCGv idle
= tcg_const_i32(0x41000000);
5560 DEST_EA(env
, insn
, OS_LONG
, idle
, NULL
);
5561 tcg_temp_free(idle
);
5563 disas_undef(env
, s
, insn
);
5568 static inline TCGv
gen_mac_extract_word(DisasContext
*s
, TCGv val
, int upper
)
5570 TCGv tmp
= tcg_temp_new();
5571 if (s
->env
->macsr
& MACSR_FI
) {
5573 tcg_gen_andi_i32(tmp
, val
, 0xffff0000);
5575 tcg_gen_shli_i32(tmp
, val
, 16);
5576 } else if (s
->env
->macsr
& MACSR_SU
) {
5578 tcg_gen_sari_i32(tmp
, val
, 16);
5580 tcg_gen_ext16s_i32(tmp
, val
);
5583 tcg_gen_shri_i32(tmp
, val
, 16);
5585 tcg_gen_ext16u_i32(tmp
, val
);
5590 static void gen_mac_clear_flags(void)
5592 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
,
5593 ~(MACSR_V
| MACSR_Z
| MACSR_N
| MACSR_EV
));
5609 s
->mactmp
= tcg_temp_new_i64();
5613 ext
= read_im16(env
, s
);
5615 acc
= ((insn
>> 7) & 1) | ((ext
>> 3) & 2);
5616 dual
= ((insn
& 0x30) != 0 && (ext
& 3) != 0);
5617 if (dual
&& !m68k_feature(s
->env
, M68K_FEATURE_CF_EMAC_B
)) {
5618 disas_undef(env
, s
, insn
);
5622 /* MAC with load. */
5623 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
5624 addr
= tcg_temp_new();
5625 tcg_gen_and_i32(addr
, tmp
, QREG_MAC_MASK
);
5627 * Load the value now to ensure correct exception behavior.
5628 * Perform writeback after reading the MAC inputs.
5630 loadval
= gen_load(s
, OS_LONG
, addr
, 0, IS_USER(s
));
5633 rx
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(insn
, 12);
5634 ry
= (ext
& 8) ? AREG(ext
, 0) : DREG(ext
, 0);
5636 loadval
= addr
= NULL_QREG
;
5637 rx
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5638 ry
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5641 gen_mac_clear_flags();
5644 /* Disabled because conditional branches clobber temporary vars. */
5645 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && !dual
) {
5646 /* Skip the multiply if we know we will ignore it. */
5647 l1
= gen_new_label();
5648 tmp
= tcg_temp_new();
5649 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 1 << (acc
+ 8));
5650 gen_op_jmp_nz32(tmp
, l1
);
5654 if ((ext
& 0x0800) == 0) {
5656 rx
= gen_mac_extract_word(s
, rx
, (ext
& 0x80) != 0);
5657 ry
= gen_mac_extract_word(s
, ry
, (ext
& 0x40) != 0);
5659 if (s
->env
->macsr
& MACSR_FI
) {
5660 gen_helper_macmulf(s
->mactmp
, cpu_env
, rx
, ry
);
5662 if (s
->env
->macsr
& MACSR_SU
)
5663 gen_helper_macmuls(s
->mactmp
, cpu_env
, rx
, ry
);
5665 gen_helper_macmulu(s
->mactmp
, cpu_env
, rx
, ry
);
5666 switch ((ext
>> 9) & 3) {
5668 tcg_gen_shli_i64(s
->mactmp
, s
->mactmp
, 1);
5671 tcg_gen_shri_i64(s
->mactmp
, s
->mactmp
, 1);
5677 /* Save the overflow flag from the multiply. */
5678 saved_flags
= tcg_temp_new();
5679 tcg_gen_mov_i32(saved_flags
, QREG_MACSR
);
5681 saved_flags
= NULL_QREG
;
5685 /* Disabled because conditional branches clobber temporary vars. */
5686 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && dual
) {
5687 /* Skip the accumulate if the value is already saturated. */
5688 l1
= gen_new_label();
5689 tmp
= tcg_temp_new();
5690 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
5691 gen_op_jmp_nz32(tmp
, l1
);
5696 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5698 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5700 if (s
->env
->macsr
& MACSR_FI
)
5701 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
5702 else if (s
->env
->macsr
& MACSR_SU
)
5703 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
5705 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
5708 /* Disabled because conditional branches clobber temporary vars. */
5714 /* Dual accumulate variant. */
5715 acc
= (ext
>> 2) & 3;
5716 /* Restore the overflow flag from the multiplier. */
5717 tcg_gen_mov_i32(QREG_MACSR
, saved_flags
);
5719 /* Disabled because conditional branches clobber temporary vars. */
5720 if ((s
->env
->macsr
& MACSR_OMC
) != 0) {
5721 /* Skip the accumulate if the value is already saturated. */
5722 l1
= gen_new_label();
5723 tmp
= tcg_temp_new();
5724 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
5725 gen_op_jmp_nz32(tmp
, l1
);
5729 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5731 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5732 if (s
->env
->macsr
& MACSR_FI
)
5733 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
5734 else if (s
->env
->macsr
& MACSR_SU
)
5735 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
5737 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
5739 /* Disabled because conditional branches clobber temporary vars. */
5744 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(acc
));
5748 rw
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5749 tcg_gen_mov_i32(rw
, loadval
);
5751 * FIXME: Should address writeback happen with the masked or
5754 switch ((insn
>> 3) & 7) {
5755 case 3: /* Post-increment. */
5756 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 4);
5758 case 4: /* Pre-decrement. */
5759 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5761 tcg_temp_free(loadval
);
5765 DISAS_INSN(from_mac
)
5771 rx
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5772 accnum
= (insn
>> 9) & 3;
5773 acc
= MACREG(accnum
);
5774 if (s
->env
->macsr
& MACSR_FI
) {
5775 gen_helper_get_macf(rx
, cpu_env
, acc
);
5776 } else if ((s
->env
->macsr
& MACSR_OMC
) == 0) {
5777 tcg_gen_extrl_i64_i32(rx
, acc
);
5778 } else if (s
->env
->macsr
& MACSR_SU
) {
5779 gen_helper_get_macs(rx
, acc
);
5781 gen_helper_get_macu(rx
, acc
);
5784 tcg_gen_movi_i64(acc
, 0);
5785 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5789 DISAS_INSN(move_mac
)
5791 /* FIXME: This can be done without a helper. */
5795 dest
= tcg_const_i32((insn
>> 9) & 3);
5796 gen_helper_mac_move(cpu_env
, dest
, tcg_const_i32(src
));
5797 gen_mac_clear_flags();
5798 gen_helper_mac_set_flags(cpu_env
, dest
);
5801 DISAS_INSN(from_macsr
)
5805 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5806 tcg_gen_mov_i32(reg
, QREG_MACSR
);
5809 DISAS_INSN(from_mask
)
5812 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5813 tcg_gen_mov_i32(reg
, QREG_MAC_MASK
);
5816 DISAS_INSN(from_mext
)
5820 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5821 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
5822 if (s
->env
->macsr
& MACSR_FI
)
5823 gen_helper_get_mac_extf(reg
, cpu_env
, acc
);
5825 gen_helper_get_mac_exti(reg
, cpu_env
, acc
);
5828 DISAS_INSN(macsr_to_ccr
)
5830 TCGv tmp
= tcg_temp_new();
5831 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 0xf);
5832 gen_helper_set_sr(cpu_env
, tmp
);
5834 set_cc_op(s
, CC_OP_FLAGS
);
5842 accnum
= (insn
>> 9) & 3;
5843 acc
= MACREG(accnum
);
5844 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5845 if (s
->env
->macsr
& MACSR_FI
) {
5846 tcg_gen_ext_i32_i64(acc
, val
);
5847 tcg_gen_shli_i64(acc
, acc
, 8);
5848 } else if (s
->env
->macsr
& MACSR_SU
) {
5849 tcg_gen_ext_i32_i64(acc
, val
);
5851 tcg_gen_extu_i32_i64(acc
, val
);
5853 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5854 gen_mac_clear_flags();
5855 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(accnum
));
5858 DISAS_INSN(to_macsr
)
5861 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5862 gen_helper_set_macsr(cpu_env
, val
);
5869 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5870 tcg_gen_ori_i32(QREG_MAC_MASK
, val
, 0xffff0000);
5877 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5878 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
5879 if (s
->env
->macsr
& MACSR_FI
)
5880 gen_helper_set_mac_extf(cpu_env
, val
, acc
);
5881 else if (s
->env
->macsr
& MACSR_SU
)
5882 gen_helper_set_mac_exts(cpu_env
, val
, acc
);
5884 gen_helper_set_mac_extu(cpu_env
, val
, acc
);
5887 static disas_proc opcode_table
[65536];
5890 register_opcode (disas_proc proc
, uint16_t opcode
, uint16_t mask
)
5896 /* Sanity check. All set bits must be included in the mask. */
5897 if (opcode
& ~mask
) {
5899 "qemu internal error: bogus opcode definition %04x/%04x\n",
5904 * This could probably be cleverer. For now just optimize the case where
5905 * the top bits are known.
5907 /* Find the first zero bit in the mask. */
5909 while ((i
& mask
) != 0)
5911 /* Iterate over all combinations of this and lower bits. */
5916 from
= opcode
& ~(i
- 1);
5918 for (i
= from
; i
< to
; i
++) {
5919 if ((i
& mask
) == opcode
)
5920 opcode_table
[i
] = proc
;
5925 * Register m68k opcode handlers. Order is important.
5926 * Later insn override earlier ones.
5928 void register_m68k_insns (CPUM68KState
*env
)
5931 * Build the opcode table only once to avoid
5932 * multithreading issues.
5934 if (opcode_table
[0] != NULL
) {
5939 * use BASE() for instruction available
5940 * for CF_ISA_A and M68000.
5942 #define BASE(name, opcode, mask) \
5943 register_opcode(disas_##name, 0x##opcode, 0x##mask)
5944 #define INSN(name, opcode, mask, feature) do { \
5945 if (m68k_feature(env, M68K_FEATURE_##feature)) \
5946 BASE(name, opcode, mask); \
5948 BASE(undef
, 0000, 0000);
5949 INSN(arith_im
, 0080, fff8
, CF_ISA_A
);
5950 INSN(arith_im
, 0000, ff00
, M68000
);
5951 INSN(chk2
, 00c0
, f9c0
, CHK2
);
5952 INSN(bitrev
, 00c0
, fff8
, CF_ISA_APLUSC
);
5953 BASE(bitop_reg
, 0100, f1c0
);
5954 BASE(bitop_reg
, 0140, f1c0
);
5955 BASE(bitop_reg
, 0180, f1c0
);
5956 BASE(bitop_reg
, 01c0
, f1c0
);
5957 INSN(movep
, 0108, f138
, MOVEP
);
5958 INSN(arith_im
, 0280, fff8
, CF_ISA_A
);
5959 INSN(arith_im
, 0200, ff00
, M68000
);
5960 INSN(undef
, 02c0
, ffc0
, M68000
);
5961 INSN(byterev
, 02c0
, fff8
, CF_ISA_APLUSC
);
5962 INSN(arith_im
, 0480, fff8
, CF_ISA_A
);
5963 INSN(arith_im
, 0400, ff00
, M68000
);
5964 INSN(undef
, 04c0
, ffc0
, M68000
);
5965 INSN(arith_im
, 0600, ff00
, M68000
);
5966 INSN(undef
, 06c0
, ffc0
, M68000
);
5967 INSN(ff1
, 04c0
, fff8
, CF_ISA_APLUSC
);
5968 INSN(arith_im
, 0680, fff8
, CF_ISA_A
);
5969 INSN(arith_im
, 0c00
, ff38
, CF_ISA_A
);
5970 INSN(arith_im
, 0c00
, ff00
, M68000
);
5971 BASE(bitop_im
, 0800, ffc0
);
5972 BASE(bitop_im
, 0840, ffc0
);
5973 BASE(bitop_im
, 0880, ffc0
);
5974 BASE(bitop_im
, 08c0
, ffc0
);
5975 INSN(arith_im
, 0a80
, fff8
, CF_ISA_A
);
5976 INSN(arith_im
, 0a00
, ff00
, M68000
);
5977 #if defined(CONFIG_SOFTMMU)
5978 INSN(moves
, 0e00
, ff00
, M68000
);
5980 INSN(cas
, 0ac0
, ffc0
, CAS
);
5981 INSN(cas
, 0cc0
, ffc0
, CAS
);
5982 INSN(cas
, 0ec0
, ffc0
, CAS
);
5983 INSN(cas2w
, 0cfc
, ffff
, CAS
);
5984 INSN(cas2l
, 0efc
, ffff
, CAS
);
5985 BASE(move
, 1000, f000
);
5986 BASE(move
, 2000, f000
);
5987 BASE(move
, 3000, f000
);
5988 INSN(chk
, 4000, f040
, M68000
);
5989 INSN(strldsr
, 40e7
, ffff
, CF_ISA_APLUSC
);
5990 INSN(negx
, 4080, fff8
, CF_ISA_A
);
5991 INSN(negx
, 4000, ff00
, M68000
);
5992 INSN(undef
, 40c0
, ffc0
, M68000
);
5993 INSN(move_from_sr
, 40c0
, fff8
, CF_ISA_A
);
5994 INSN(move_from_sr
, 40c0
, ffc0
, M68000
);
5995 BASE(lea
, 41c0
, f1c0
);
5996 BASE(clr
, 4200, ff00
);
5997 BASE(undef
, 42c0
, ffc0
);
5998 INSN(move_from_ccr
, 42c0
, fff8
, CF_ISA_A
);
5999 INSN(move_from_ccr
, 42c0
, ffc0
, M68000
);
6000 INSN(neg
, 4480, fff8
, CF_ISA_A
);
6001 INSN(neg
, 4400, ff00
, M68000
);
6002 INSN(undef
, 44c0
, ffc0
, M68000
);
6003 BASE(move_to_ccr
, 44c0
, ffc0
);
6004 INSN(not, 4680, fff8
, CF_ISA_A
);
6005 INSN(not, 4600, ff00
, M68000
);
6006 #if defined(CONFIG_SOFTMMU)
6007 BASE(move_to_sr
, 46c0
, ffc0
);
6009 INSN(nbcd
, 4800, ffc0
, M68000
);
6010 INSN(linkl
, 4808, fff8
, M68000
);
6011 BASE(pea
, 4840, ffc0
);
6012 BASE(swap
, 4840, fff8
);
6013 INSN(bkpt
, 4848, fff8
, BKPT
);
6014 INSN(movem
, 48d0
, fbf8
, CF_ISA_A
);
6015 INSN(movem
, 48e8
, fbf8
, CF_ISA_A
);
6016 INSN(movem
, 4880, fb80
, M68000
);
6017 BASE(ext
, 4880, fff8
);
6018 BASE(ext
, 48c0
, fff8
);
6019 BASE(ext
, 49c0
, fff8
);
6020 BASE(tst
, 4a00
, ff00
);
6021 INSN(tas
, 4ac0
, ffc0
, CF_ISA_B
);
6022 INSN(tas
, 4ac0
, ffc0
, M68000
);
6023 #if defined(CONFIG_SOFTMMU)
6024 INSN(halt
, 4ac8
, ffff
, CF_ISA_A
);
6026 INSN(pulse
, 4acc
, ffff
, CF_ISA_A
);
6027 BASE(illegal
, 4afc
, ffff
);
6028 INSN(mull
, 4c00
, ffc0
, CF_ISA_A
);
6029 INSN(mull
, 4c00
, ffc0
, LONG_MULDIV
);
6030 INSN(divl
, 4c40
, ffc0
, CF_ISA_A
);
6031 INSN(divl
, 4c40
, ffc0
, LONG_MULDIV
);
6032 INSN(sats
, 4c80
, fff8
, CF_ISA_B
);
6033 BASE(trap
, 4e40
, fff0
);
6034 BASE(link
, 4e50
, fff8
);
6035 BASE(unlk
, 4e58
, fff8
);
6036 #if defined(CONFIG_SOFTMMU)
6037 INSN(move_to_usp
, 4e60
, fff8
, USP
);
6038 INSN(move_from_usp
, 4e68
, fff8
, USP
);
6039 INSN(reset
, 4e70
, ffff
, M68000
);
6040 BASE(stop
, 4e72
, ffff
);
6041 BASE(rte
, 4e73
, ffff
);
6042 INSN(cf_movec
, 4e7b
, ffff
, CF_ISA_A
);
6043 INSN(m68k_movec
, 4e7a
, fffe
, MOVEC
);
6045 BASE(nop
, 4e71
, ffff
);
6046 INSN(rtd
, 4e74
, ffff
, RTD
);
6047 BASE(rts
, 4e75
, ffff
);
6048 INSN(rtr
, 4e77
, ffff
, M68000
);
6049 BASE(jump
, 4e80
, ffc0
);
6050 BASE(jump
, 4ec0
, ffc0
);
6051 INSN(addsubq
, 5000, f080
, M68000
);
6052 BASE(addsubq
, 5080, f0c0
);
6053 INSN(scc
, 50c0
, f0f8
, CF_ISA_A
); /* Scc.B Dx */
6054 INSN(scc
, 50c0
, f0c0
, M68000
); /* Scc.B <EA> */
6055 INSN(dbcc
, 50c8
, f0f8
, M68000
);
6056 INSN(tpf
, 51f8
, fff8
, CF_ISA_A
);
6058 /* Branch instructions. */
6059 BASE(branch
, 6000, f000
);
6060 /* Disable long branch instructions, then add back the ones we want. */
6061 BASE(undef
, 60ff
, f0ff
); /* All long branches. */
6062 INSN(branch
, 60ff
, f0ff
, CF_ISA_B
);
6063 INSN(undef
, 60ff
, ffff
, CF_ISA_B
); /* bra.l */
6064 INSN(branch
, 60ff
, ffff
, BRAL
);
6065 INSN(branch
, 60ff
, f0ff
, BCCL
);
6067 BASE(moveq
, 7000, f100
);
6068 INSN(mvzs
, 7100, f100
, CF_ISA_B
);
6069 BASE(or, 8000, f000
);
6070 BASE(divw
, 80c0
, f0c0
);
6071 INSN(sbcd_reg
, 8100, f1f8
, M68000
);
6072 INSN(sbcd_mem
, 8108, f1f8
, M68000
);
6073 BASE(addsub
, 9000, f000
);
6074 INSN(undef
, 90c0
, f0c0
, CF_ISA_A
);
6075 INSN(subx_reg
, 9180, f1f8
, CF_ISA_A
);
6076 INSN(subx_reg
, 9100, f138
, M68000
);
6077 INSN(subx_mem
, 9108, f138
, M68000
);
6078 INSN(suba
, 91c0
, f1c0
, CF_ISA_A
);
6079 INSN(suba
, 90c0
, f0c0
, M68000
);
6081 BASE(undef_mac
, a000
, f000
);
6082 INSN(mac
, a000
, f100
, CF_EMAC
);
6083 INSN(from_mac
, a180
, f9b0
, CF_EMAC
);
6084 INSN(move_mac
, a110
, f9fc
, CF_EMAC
);
6085 INSN(from_macsr
,a980
, f9f0
, CF_EMAC
);
6086 INSN(from_mask
, ad80
, fff0
, CF_EMAC
);
6087 INSN(from_mext
, ab80
, fbf0
, CF_EMAC
);
6088 INSN(macsr_to_ccr
, a9c0
, ffff
, CF_EMAC
);
6089 INSN(to_mac
, a100
, f9c0
, CF_EMAC
);
6090 INSN(to_macsr
, a900
, ffc0
, CF_EMAC
);
6091 INSN(to_mext
, ab00
, fbc0
, CF_EMAC
);
6092 INSN(to_mask
, ad00
, ffc0
, CF_EMAC
);
6094 INSN(mov3q
, a140
, f1c0
, CF_ISA_B
);
6095 INSN(cmp
, b000
, f1c0
, CF_ISA_B
); /* cmp.b */
6096 INSN(cmp
, b040
, f1c0
, CF_ISA_B
); /* cmp.w */
6097 INSN(cmpa
, b0c0
, f1c0
, CF_ISA_B
); /* cmpa.w */
6098 INSN(cmp
, b080
, f1c0
, CF_ISA_A
);
6099 INSN(cmpa
, b1c0
, f1c0
, CF_ISA_A
);
6100 INSN(cmp
, b000
, f100
, M68000
);
6101 INSN(eor
, b100
, f100
, M68000
);
6102 INSN(cmpm
, b108
, f138
, M68000
);
6103 INSN(cmpa
, b0c0
, f0c0
, M68000
);
6104 INSN(eor
, b180
, f1c0
, CF_ISA_A
);
6105 BASE(and, c000
, f000
);
6106 INSN(exg_dd
, c140
, f1f8
, M68000
);
6107 INSN(exg_aa
, c148
, f1f8
, M68000
);
6108 INSN(exg_da
, c188
, f1f8
, M68000
);
6109 BASE(mulw
, c0c0
, f0c0
);
6110 INSN(abcd_reg
, c100
, f1f8
, M68000
);
6111 INSN(abcd_mem
, c108
, f1f8
, M68000
);
6112 BASE(addsub
, d000
, f000
);
6113 INSN(undef
, d0c0
, f0c0
, CF_ISA_A
);
6114 INSN(addx_reg
, d180
, f1f8
, CF_ISA_A
);
6115 INSN(addx_reg
, d100
, f138
, M68000
);
6116 INSN(addx_mem
, d108
, f138
, M68000
);
6117 INSN(adda
, d1c0
, f1c0
, CF_ISA_A
);
6118 INSN(adda
, d0c0
, f0c0
, M68000
);
6119 INSN(shift_im
, e080
, f0f0
, CF_ISA_A
);
6120 INSN(shift_reg
, e0a0
, f0f0
, CF_ISA_A
);
6121 INSN(shift8_im
, e000
, f0f0
, M68000
);
6122 INSN(shift16_im
, e040
, f0f0
, M68000
);
6123 INSN(shift_im
, e080
, f0f0
, M68000
);
6124 INSN(shift8_reg
, e020
, f0f0
, M68000
);
6125 INSN(shift16_reg
, e060
, f0f0
, M68000
);
6126 INSN(shift_reg
, e0a0
, f0f0
, M68000
);
6127 INSN(shift_mem
, e0c0
, fcc0
, M68000
);
6128 INSN(rotate_im
, e090
, f0f0
, M68000
);
6129 INSN(rotate8_im
, e010
, f0f0
, M68000
);
6130 INSN(rotate16_im
, e050
, f0f0
, M68000
);
6131 INSN(rotate_reg
, e0b0
, f0f0
, M68000
);
6132 INSN(rotate8_reg
, e030
, f0f0
, M68000
);
6133 INSN(rotate16_reg
, e070
, f0f0
, M68000
);
6134 INSN(rotate_mem
, e4c0
, fcc0
, M68000
);
6135 INSN(bfext_mem
, e9c0
, fdc0
, BITFIELD
); /* bfextu & bfexts */
6136 INSN(bfext_reg
, e9c0
, fdf8
, BITFIELD
);
6137 INSN(bfins_mem
, efc0
, ffc0
, BITFIELD
);
6138 INSN(bfins_reg
, efc0
, fff8
, BITFIELD
);
6139 INSN(bfop_mem
, eac0
, ffc0
, BITFIELD
); /* bfchg */
6140 INSN(bfop_reg
, eac0
, fff8
, BITFIELD
); /* bfchg */
6141 INSN(bfop_mem
, ecc0
, ffc0
, BITFIELD
); /* bfclr */
6142 INSN(bfop_reg
, ecc0
, fff8
, BITFIELD
); /* bfclr */
6143 INSN(bfop_mem
, edc0
, ffc0
, BITFIELD
); /* bfffo */
6144 INSN(bfop_reg
, edc0
, fff8
, BITFIELD
); /* bfffo */
6145 INSN(bfop_mem
, eec0
, ffc0
, BITFIELD
); /* bfset */
6146 INSN(bfop_reg
, eec0
, fff8
, BITFIELD
); /* bfset */
6147 INSN(bfop_mem
, e8c0
, ffc0
, BITFIELD
); /* bftst */
6148 INSN(bfop_reg
, e8c0
, fff8
, BITFIELD
); /* bftst */
6149 BASE(undef_fpu
, f000
, f000
);
6150 INSN(fpu
, f200
, ffc0
, CF_FPU
);
6151 INSN(fbcc
, f280
, ffc0
, CF_FPU
);
6152 INSN(fpu
, f200
, ffc0
, FPU
);
6153 INSN(fscc
, f240
, ffc0
, FPU
);
6154 INSN(fbcc
, f280
, ff80
, FPU
);
6155 #if defined(CONFIG_SOFTMMU)
6156 INSN(frestore
, f340
, ffc0
, CF_FPU
);
6157 INSN(fsave
, f300
, ffc0
, CF_FPU
);
6158 INSN(frestore
, f340
, ffc0
, FPU
);
6159 INSN(fsave
, f300
, ffc0
, FPU
);
6160 INSN(intouch
, f340
, ffc0
, CF_ISA_A
);
6161 INSN(cpushl
, f428
, ff38
, CF_ISA_A
);
6162 INSN(cpush
, f420
, ff20
, M68040
);
6163 INSN(cinv
, f400
, ff20
, M68040
);
6164 INSN(pflush
, f500
, ffe0
, M68040
);
6165 INSN(ptest
, f548
, ffd8
, M68040
);
6166 INSN(wddata
, fb00
, ff00
, CF_ISA_A
);
6167 INSN(wdebug
, fbc0
, ffc0
, CF_ISA_A
);
6169 INSN(move16_mem
, f600
, ffe0
, M68040
);
6170 INSN(move16_reg
, f620
, fff8
, M68040
);
6174 static void m68k_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cpu
)
6176 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6177 CPUM68KState
*env
= cpu
->env_ptr
;
6180 dc
->pc
= dc
->base
.pc_first
;
6181 dc
->cc_op
= CC_OP_DYNAMIC
;
6182 dc
->cc_op_synced
= 1;
6184 dc
->writeback_mask
= 0;
6185 init_release_array(dc
);
6188 static void m68k_tr_tb_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6192 static void m68k_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6194 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6195 tcg_gen_insn_start(dc
->base
.pc_next
, dc
->cc_op
);
6198 static bool m68k_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
6199 const CPUBreakpoint
*bp
)
6201 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6203 gen_exception(dc
, dc
->base
.pc_next
, EXCP_DEBUG
);
6205 * The address covered by the breakpoint must be included in
6206 * [tb->pc, tb->pc + tb->size) in order to for it to be
6207 * properly cleared -- thus we increment the PC here so that
6208 * the logic setting tb->size below does the right thing.
6210 dc
->base
.pc_next
+= 2;
6215 static void m68k_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
6217 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6218 CPUM68KState
*env
= cpu
->env_ptr
;
6219 uint16_t insn
= read_im16(env
, dc
);
6221 opcode_table
[insn
](env
, dc
, insn
);
6225 dc
->base
.pc_next
= dc
->pc
;
6227 if (dc
->base
.is_jmp
== DISAS_NEXT
) {
6229 * Stop translation when the next insn might touch a new page.
6230 * This ensures that prefetch aborts at the right place.
6232 * We cannot determine the size of the next insn without
6233 * completely decoding it. However, the maximum insn size
6234 * is 32 bytes, so end if we do not have that much remaining.
6235 * This may produce several small TBs at the end of each page,
6236 * but they will all be linked with goto_tb.
6238 * ??? ColdFire maximum is 4 bytes; MC68000's maximum is also
6239 * smaller than MC68020's.
6241 target_ulong start_page_offset
6242 = dc
->pc
- (dc
->base
.pc_first
& TARGET_PAGE_MASK
);
6244 if (start_page_offset
>= TARGET_PAGE_SIZE
- 32) {
6245 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
6250 static void m68k_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
6252 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6254 switch (dc
->base
.is_jmp
) {
6255 case DISAS_NORETURN
:
6257 case DISAS_TOO_MANY
:
6259 if (is_singlestepping(dc
)) {
6260 tcg_gen_movi_i32(QREG_PC
, dc
->pc
);
6261 gen_raise_exception(EXCP_DEBUG
);
6263 gen_jmp_tb(dc
, 0, dc
->pc
);
6267 /* We updated CC_OP and PC in gen_jmp/gen_jmp_im. */
6268 if (is_singlestepping(dc
)) {
6269 gen_raise_exception(EXCP_DEBUG
);
6271 tcg_gen_lookup_and_goto_ptr();
6276 * We updated CC_OP and PC in gen_exit_tb, but also modified
6277 * other state that may require returning to the main loop.
6279 if (is_singlestepping(dc
)) {
6280 gen_raise_exception(EXCP_DEBUG
);
6282 tcg_gen_exit_tb(NULL
, 0);
6286 g_assert_not_reached();
6290 static void m68k_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cpu
)
6292 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
6293 log_target_disas(cpu
, dcbase
->pc_first
, dcbase
->tb
->size
);
6296 static const TranslatorOps m68k_tr_ops
= {
6297 .init_disas_context
= m68k_tr_init_disas_context
,
6298 .tb_start
= m68k_tr_tb_start
,
6299 .insn_start
= m68k_tr_insn_start
,
6300 .breakpoint_check
= m68k_tr_breakpoint_check
,
6301 .translate_insn
= m68k_tr_translate_insn
,
6302 .tb_stop
= m68k_tr_tb_stop
,
6303 .disas_log
= m68k_tr_disas_log
,
6306 void gen_intermediate_code(CPUState
*cpu
, TranslationBlock
*tb
, int max_insns
)
6309 translator_loop(&m68k_tr_ops
, &dc
.base
, cpu
, tb
, max_insns
);
6312 static double floatx80_to_double(CPUM68KState
*env
, uint16_t high
, uint64_t low
)
6314 floatx80 a
= { .high
= high
, .low
= low
};
6320 u
.f64
= floatx80_to_float64(a
, &env
->fp_status
);
6324 void m68k_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
6326 M68kCPU
*cpu
= M68K_CPU(cs
);
6327 CPUM68KState
*env
= &cpu
->env
;
6330 for (i
= 0; i
< 8; i
++) {
6331 qemu_fprintf(f
, "D%d = %08x A%d = %08x "
6332 "F%d = %04x %016"PRIx64
" (%12g)\n",
6333 i
, env
->dregs
[i
], i
, env
->aregs
[i
],
6334 i
, env
->fregs
[i
].l
.upper
, env
->fregs
[i
].l
.lower
,
6335 floatx80_to_double(env
, env
->fregs
[i
].l
.upper
,
6336 env
->fregs
[i
].l
.lower
));
6338 qemu_fprintf(f
, "PC = %08x ", env
->pc
);
6339 sr
= env
->sr
| cpu_m68k_get_ccr(env
);
6340 qemu_fprintf(f
, "SR = %04x T:%x I:%x %c%c %c%c%c%c%c\n",
6341 sr
, (sr
& SR_T
) >> SR_T_SHIFT
, (sr
& SR_I
) >> SR_I_SHIFT
,
6342 (sr
& SR_S
) ? 'S' : 'U', (sr
& SR_M
) ? '%' : 'I',
6343 (sr
& CCF_X
) ? 'X' : '-', (sr
& CCF_N
) ? 'N' : '-',
6344 (sr
& CCF_Z
) ? 'Z' : '-', (sr
& CCF_V
) ? 'V' : '-',
6345 (sr
& CCF_C
) ? 'C' : '-');
6346 qemu_fprintf(f
, "FPSR = %08x %c%c%c%c ", env
->fpsr
,
6347 (env
->fpsr
& FPSR_CC_A
) ? 'A' : '-',
6348 (env
->fpsr
& FPSR_CC_I
) ? 'I' : '-',
6349 (env
->fpsr
& FPSR_CC_Z
) ? 'Z' : '-',
6350 (env
->fpsr
& FPSR_CC_N
) ? 'N' : '-');
6351 qemu_fprintf(f
, "\n "
6352 "FPCR = %04x ", env
->fpcr
);
6353 switch (env
->fpcr
& FPCR_PREC_MASK
) {
6355 qemu_fprintf(f
, "X ");
6358 qemu_fprintf(f
, "S ");
6361 qemu_fprintf(f
, "D ");
6364 switch (env
->fpcr
& FPCR_RND_MASK
) {
6366 qemu_fprintf(f
, "RN ");
6369 qemu_fprintf(f
, "RZ ");
6372 qemu_fprintf(f
, "RM ");
6375 qemu_fprintf(f
, "RP ");
6378 qemu_fprintf(f
, "\n");
6379 #ifdef CONFIG_SOFTMMU
6380 qemu_fprintf(f
, "%sA7(MSP) = %08x %sA7(USP) = %08x %sA7(ISP) = %08x\n",
6381 env
->current_sp
== M68K_SSP
? "->" : " ", env
->sp
[M68K_SSP
],
6382 env
->current_sp
== M68K_USP
? "->" : " ", env
->sp
[M68K_USP
],
6383 env
->current_sp
== M68K_ISP
? "->" : " ", env
->sp
[M68K_ISP
]);
6384 qemu_fprintf(f
, "VBR = 0x%08x\n", env
->vbr
);
6385 qemu_fprintf(f
, "SFC = %x DFC %x\n", env
->sfc
, env
->dfc
);
6386 qemu_fprintf(f
, "SSW %08x TCR %08x URP %08x SRP %08x\n",
6387 env
->mmu
.ssw
, env
->mmu
.tcr
, env
->mmu
.urp
, env
->mmu
.srp
);
6388 qemu_fprintf(f
, "DTTR0/1: %08x/%08x ITTR0/1: %08x/%08x\n",
6389 env
->mmu
.ttr
[M68K_DTTR0
], env
->mmu
.ttr
[M68K_DTTR1
],
6390 env
->mmu
.ttr
[M68K_ITTR0
], env
->mmu
.ttr
[M68K_ITTR1
]);
6391 qemu_fprintf(f
, "MMUSR %08x, fault at %08x\n",
6392 env
->mmu
.mmusr
, env
->mmu
.ar
);
6396 void restore_state_to_opc(CPUM68KState
*env
, TranslationBlock
*tb
,
6399 int cc_op
= data
[1];
6401 if (cc_op
!= CC_OP_DYNAMIC
) {