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 "exec/exec-all.h"
24 #include "tcg/tcg-op.h"
26 #include "qemu/qemu-print.h"
27 #include "exec/translator.h"
28 #include "exec/helper-proto.h"
29 #include "exec/helper-gen.h"
31 #include "fpu/softfloat.h"
32 #include "semihosting/semihost.h"
34 #define HELPER_H "helper.h"
35 #include "exec/helper-info.c.inc"
38 //#define DEBUG_DISPATCH 1
40 #define DEFO32(name, offset) static TCGv QREG_##name;
41 #define DEFO64(name, offset) static TCGv_i64 QREG_##name;
42 #include "qregs.h.inc"
46 static TCGv_i32 cpu_halted
;
47 static TCGv_i32 cpu_exception_index
;
49 static char cpu_reg_names
[2 * 8 * 3 + 5 * 4];
50 static TCGv cpu_dregs
[8];
51 static TCGv cpu_aregs
[8];
52 static TCGv_i64 cpu_macc
[4];
54 #define REG(insn, pos) (((insn) >> (pos)) & 7)
55 #define DREG(insn, pos) cpu_dregs[REG(insn, pos)]
56 #define AREG(insn, pos) get_areg(s, REG(insn, pos))
57 #define MACREG(acc) cpu_macc[acc]
58 #define QREG_SP get_areg(s, 7)
60 static TCGv NULL_QREG
;
61 #define IS_NULL_QREG(t) (t == NULL_QREG)
62 /* Used to distinguish stores from bad addressing modes. */
63 static TCGv store_dummy
;
65 void m68k_tcg_init(void)
70 #define DEFO32(name, offset) \
71 QREG_##name = tcg_global_mem_new_i32(tcg_env, \
72 offsetof(CPUM68KState, offset), #name);
73 #define DEFO64(name, offset) \
74 QREG_##name = tcg_global_mem_new_i64(tcg_env, \
75 offsetof(CPUM68KState, offset), #name);
76 #include "qregs.h.inc"
80 cpu_halted
= tcg_global_mem_new_i32(tcg_env
,
81 -offsetof(M68kCPU
, env
) +
82 offsetof(CPUState
, halted
), "HALTED");
83 cpu_exception_index
= tcg_global_mem_new_i32(tcg_env
,
84 -offsetof(M68kCPU
, env
) +
85 offsetof(CPUState
, exception_index
),
89 for (i
= 0; i
< 8; i
++) {
91 cpu_dregs
[i
] = tcg_global_mem_new(tcg_env
,
92 offsetof(CPUM68KState
, dregs
[i
]), p
);
95 cpu_aregs
[i
] = tcg_global_mem_new(tcg_env
,
96 offsetof(CPUM68KState
, aregs
[i
]), p
);
99 for (i
= 0; i
< 4; i
++) {
100 sprintf(p
, "ACC%d", i
);
101 cpu_macc
[i
] = tcg_global_mem_new_i64(tcg_env
,
102 offsetof(CPUM68KState
, macc
[i
]), p
);
106 NULL_QREG
= tcg_global_mem_new(tcg_env
, -4, "NULL");
107 store_dummy
= tcg_global_mem_new(tcg_env
, -8, "NULL");
110 /* internal defines */
111 typedef struct DisasContext
{
112 DisasContextBase base
;
115 target_ulong pc_prev
;
116 CCOp cc_op
; /* Current CC operation */
125 static TCGv
get_areg(DisasContext
*s
, unsigned regno
)
127 if (s
->writeback_mask
& (1 << regno
)) {
128 return s
->writeback
[regno
];
130 return cpu_aregs
[regno
];
134 static void delay_set_areg(DisasContext
*s
, unsigned regno
,
135 TCGv val
, bool give_temp
)
137 if (s
->writeback_mask
& (1 << regno
)) {
139 s
->writeback
[regno
] = val
;
141 tcg_gen_mov_i32(s
->writeback
[regno
], val
);
144 s
->writeback_mask
|= 1 << regno
;
146 s
->writeback
[regno
] = val
;
148 TCGv tmp
= tcg_temp_new();
149 s
->writeback
[regno
] = tmp
;
150 tcg_gen_mov_i32(tmp
, val
);
155 static void do_writebacks(DisasContext
*s
)
157 unsigned mask
= s
->writeback_mask
;
159 s
->writeback_mask
= 0;
161 unsigned regno
= ctz32(mask
);
162 tcg_gen_mov_i32(cpu_aregs
[regno
], s
->writeback
[regno
]);
168 /* is_jmp field values */
169 #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
170 #define DISAS_EXIT DISAS_TARGET_1 /* cpu state was modified dynamically */
172 #if defined(CONFIG_USER_ONLY)
175 #define IS_USER(s) (!(s->base.tb->flags & TB_FLAGS_MSR_S))
176 #define SFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_SFC_S) ? \
177 MMU_KERNEL_IDX : MMU_USER_IDX)
178 #define DFC_INDEX(s) ((s->base.tb->flags & TB_FLAGS_DFC_S) ? \
179 MMU_KERNEL_IDX : MMU_USER_IDX)
182 typedef void (*disas_proc
)(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
);
184 #ifdef DEBUG_DISPATCH
185 #define DISAS_INSN(name) \
186 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
188 static void disas_##name(CPUM68KState *env, DisasContext *s, \
191 qemu_log("Dispatch " #name "\n"); \
192 real_disas_##name(env, s, insn); \
194 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
197 #define DISAS_INSN(name) \
198 static void disas_##name(CPUM68KState *env, DisasContext *s, \
202 static const uint8_t cc_op_live
[CC_OP_NB
] = {
203 [CC_OP_DYNAMIC
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
204 [CC_OP_FLAGS
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
205 [CC_OP_ADDB
... CC_OP_ADDL
] = CCF_X
| CCF_N
| CCF_V
,
206 [CC_OP_SUBB
... CC_OP_SUBL
] = CCF_X
| CCF_N
| CCF_V
,
207 [CC_OP_CMPB
... CC_OP_CMPL
] = CCF_X
| CCF_N
| CCF_V
,
208 [CC_OP_LOGIC
] = CCF_X
| CCF_N
211 static void set_cc_op(DisasContext
*s
, CCOp op
)
213 CCOp old_op
= s
->cc_op
;
223 * Discard CC computation that will no longer be used.
224 * Note that X and N are never dead.
226 dead
= cc_op_live
[old_op
] & ~cc_op_live
[op
];
228 tcg_gen_discard_i32(QREG_CC_C
);
231 tcg_gen_discard_i32(QREG_CC_Z
);
234 tcg_gen_discard_i32(QREG_CC_V
);
238 /* Update the CPU env CC_OP state. */
239 static void update_cc_op(DisasContext
*s
)
241 if (!s
->cc_op_synced
) {
243 tcg_gen_movi_i32(QREG_CC_OP
, s
->cc_op
);
247 /* Generate a jump to an immediate address. */
248 static void gen_jmp_im(DisasContext
*s
, uint32_t dest
)
251 tcg_gen_movi_i32(QREG_PC
, dest
);
252 s
->base
.is_jmp
= DISAS_JUMP
;
255 /* Generate a jump to the address in qreg DEST. */
256 static void gen_jmp(DisasContext
*s
, TCGv dest
)
259 tcg_gen_mov_i32(QREG_PC
, dest
);
260 s
->base
.is_jmp
= DISAS_JUMP
;
263 static void gen_raise_exception(int nr
)
265 gen_helper_raise_exception(tcg_env
, tcg_constant_i32(nr
));
268 static void gen_raise_exception_format2(DisasContext
*s
, int nr
,
269 target_ulong this_pc
)
272 * Pass the address of the insn to the exception handler,
273 * for recording in the Format $2 (6-word) stack frame.
274 * Re-use mmu.ar for the purpose, since that's only valid
277 tcg_gen_st_i32(tcg_constant_i32(this_pc
), tcg_env
,
278 offsetof(CPUM68KState
, mmu
.ar
));
279 gen_raise_exception(nr
);
280 s
->base
.is_jmp
= DISAS_NORETURN
;
283 static void gen_exception(DisasContext
*s
, uint32_t dest
, int nr
)
286 tcg_gen_movi_i32(QREG_PC
, dest
);
288 gen_raise_exception(nr
);
290 s
->base
.is_jmp
= DISAS_NORETURN
;
293 static inline void gen_addr_fault(DisasContext
*s
)
295 gen_exception(s
, s
->base
.pc_next
, EXCP_ADDRESS
);
299 * Generate a load from the specified address. Narrow values are
300 * sign extended to full register width.
302 static inline TCGv
gen_load(DisasContext
*s
, int opsize
, TCGv addr
,
305 TCGv tmp
= tcg_temp_new_i32();
311 tcg_gen_qemu_ld_tl(tmp
, addr
, index
,
312 opsize
| (sign
? MO_SIGN
: 0) | MO_TE
);
315 g_assert_not_reached();
320 /* Generate a store. */
321 static inline void gen_store(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
328 tcg_gen_qemu_st_tl(val
, addr
, index
, opsize
| MO_TE
);
331 g_assert_not_reached();
342 * Generate an unsigned load if VAL is 0 a signed load if val is -1,
343 * otherwise generate a store.
345 static TCGv
gen_ldst(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
346 ea_what what
, int index
)
348 if (what
== EA_STORE
) {
349 gen_store(s
, opsize
, addr
, val
, index
);
352 return gen_load(s
, opsize
, addr
, what
== EA_LOADS
, index
);
356 /* Read a 16-bit immediate constant */
357 static inline uint16_t read_im16(CPUM68KState
*env
, DisasContext
*s
)
360 im
= translator_lduw(env
, &s
->base
, s
->pc
);
365 /* Read an 8-bit immediate constant */
366 static inline uint8_t read_im8(CPUM68KState
*env
, DisasContext
*s
)
368 return read_im16(env
, s
);
371 /* Read a 32-bit immediate constant. */
372 static inline uint32_t read_im32(CPUM68KState
*env
, DisasContext
*s
)
375 im
= read_im16(env
, s
) << 16;
376 im
|= 0xffff & read_im16(env
, s
);
380 /* Read a 64-bit immediate constant. */
381 static inline uint64_t read_im64(CPUM68KState
*env
, DisasContext
*s
)
384 im
= (uint64_t)read_im32(env
, s
) << 32;
385 im
|= (uint64_t)read_im32(env
, s
);
389 /* Calculate and address index. */
390 static TCGv
gen_addr_index(DisasContext
*s
, uint16_t ext
, TCGv tmp
)
395 add
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(ext
, 12);
396 if ((ext
& 0x800) == 0) {
397 tcg_gen_ext16s_i32(tmp
, add
);
400 scale
= (ext
>> 9) & 3;
402 tcg_gen_shli_i32(tmp
, add
, scale
);
409 * Handle a base + index + displacement effective address.
410 * A NULL_QREG base means pc-relative.
412 static TCGv
gen_lea_indexed(CPUM68KState
*env
, DisasContext
*s
, TCGv base
)
421 ext
= read_im16(env
, s
);
423 if ((ext
& 0x800) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_WORD_INDEX
))
426 if (m68k_feature(s
->env
, M68K_FEATURE_M68K
) &&
427 !m68k_feature(s
->env
, M68K_FEATURE_SCALED_INDEX
)) {
432 /* full extension word format */
433 if (!m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
))
436 if ((ext
& 0x30) > 0x10) {
437 /* base displacement */
438 if ((ext
& 0x30) == 0x20) {
439 bd
= (int16_t)read_im16(env
, s
);
441 bd
= read_im32(env
, s
);
446 tmp
= tcg_temp_new();
447 if ((ext
& 0x44) == 0) {
449 add
= gen_addr_index(s
, ext
, tmp
);
453 if ((ext
& 0x80) == 0) {
454 /* base not suppressed */
455 if (IS_NULL_QREG(base
)) {
456 base
= tcg_constant_i32(offset
+ bd
);
459 if (!IS_NULL_QREG(add
)) {
460 tcg_gen_add_i32(tmp
, add
, base
);
466 if (!IS_NULL_QREG(add
)) {
468 tcg_gen_addi_i32(tmp
, add
, bd
);
472 add
= tcg_constant_i32(bd
);
474 if ((ext
& 3) != 0) {
475 /* memory indirect */
476 base
= gen_load(s
, OS_LONG
, add
, 0, IS_USER(s
));
477 if ((ext
& 0x44) == 4) {
478 add
= gen_addr_index(s
, ext
, tmp
);
479 tcg_gen_add_i32(tmp
, add
, base
);
485 /* outer displacement */
486 if ((ext
& 3) == 2) {
487 od
= (int16_t)read_im16(env
, s
);
489 od
= read_im32(env
, s
);
495 tcg_gen_addi_i32(tmp
, add
, od
);
500 /* brief extension word format */
501 tmp
= tcg_temp_new();
502 add
= gen_addr_index(s
, ext
, tmp
);
503 if (!IS_NULL_QREG(base
)) {
504 tcg_gen_add_i32(tmp
, add
, base
);
506 tcg_gen_addi_i32(tmp
, tmp
, (int8_t)ext
);
508 tcg_gen_addi_i32(tmp
, add
, offset
+ (int8_t)ext
);
515 /* Sign or zero extend a value. */
517 static inline void gen_ext(TCGv res
, TCGv val
, int opsize
, int sign
)
523 tcg_gen_ext_i32(res
, val
, opsize
| (sign
? MO_SIGN
: 0));
526 g_assert_not_reached();
530 /* Evaluate all the CC flags. */
532 static void gen_flush_flags(DisasContext
*s
)
543 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
544 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
545 /* Compute signed overflow for addition. */
548 tcg_gen_sub_i32(t0
, QREG_CC_N
, QREG_CC_V
);
549 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_ADDB
, 1);
550 tcg_gen_xor_i32(t1
, QREG_CC_N
, QREG_CC_V
);
551 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
552 tcg_gen_andc_i32(QREG_CC_V
, t1
, QREG_CC_V
);
558 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
559 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
560 /* Compute signed overflow for subtraction. */
563 tcg_gen_add_i32(t0
, QREG_CC_N
, QREG_CC_V
);
564 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_SUBB
, 1);
565 tcg_gen_xor_i32(t1
, QREG_CC_N
, t0
);
566 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
567 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t1
);
573 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_C
, QREG_CC_N
, QREG_CC_V
);
574 tcg_gen_sub_i32(QREG_CC_Z
, QREG_CC_N
, QREG_CC_V
);
575 gen_ext(QREG_CC_Z
, QREG_CC_Z
, s
->cc_op
- CC_OP_CMPB
, 1);
576 /* Compute signed overflow for subtraction. */
578 tcg_gen_xor_i32(t0
, QREG_CC_Z
, QREG_CC_N
);
579 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, QREG_CC_N
);
580 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t0
);
581 tcg_gen_mov_i32(QREG_CC_N
, QREG_CC_Z
);
585 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
586 tcg_gen_movi_i32(QREG_CC_C
, 0);
587 tcg_gen_movi_i32(QREG_CC_V
, 0);
591 gen_helper_flush_flags(tcg_env
, QREG_CC_OP
);
596 gen_helper_flush_flags(tcg_env
, tcg_constant_i32(s
->cc_op
));
601 /* Note that flush_flags also assigned to env->cc_op. */
602 s
->cc_op
= CC_OP_FLAGS
;
605 static inline TCGv
gen_extend(DisasContext
*s
, TCGv val
, int opsize
, int sign
)
609 if (opsize
== OS_LONG
) {
612 tmp
= tcg_temp_new();
613 gen_ext(tmp
, val
, opsize
, sign
);
619 static void gen_logic_cc(DisasContext
*s
, TCGv val
, int opsize
)
621 gen_ext(QREG_CC_N
, val
, opsize
, 1);
622 set_cc_op(s
, CC_OP_LOGIC
);
625 static void gen_update_cc_cmp(DisasContext
*s
, TCGv dest
, TCGv src
, int opsize
)
627 tcg_gen_mov_i32(QREG_CC_N
, dest
);
628 tcg_gen_mov_i32(QREG_CC_V
, src
);
629 set_cc_op(s
, CC_OP_CMPB
+ opsize
);
632 static void gen_update_cc_add(TCGv dest
, TCGv src
, int opsize
)
634 gen_ext(QREG_CC_N
, dest
, opsize
, 1);
635 tcg_gen_mov_i32(QREG_CC_V
, src
);
638 static inline int opsize_bytes(int opsize
)
641 case OS_BYTE
: return 1;
642 case OS_WORD
: return 2;
643 case OS_LONG
: return 4;
644 case OS_SINGLE
: return 4;
645 case OS_DOUBLE
: return 8;
646 case OS_EXTENDED
: return 12;
647 case OS_PACKED
: return 12;
649 g_assert_not_reached();
653 static inline int insn_opsize(int insn
)
655 switch ((insn
>> 6) & 3) {
656 case 0: return OS_BYTE
;
657 case 1: return OS_WORD
;
658 case 2: return OS_LONG
;
660 g_assert_not_reached();
664 static inline int ext_opsize(int ext
, int pos
)
666 switch ((ext
>> pos
) & 7) {
667 case 0: return OS_LONG
;
668 case 1: return OS_SINGLE
;
669 case 2: return OS_EXTENDED
;
670 case 3: return OS_PACKED
;
671 case 4: return OS_WORD
;
672 case 5: return OS_DOUBLE
;
673 case 6: return OS_BYTE
;
675 g_assert_not_reached();
680 * Assign value to a register. If the width is less than the register width
681 * only the low part of the register is set.
683 static void gen_partset_reg(int opsize
, TCGv reg
, TCGv val
)
687 tcg_gen_deposit_i32(reg
, reg
, val
, 0, 8);
690 tcg_gen_deposit_i32(reg
, reg
, val
, 0, 16);
694 tcg_gen_mov_i32(reg
, val
);
697 g_assert_not_reached();
702 * Generate code for an "effective address". Does not adjust the base
703 * register for autoincrement addressing modes.
705 static TCGv
gen_lea_mode(CPUM68KState
*env
, DisasContext
*s
,
706 int mode
, int reg0
, int opsize
)
714 case 0: /* Data register direct. */
715 case 1: /* Address register direct. */
717 case 3: /* Indirect postincrement. */
718 if (opsize
== OS_UNSIZED
) {
722 case 2: /* Indirect register */
723 tmp
= tcg_temp_new();
724 tcg_gen_mov_i32(tmp
, get_areg(s
, reg0
));
726 case 4: /* Indirect predecrememnt. */
727 if (opsize
== OS_UNSIZED
) {
730 reg
= get_areg(s
, reg0
);
731 tmp
= tcg_temp_new();
732 if (reg0
== 7 && opsize
== OS_BYTE
&&
733 m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
734 tcg_gen_subi_i32(tmp
, reg
, 2);
736 tcg_gen_subi_i32(tmp
, reg
, opsize_bytes(opsize
));
739 case 5: /* Indirect displacement. */
740 reg
= get_areg(s
, reg0
);
741 tmp
= tcg_temp_new();
742 ext
= read_im16(env
, s
);
743 tcg_gen_addi_i32(tmp
, reg
, (int16_t)ext
);
745 case 6: /* Indirect index + displacement. */
746 reg
= get_areg(s
, reg0
);
747 return gen_lea_indexed(env
, s
, reg
);
750 case 0: /* Absolute short. */
751 offset
= (int16_t)read_im16(env
, s
);
753 case 1: /* Absolute long. */
754 offset
= read_im32(env
, s
);
756 case 2: /* pc displacement */
758 offset
+= (int16_t)read_im16(env
, s
);
760 case 3: /* pc index+displacement. */
761 return gen_lea_indexed(env
, s
, NULL_QREG
);
762 case 4: /* Immediate. */
766 tmp
= tcg_temp_new();
767 tcg_gen_movi_i32(tmp
, offset
);
770 /* Should never happen. */
774 static TCGv
gen_lea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
777 int mode
= extract32(insn
, 3, 3);
778 int reg0
= REG(insn
, 0);
779 return gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
783 * Generate code to load/store a value from/into an EA. If WHAT > 0 this is
784 * a write otherwise it is a read (0 == sign extend, -1 == zero extend).
785 * ADDRP is non-null for readwrite operands.
787 static TCGv
gen_ea_mode(CPUM68KState
*env
, DisasContext
*s
, int mode
, int reg0
,
788 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
,
791 TCGv reg
, tmp
, result
;
795 case 0: /* Data register direct. */
796 reg
= cpu_dregs
[reg0
];
797 if (what
== EA_STORE
) {
798 gen_partset_reg(opsize
, reg
, val
);
801 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
803 case 1: /* Address register direct. */
804 reg
= get_areg(s
, reg0
);
805 if (what
== EA_STORE
) {
806 tcg_gen_mov_i32(reg
, val
);
809 return gen_extend(s
, reg
, opsize
, what
== EA_LOADS
);
811 case 2: /* Indirect register */
812 reg
= get_areg(s
, reg0
);
813 return gen_ldst(s
, opsize
, reg
, val
, what
, index
);
814 case 3: /* Indirect postincrement. */
815 reg
= get_areg(s
, reg0
);
816 result
= gen_ldst(s
, opsize
, reg
, val
, what
, index
);
817 if (what
== EA_STORE
|| !addrp
) {
818 tmp
= tcg_temp_new();
819 if (reg0
== 7 && opsize
== OS_BYTE
&&
820 m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
821 tcg_gen_addi_i32(tmp
, reg
, 2);
823 tcg_gen_addi_i32(tmp
, reg
, opsize_bytes(opsize
));
825 delay_set_areg(s
, reg0
, tmp
, true);
828 case 4: /* Indirect predecrememnt. */
829 if (addrp
&& what
== EA_STORE
) {
832 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
833 if (IS_NULL_QREG(tmp
)) {
840 result
= gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
841 if (what
== EA_STORE
|| !addrp
) {
842 delay_set_areg(s
, reg0
, tmp
, false);
845 case 5: /* Indirect displacement. */
846 case 6: /* Indirect index + displacement. */
848 if (addrp
&& what
== EA_STORE
) {
851 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
852 if (IS_NULL_QREG(tmp
)) {
859 return gen_ldst(s
, opsize
, tmp
, val
, what
, index
);
862 case 0: /* Absolute short. */
863 case 1: /* Absolute long. */
864 case 2: /* pc displacement */
865 case 3: /* pc index+displacement. */
867 case 4: /* Immediate. */
868 /* Sign extend values for consistency. */
871 if (what
== EA_LOADS
) {
872 offset
= (int8_t)read_im8(env
, s
);
874 offset
= read_im8(env
, s
);
878 if (what
== EA_LOADS
) {
879 offset
= (int16_t)read_im16(env
, s
);
881 offset
= read_im16(env
, s
);
885 offset
= read_im32(env
, s
);
888 g_assert_not_reached();
890 return tcg_constant_i32(offset
);
895 /* Should never happen. */
899 static TCGv
gen_ea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
900 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
, int index
)
902 int mode
= extract32(insn
, 3, 3);
903 int reg0
= REG(insn
, 0);
904 return gen_ea_mode(env
, s
, mode
, reg0
, opsize
, val
, addrp
, what
, index
);
907 static TCGv_ptr
gen_fp_ptr(int freg
)
909 TCGv_ptr fp
= tcg_temp_new_ptr();
910 tcg_gen_addi_ptr(fp
, tcg_env
, offsetof(CPUM68KState
, fregs
[freg
]));
914 static TCGv_ptr
gen_fp_result_ptr(void)
916 TCGv_ptr fp
= tcg_temp_new_ptr();
917 tcg_gen_addi_ptr(fp
, tcg_env
, offsetof(CPUM68KState
, fp_result
));
921 static void gen_fp_move(TCGv_ptr dest
, TCGv_ptr src
)
926 t32
= tcg_temp_new();
927 tcg_gen_ld16u_i32(t32
, src
, offsetof(FPReg
, l
.upper
));
928 tcg_gen_st16_i32(t32
, dest
, offsetof(FPReg
, l
.upper
));
930 t64
= tcg_temp_new_i64();
931 tcg_gen_ld_i64(t64
, src
, offsetof(FPReg
, l
.lower
));
932 tcg_gen_st_i64(t64
, dest
, offsetof(FPReg
, l
.lower
));
935 static void gen_load_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
941 t64
= tcg_temp_new_i64();
942 tmp
= tcg_temp_new();
947 tcg_gen_qemu_ld_tl(tmp
, addr
, index
, opsize
| MO_SIGN
| MO_TE
);
948 gen_helper_exts32(tcg_env
, fp
, tmp
);
951 tcg_gen_qemu_ld_tl(tmp
, addr
, index
, MO_TEUL
);
952 gen_helper_extf32(tcg_env
, fp
, tmp
);
955 tcg_gen_qemu_ld_i64(t64
, addr
, index
, MO_TEUQ
);
956 gen_helper_extf64(tcg_env
, fp
, t64
);
959 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
960 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
963 tcg_gen_qemu_ld_i32(tmp
, addr
, index
, MO_TEUL
);
964 tcg_gen_shri_i32(tmp
, tmp
, 16);
965 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
966 tcg_gen_addi_i32(tmp
, addr
, 4);
967 tcg_gen_qemu_ld_i64(t64
, tmp
, index
, MO_TEUQ
);
968 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
972 * unimplemented data type on 68040/ColdFire
973 * FIXME if needed for another FPU
975 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
978 g_assert_not_reached();
982 static void gen_store_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
,
988 t64
= tcg_temp_new_i64();
989 tmp
= tcg_temp_new();
994 gen_helper_reds32(tmp
, tcg_env
, fp
);
995 tcg_gen_qemu_st_tl(tmp
, addr
, index
, opsize
| MO_TE
);
998 gen_helper_redf32(tmp
, tcg_env
, fp
);
999 tcg_gen_qemu_st_tl(tmp
, addr
, index
, MO_TEUL
);
1002 gen_helper_redf64(t64
, tcg_env
, fp
);
1003 tcg_gen_qemu_st_i64(t64
, addr
, index
, MO_TEUQ
);
1006 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1007 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1010 tcg_gen_ld16u_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1011 tcg_gen_shli_i32(tmp
, tmp
, 16);
1012 tcg_gen_qemu_st_i32(tmp
, addr
, index
, MO_TEUL
);
1013 tcg_gen_addi_i32(tmp
, addr
, 4);
1014 tcg_gen_ld_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1015 tcg_gen_qemu_st_i64(t64
, tmp
, index
, MO_TEUQ
);
1019 * unimplemented data type on 68040/ColdFire
1020 * FIXME if needed for another FPU
1022 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1025 g_assert_not_reached();
1029 static void gen_ldst_fp(DisasContext
*s
, int opsize
, TCGv addr
,
1030 TCGv_ptr fp
, ea_what what
, int index
)
1032 if (what
== EA_STORE
) {
1033 gen_store_fp(s
, opsize
, addr
, fp
, index
);
1035 gen_load_fp(s
, opsize
, addr
, fp
, index
);
1039 static int gen_ea_mode_fp(CPUM68KState
*env
, DisasContext
*s
, int mode
,
1040 int reg0
, int opsize
, TCGv_ptr fp
, ea_what what
,
1043 TCGv reg
, addr
, tmp
;
1047 case 0: /* Data register direct. */
1048 reg
= cpu_dregs
[reg0
];
1049 if (what
== EA_STORE
) {
1054 gen_helper_reds32(reg
, tcg_env
, fp
);
1057 gen_helper_redf32(reg
, tcg_env
, fp
);
1060 g_assert_not_reached();
1063 tmp
= tcg_temp_new();
1068 tcg_gen_ext_i32(tmp
, reg
, opsize
| MO_SIGN
);
1069 gen_helper_exts32(tcg_env
, fp
, tmp
);
1072 gen_helper_extf32(tcg_env
, fp
, reg
);
1075 g_assert_not_reached();
1079 case 1: /* Address register direct. */
1081 case 2: /* Indirect register */
1082 addr
= get_areg(s
, reg0
);
1083 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1085 case 3: /* Indirect postincrement. */
1086 addr
= cpu_aregs
[reg0
];
1087 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1088 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(opsize
));
1090 case 4: /* Indirect predecrememnt. */
1091 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1092 if (IS_NULL_QREG(addr
)) {
1095 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1096 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
1098 case 5: /* Indirect displacement. */
1099 case 6: /* Indirect index + displacement. */
1101 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1102 if (IS_NULL_QREG(addr
)) {
1105 gen_ldst_fp(s
, opsize
, addr
, fp
, what
, index
);
1109 case 0: /* Absolute short. */
1110 case 1: /* Absolute long. */
1111 case 2: /* pc displacement */
1112 case 3: /* pc index+displacement. */
1114 case 4: /* Immediate. */
1115 if (what
== EA_STORE
) {
1120 tmp
= tcg_constant_i32((int8_t)read_im8(env
, s
));
1121 gen_helper_exts32(tcg_env
, fp
, tmp
);
1124 tmp
= tcg_constant_i32((int16_t)read_im16(env
, s
));
1125 gen_helper_exts32(tcg_env
, fp
, tmp
);
1128 tmp
= tcg_constant_i32(read_im32(env
, s
));
1129 gen_helper_exts32(tcg_env
, fp
, tmp
);
1132 tmp
= tcg_constant_i32(read_im32(env
, s
));
1133 gen_helper_extf32(tcg_env
, fp
, tmp
);
1136 t64
= tcg_constant_i64(read_im64(env
, s
));
1137 gen_helper_extf64(tcg_env
, fp
, t64
);
1140 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1141 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1144 tmp
= tcg_constant_i32(read_im32(env
, s
) >> 16);
1145 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1146 t64
= tcg_constant_i64(read_im64(env
, s
));
1147 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1151 * unimplemented data type on 68040/ColdFire
1152 * FIXME if needed for another FPU
1154 gen_exception(s
, s
->base
.pc_next
, EXCP_FP_UNIMP
);
1157 g_assert_not_reached();
1167 static int gen_ea_fp(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
1168 int opsize
, TCGv_ptr fp
, ea_what what
, int index
)
1170 int mode
= extract32(insn
, 3, 3);
1171 int reg0
= REG(insn
, 0);
1172 return gen_ea_mode_fp(env
, s
, mode
, reg0
, opsize
, fp
, what
, index
);
1181 static void gen_cc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
1187 /* The CC_OP_CMP form can handle most normal comparisons directly. */
1188 if (op
== CC_OP_CMPB
|| op
== CC_OP_CMPW
|| op
== CC_OP_CMPL
) {
1194 tcond
= TCG_COND_LEU
;
1198 tcond
= TCG_COND_LTU
;
1202 tcond
= TCG_COND_EQ
;
1206 c
->v2
= tcg_constant_i32(0);
1207 c
->v1
= tmp
= tcg_temp_new();
1208 tcg_gen_sub_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1209 gen_ext(tmp
, tmp
, op
- CC_OP_CMPB
, 1);
1213 tcond
= TCG_COND_LT
;
1217 tcond
= TCG_COND_LE
;
1222 c
->v2
= tcg_constant_i32(0);
1228 tcond
= TCG_COND_NEVER
;
1230 case 14: /* GT (!(Z || (N ^ V))) */
1231 case 15: /* LE (Z || (N ^ V)) */
1233 * Logic operations clear V, which simplifies LE to (Z || N),
1234 * and since Z and N are co-located, this becomes a normal
1237 if (op
== CC_OP_LOGIC
) {
1239 tcond
= TCG_COND_LE
;
1243 case 12: /* GE (!(N ^ V)) */
1244 case 13: /* LT (N ^ V) */
1245 /* Logic operations clear V, which simplifies this to N. */
1246 if (op
!= CC_OP_LOGIC
) {
1250 case 10: /* PL (!N) */
1251 case 11: /* MI (N) */
1252 /* Several cases represent N normally. */
1253 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1254 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1255 op
== CC_OP_LOGIC
) {
1257 tcond
= TCG_COND_LT
;
1261 case 6: /* NE (!Z) */
1262 case 7: /* EQ (Z) */
1263 /* Some cases fold Z into N. */
1264 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1265 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1266 op
== CC_OP_LOGIC
) {
1267 tcond
= TCG_COND_EQ
;
1272 case 4: /* CC (!C) */
1273 case 5: /* CS (C) */
1274 /* Some cases fold C into X. */
1275 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1276 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
) {
1277 tcond
= TCG_COND_NE
;
1282 case 8: /* VC (!V) */
1283 case 9: /* VS (V) */
1284 /* Logic operations clear V and C. */
1285 if (op
== CC_OP_LOGIC
) {
1286 tcond
= TCG_COND_NEVER
;
1293 /* Otherwise, flush flag state to CC_OP_FLAGS. */
1300 /* Invalid, or handled above. */
1302 case 2: /* HI (!C && !Z) -> !(C || Z)*/
1303 case 3: /* LS (C || Z) */
1304 c
->v1
= tmp
= tcg_temp_new();
1305 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1306 tcg_gen_or_i32(tmp
, tmp
, QREG_CC_C
);
1307 tcond
= TCG_COND_NE
;
1309 case 4: /* CC (!C) */
1310 case 5: /* CS (C) */
1312 tcond
= TCG_COND_NE
;
1314 case 6: /* NE (!Z) */
1315 case 7: /* EQ (Z) */
1317 tcond
= TCG_COND_EQ
;
1319 case 8: /* VC (!V) */
1320 case 9: /* VS (V) */
1322 tcond
= TCG_COND_LT
;
1324 case 10: /* PL (!N) */
1325 case 11: /* MI (N) */
1327 tcond
= TCG_COND_LT
;
1329 case 12: /* GE (!(N ^ V)) */
1330 case 13: /* LT (N ^ V) */
1331 c
->v1
= tmp
= tcg_temp_new();
1332 tcg_gen_xor_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1333 tcond
= TCG_COND_LT
;
1335 case 14: /* GT (!(Z || (N ^ V))) */
1336 case 15: /* LE (Z || (N ^ V)) */
1337 c
->v1
= tmp
= tcg_temp_new();
1338 tcg_gen_negsetcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1339 tmp2
= tcg_temp_new();
1340 tcg_gen_xor_i32(tmp2
, QREG_CC_N
, QREG_CC_V
);
1341 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1342 tcond
= TCG_COND_LT
;
1347 if ((cond
& 1) == 0) {
1348 tcond
= tcg_invert_cond(tcond
);
1353 static void gen_jmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
1357 gen_cc_cond(&c
, s
, cond
);
1359 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
1362 /* Force a TB lookup after an instruction that changes the CPU state. */
1363 static void gen_exit_tb(DisasContext
*s
)
1366 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
1367 s
->base
.is_jmp
= DISAS_EXIT
;
1370 #define SRC_EA(env, result, opsize, op_sign, addrp) do { \
1371 result = gen_ea(env, s, insn, opsize, NULL_QREG, addrp, \
1372 op_sign ? EA_LOADS : EA_LOADU, IS_USER(s)); \
1373 if (IS_NULL_QREG(result)) { \
1374 gen_addr_fault(s); \
1379 #define DEST_EA(env, insn, opsize, val, addrp) do { \
1380 TCGv ea_result = gen_ea(env, s, insn, opsize, val, addrp, \
1381 EA_STORE, IS_USER(s)); \
1382 if (IS_NULL_QREG(ea_result)) { \
1383 gen_addr_fault(s); \
1388 /* Generate a jump to an immediate address. */
1389 static void gen_jmp_tb(DisasContext
*s
, int n
, target_ulong dest
,
1392 if (unlikely(s
->ss_active
)) {
1394 tcg_gen_movi_i32(QREG_PC
, dest
);
1395 gen_raise_exception_format2(s
, EXCP_TRACE
, src
);
1396 } else if (translator_use_goto_tb(&s
->base
, dest
)) {
1398 tcg_gen_movi_i32(QREG_PC
, dest
);
1399 tcg_gen_exit_tb(s
->base
.tb
, n
);
1401 gen_jmp_im(s
, dest
);
1402 tcg_gen_exit_tb(NULL
, 0);
1404 s
->base
.is_jmp
= DISAS_NORETURN
;
1407 #ifndef CONFIG_USER_ONLY
1408 static bool semihosting_test(DisasContext
*s
)
1412 if (!semihosting_enabled(IS_USER(s
))) {
1417 * "The semihosting instruction is immediately preceded by a
1418 * nop aligned to a 4-byte boundary..."
1419 * The preceding 2-byte (aligned) nop plus the 2-byte halt/bkpt
1420 * means that we have advanced 4 bytes from the required nop.
1422 if (s
->pc
% 4 != 0) {
1425 test
= translator_lduw(s
->env
, &s
->base
, s
->pc
- 4);
1426 if (test
!= 0x4e71) {
1429 /* "... and followed by an invalid sentinel instruction movec %sp,0." */
1430 test
= translator_ldl(s
->env
, &s
->base
, s
->pc
);
1431 if (test
!= 0x4e7bf000) {
1435 /* Consume the sentinel. */
1439 #endif /* !CONFIG_USER_ONLY */
1447 cond
= (insn
>> 8) & 0xf;
1448 gen_cc_cond(&c
, s
, cond
);
1450 tmp
= tcg_temp_new();
1451 tcg_gen_negsetcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
1453 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
1464 reg
= DREG(insn
, 0);
1466 offset
= (int16_t)read_im16(env
, s
);
1467 l1
= gen_new_label();
1468 gen_jmpcc(s
, (insn
>> 8) & 0xf, l1
);
1470 tmp
= tcg_temp_new();
1471 tcg_gen_ext16s_i32(tmp
, reg
);
1472 tcg_gen_addi_i32(tmp
, tmp
, -1);
1473 gen_partset_reg(OS_WORD
, reg
, tmp
);
1474 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, -1, l1
);
1475 gen_jmp_tb(s
, 1, base
+ offset
, s
->base
.pc_next
);
1477 gen_jmp_tb(s
, 0, s
->pc
, s
->base
.pc_next
);
1480 DISAS_INSN(undef_mac
)
1482 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEA
);
1485 DISAS_INSN(undef_fpu
)
1487 gen_exception(s
, s
->base
.pc_next
, EXCP_LINEF
);
1493 * ??? This is both instructions that are as yet unimplemented
1494 * for the 680x0 series, as well as those that are implemented
1495 * but actually illegal for CPU32 or pre-68020.
1497 qemu_log_mask(LOG_UNIMP
, "Illegal instruction: %04x @ %" VADDR_PRIx
"\n",
1498 insn
, s
->base
.pc_next
);
1499 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1509 sign
= (insn
& 0x100) != 0;
1510 reg
= DREG(insn
, 9);
1511 tmp
= tcg_temp_new();
1513 tcg_gen_ext16s_i32(tmp
, reg
);
1515 tcg_gen_ext16u_i32(tmp
, reg
);
1516 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1517 tcg_gen_mul_i32(tmp
, tmp
, src
);
1518 tcg_gen_mov_i32(reg
, tmp
);
1519 gen_logic_cc(s
, tmp
, OS_LONG
);
1529 /* divX.w <EA>,Dn 32/16 -> 16r:16q */
1531 sign
= (insn
& 0x100) != 0;
1533 /* dest.l / src.w */
1535 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1536 destr
= tcg_constant_i32(REG(insn
, 9));
1537 ilen
= tcg_constant_i32(s
->pc
- s
->base
.pc_next
);
1539 gen_helper_divsw(tcg_env
, destr
, src
, ilen
);
1541 gen_helper_divuw(tcg_env
, destr
, src
, ilen
);
1544 set_cc_op(s
, CC_OP_FLAGS
);
1549 TCGv num
, reg
, den
, ilen
;
1553 ext
= read_im16(env
, s
);
1555 sign
= (ext
& 0x0800) != 0;
1558 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
1559 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
1563 /* divX.l <EA>, Dr:Dq 64/32 -> 32r:32q */
1565 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1566 num
= tcg_constant_i32(REG(ext
, 12));
1567 reg
= tcg_constant_i32(REG(ext
, 0));
1568 ilen
= tcg_constant_i32(s
->pc
- s
->base
.pc_next
);
1570 gen_helper_divsll(tcg_env
, num
, reg
, den
, ilen
);
1572 gen_helper_divull(tcg_env
, num
, reg
, den
, ilen
);
1574 set_cc_op(s
, CC_OP_FLAGS
);
1578 /* divX.l <EA>, Dq 32/32 -> 32q */
1579 /* divXl.l <EA>, Dr:Dq 32/32 -> 32r:32q */
1581 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1582 num
= tcg_constant_i32(REG(ext
, 12));
1583 reg
= tcg_constant_i32(REG(ext
, 0));
1584 ilen
= tcg_constant_i32(s
->pc
- s
->base
.pc_next
);
1586 gen_helper_divsl(tcg_env
, num
, reg
, den
, ilen
);
1588 gen_helper_divul(tcg_env
, num
, reg
, den
, ilen
);
1591 set_cc_op(s
, CC_OP_FLAGS
);
1594 static void bcd_add(TCGv dest
, TCGv src
)
1599 * dest10 = dest10 + src10 + X
1603 * t3 = t2 + dest + X
1607 * t7 = (t6 >> 2) | (t6 >> 3)
1612 * t1 = (src + 0x066) + dest + X
1613 * = result with some possible exceeding 0x6
1616 t0
= tcg_temp_new();
1617 tcg_gen_addi_i32(t0
, src
, 0x066);
1619 t1
= tcg_temp_new();
1620 tcg_gen_add_i32(t1
, t0
, dest
);
1621 tcg_gen_add_i32(t1
, t1
, QREG_CC_X
);
1623 /* we will remove exceeding 0x6 where there is no carry */
1626 * t0 = (src + 0x0066) ^ dest
1627 * = t1 without carries
1630 tcg_gen_xor_i32(t0
, t0
, dest
);
1633 * extract the carries
1635 * = only the carries
1638 tcg_gen_xor_i32(t0
, t0
, t1
);
1641 * generate 0x1 where there is no carry
1642 * and for each 0x10, generate a 0x6
1645 tcg_gen_shri_i32(t0
, t0
, 3);
1646 tcg_gen_not_i32(t0
, t0
);
1647 tcg_gen_andi_i32(t0
, t0
, 0x22);
1648 tcg_gen_add_i32(dest
, t0
, t0
);
1649 tcg_gen_add_i32(dest
, dest
, t0
);
1652 * remove the exceeding 0x6
1653 * for digits that have not generated a carry
1656 tcg_gen_sub_i32(dest
, t1
, dest
);
1659 static void bcd_sub(TCGv dest
, TCGv src
)
1664 * dest10 = dest10 - src10 - X
1665 * = bcd_add(dest + 1 - X, 0x199 - src)
1668 /* t0 = 0x066 + (0x199 - src) */
1670 t0
= tcg_temp_new();
1671 tcg_gen_subfi_i32(t0
, 0x1ff, src
);
1673 /* t1 = t0 + dest + 1 - X*/
1675 t1
= tcg_temp_new();
1676 tcg_gen_add_i32(t1
, t0
, dest
);
1677 tcg_gen_addi_i32(t1
, t1
, 1);
1678 tcg_gen_sub_i32(t1
, t1
, QREG_CC_X
);
1680 /* t2 = t0 ^ dest */
1682 t2
= tcg_temp_new();
1683 tcg_gen_xor_i32(t2
, t0
, dest
);
1687 tcg_gen_xor_i32(t0
, t1
, t2
);
1691 * t0 = (t2 >> 2) | (t2 >> 3)
1693 * to fit on 8bit operands, changed in:
1695 * t2 = ~(t0 >> 3) & 0x22
1700 tcg_gen_shri_i32(t2
, t0
, 3);
1701 tcg_gen_not_i32(t2
, t2
);
1702 tcg_gen_andi_i32(t2
, t2
, 0x22);
1703 tcg_gen_add_i32(t0
, t2
, t2
);
1704 tcg_gen_add_i32(t0
, t0
, t2
);
1706 /* return t1 - t0 */
1708 tcg_gen_sub_i32(dest
, t1
, t0
);
1711 static void bcd_flags(TCGv val
)
1713 tcg_gen_andi_i32(QREG_CC_C
, val
, 0x0ff);
1714 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_C
);
1716 tcg_gen_extract_i32(QREG_CC_C
, val
, 8, 1);
1718 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
1721 DISAS_INSN(abcd_reg
)
1726 gen_flush_flags(s
); /* !Z is sticky */
1728 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1729 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1731 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1736 DISAS_INSN(abcd_mem
)
1738 TCGv src
, dest
, addr
;
1740 gen_flush_flags(s
); /* !Z is sticky */
1742 /* Indirect pre-decrement load (mode 4) */
1744 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1745 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1746 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1747 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1751 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1752 EA_STORE
, IS_USER(s
));
1757 DISAS_INSN(sbcd_reg
)
1761 gen_flush_flags(s
); /* !Z is sticky */
1763 src
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
1764 dest
= gen_extend(s
, DREG(insn
, 9), OS_BYTE
, 0);
1768 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1773 DISAS_INSN(sbcd_mem
)
1775 TCGv src
, dest
, addr
;
1777 gen_flush_flags(s
); /* !Z is sticky */
1779 /* Indirect pre-decrement load (mode 4) */
1781 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1782 NULL_QREG
, NULL
, EA_LOADU
, IS_USER(s
));
1783 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1784 NULL_QREG
, &addr
, EA_LOADU
, IS_USER(s
));
1788 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
,
1789 EA_STORE
, IS_USER(s
));
1799 gen_flush_flags(s
); /* !Z is sticky */
1801 SRC_EA(env
, src
, OS_BYTE
, 0, &addr
);
1803 dest
= tcg_temp_new();
1804 tcg_gen_movi_i32(dest
, 0);
1807 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
1822 add
= (insn
& 0x4000) != 0;
1823 opsize
= insn_opsize(insn
);
1824 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
1825 dest
= tcg_temp_new();
1827 SRC_EA(env
, tmp
, opsize
, 1, &addr
);
1831 SRC_EA(env
, src
, opsize
, 1, NULL
);
1834 tcg_gen_add_i32(dest
, tmp
, src
);
1835 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, src
);
1836 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
1838 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, tmp
, src
);
1839 tcg_gen_sub_i32(dest
, tmp
, src
);
1840 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
1842 gen_update_cc_add(dest
, src
, opsize
);
1844 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1846 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
1850 /* Reverse the order of the bits in REG. */
1854 reg
= DREG(insn
, 0);
1855 gen_helper_bitrev(reg
, reg
);
1858 DISAS_INSN(bitop_reg
)
1868 if ((insn
& 0x38) != 0)
1872 op
= (insn
>> 6) & 3;
1873 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
1876 src2
= tcg_temp_new();
1877 if (opsize
== OS_BYTE
)
1878 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 7);
1880 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 31);
1882 tmp
= tcg_temp_new();
1883 tcg_gen_shl_i32(tmp
, tcg_constant_i32(1), src2
);
1885 tcg_gen_and_i32(QREG_CC_Z
, src1
, tmp
);
1887 dest
= tcg_temp_new();
1890 tcg_gen_xor_i32(dest
, src1
, tmp
);
1893 tcg_gen_andc_i32(dest
, src1
, tmp
);
1896 tcg_gen_or_i32(dest
, src1
, tmp
);
1902 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1909 reg
= DREG(insn
, 0);
1911 gen_helper_sats(reg
, reg
, QREG_CC_V
);
1912 gen_logic_cc(s
, reg
, OS_LONG
);
1915 static void gen_push(DisasContext
*s
, TCGv val
)
1919 tmp
= tcg_temp_new();
1920 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
1921 gen_store(s
, OS_LONG
, tmp
, val
, IS_USER(s
));
1922 tcg_gen_mov_i32(QREG_SP
, tmp
);
1925 static TCGv
mreg(int reg
)
1929 return cpu_dregs
[reg
];
1932 return cpu_aregs
[reg
& 7];
1937 TCGv addr
, incr
, tmp
, r
[16];
1938 int is_load
= (insn
& 0x0400) != 0;
1939 int opsize
= (insn
& 0x40) != 0 ? OS_LONG
: OS_WORD
;
1940 uint16_t mask
= read_im16(env
, s
);
1941 int mode
= extract32(insn
, 3, 3);
1942 int reg0
= REG(insn
, 0);
1945 tmp
= cpu_aregs
[reg0
];
1948 case 0: /* data register direct */
1949 case 1: /* addr register direct */
1954 case 2: /* indirect */
1957 case 3: /* indirect post-increment */
1959 /* post-increment is not allowed */
1964 case 4: /* indirect pre-decrement */
1966 /* pre-decrement is not allowed */
1970 * We want a bare copy of the address reg, without any pre-decrement
1971 * adjustment, as gen_lea would provide.
1976 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1977 if (IS_NULL_QREG(tmp
)) {
1983 addr
= tcg_temp_new();
1984 tcg_gen_mov_i32(addr
, tmp
);
1985 incr
= tcg_constant_i32(opsize_bytes(opsize
));
1988 /* memory to register */
1989 for (i
= 0; i
< 16; i
++) {
1990 if (mask
& (1 << i
)) {
1991 r
[i
] = gen_load(s
, opsize
, addr
, 1, IS_USER(s
));
1992 tcg_gen_add_i32(addr
, addr
, incr
);
1995 for (i
= 0; i
< 16; i
++) {
1996 if (mask
& (1 << i
)) {
1997 tcg_gen_mov_i32(mreg(i
), r
[i
]);
2001 /* post-increment: movem (An)+,X */
2002 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2005 /* register to memory */
2007 /* pre-decrement: movem X,-(An) */
2008 for (i
= 15; i
>= 0; i
--) {
2009 if ((mask
<< i
) & 0x8000) {
2010 tcg_gen_sub_i32(addr
, addr
, incr
);
2011 if (reg0
+ 8 == i
&&
2012 m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
)) {
2014 * M68020+: if the addressing register is the
2015 * register moved to memory, the value written
2016 * is the initial value decremented by the size of
2017 * the operation, regardless of how many actual
2018 * stores have been performed until this point.
2019 * M68000/M68010: the value is the initial value.
2021 tmp
= tcg_temp_new();
2022 tcg_gen_sub_i32(tmp
, cpu_aregs
[reg0
], incr
);
2023 gen_store(s
, opsize
, addr
, tmp
, IS_USER(s
));
2025 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2029 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2031 for (i
= 0; i
< 16; i
++) {
2032 if (mask
& (1 << i
)) {
2033 gen_store(s
, opsize
, addr
, mreg(i
), IS_USER(s
));
2034 tcg_gen_add_i32(addr
, addr
, incr
);
2050 displ
= read_im16(env
, s
);
2052 addr
= AREG(insn
, 0);
2053 reg
= DREG(insn
, 9);
2055 abuf
= tcg_temp_new();
2056 tcg_gen_addi_i32(abuf
, addr
, displ
);
2057 dbuf
= tcg_temp_new();
2066 for ( ; i
> 0 ; i
--) {
2067 tcg_gen_shri_i32(dbuf
, reg
, (i
- 1) * 8);
2068 tcg_gen_qemu_st_i32(dbuf
, abuf
, IS_USER(s
), MO_UB
);
2070 tcg_gen_addi_i32(abuf
, abuf
, 2);
2074 for ( ; i
> 0 ; i
--) {
2075 tcg_gen_qemu_ld_tl(dbuf
, abuf
, IS_USER(s
), MO_UB
);
2076 tcg_gen_deposit_i32(reg
, reg
, dbuf
, (i
- 1) * 8, 8);
2078 tcg_gen_addi_i32(abuf
, abuf
, 2);
2084 DISAS_INSN(bitop_im
)
2094 if ((insn
& 0x38) != 0)
2098 op
= (insn
>> 6) & 3;
2100 bitnum
= read_im16(env
, s
);
2101 if (m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
2102 if (bitnum
& 0xfe00) {
2103 disas_undef(env
, s
, insn
);
2107 if (bitnum
& 0xff00) {
2108 disas_undef(env
, s
, insn
);
2113 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
2116 if (opsize
== OS_BYTE
)
2122 tcg_gen_andi_i32(QREG_CC_Z
, src1
, mask
);
2125 tmp
= tcg_temp_new();
2128 tcg_gen_xori_i32(tmp
, src1
, mask
);
2131 tcg_gen_andi_i32(tmp
, src1
, ~mask
);
2134 tcg_gen_ori_i32(tmp
, src1
, mask
);
2139 DEST_EA(env
, insn
, opsize
, tmp
, &addr
);
2143 static TCGv
gen_get_ccr(DisasContext
*s
)
2148 dest
= tcg_temp_new();
2149 gen_helper_get_ccr(dest
, tcg_env
);
2153 static TCGv
gen_get_sr(DisasContext
*s
)
2158 ccr
= gen_get_ccr(s
);
2159 sr
= tcg_temp_new();
2160 tcg_gen_andi_i32(sr
, QREG_SR
, 0xffe0);
2161 tcg_gen_or_i32(sr
, sr
, ccr
);
2165 static void gen_set_sr_im(DisasContext
*s
, uint16_t val
, int ccr_only
)
2168 tcg_gen_movi_i32(QREG_CC_C
, val
& CCF_C
? 1 : 0);
2169 tcg_gen_movi_i32(QREG_CC_V
, val
& CCF_V
? -1 : 0);
2170 tcg_gen_movi_i32(QREG_CC_Z
, val
& CCF_Z
? 0 : 1);
2171 tcg_gen_movi_i32(QREG_CC_N
, val
& CCF_N
? -1 : 0);
2172 tcg_gen_movi_i32(QREG_CC_X
, val
& CCF_X
? 1 : 0);
2174 /* Must writeback before changing security state. */
2176 gen_helper_set_sr(tcg_env
, tcg_constant_i32(val
));
2178 set_cc_op(s
, CC_OP_FLAGS
);
2181 static void gen_set_sr(DisasContext
*s
, TCGv val
, int ccr_only
)
2184 gen_helper_set_ccr(tcg_env
, val
);
2186 /* Must writeback before changing security state. */
2188 gen_helper_set_sr(tcg_env
, val
);
2190 set_cc_op(s
, CC_OP_FLAGS
);
2193 static void gen_move_to_sr(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
2196 if ((insn
& 0x3f) == 0x3c) {
2198 val
= read_im16(env
, s
);
2199 gen_set_sr_im(s
, val
, ccr_only
);
2202 SRC_EA(env
, src
, OS_WORD
, 0, NULL
);
2203 gen_set_sr(s
, src
, ccr_only
);
2207 DISAS_INSN(arith_im
)
2215 bool with_SR
= ((insn
& 0x3f) == 0x3c);
2217 op
= (insn
>> 9) & 7;
2218 opsize
= insn_opsize(insn
);
2221 im
= tcg_constant_i32((int8_t)read_im8(env
, s
));
2224 im
= tcg_constant_i32((int16_t)read_im16(env
, s
));
2227 im
= tcg_constant_i32(read_im32(env
, s
));
2230 g_assert_not_reached();
2234 /* SR/CCR can only be used with andi/eori/ori */
2235 if (op
== 2 || op
== 3 || op
== 6) {
2236 disas_undef(env
, s
, insn
);
2241 src1
= gen_get_ccr(s
);
2245 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2248 src1
= gen_get_sr(s
);
2251 /* OS_LONG; others already g_assert_not_reached. */
2252 disas_undef(env
, s
, insn
);
2256 SRC_EA(env
, src1
, opsize
, 1, (op
== 6) ? NULL
: &addr
);
2258 dest
= tcg_temp_new();
2261 tcg_gen_or_i32(dest
, src1
, im
);
2263 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2266 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2267 gen_logic_cc(s
, dest
, opsize
);
2271 tcg_gen_and_i32(dest
, src1
, im
);
2273 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2276 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2277 gen_logic_cc(s
, dest
, opsize
);
2281 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, src1
, im
);
2282 tcg_gen_sub_i32(dest
, src1
, im
);
2283 gen_update_cc_add(dest
, im
, opsize
);
2284 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2285 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2288 tcg_gen_add_i32(dest
, src1
, im
);
2289 gen_update_cc_add(dest
, im
, opsize
);
2290 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, im
);
2291 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2292 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2295 tcg_gen_xor_i32(dest
, src1
, im
);
2297 gen_set_sr(s
, dest
, opsize
== OS_BYTE
);
2300 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2301 gen_logic_cc(s
, dest
, opsize
);
2305 gen_update_cc_cmp(s
, src1
, im
, opsize
);
2321 switch ((insn
>> 9) & 3) {
2335 g_assert_not_reached();
2338 ext
= read_im16(env
, s
);
2340 /* cas Dc,Du,<EA> */
2342 addr
= gen_lea(env
, s
, insn
, opsize
);
2343 if (IS_NULL_QREG(addr
)) {
2348 cmp
= gen_extend(s
, DREG(ext
, 0), opsize
, 1);
2351 * if <EA> == Dc then
2353 * Dc = <EA> (because <EA> == Dc)
2358 load
= tcg_temp_new();
2359 tcg_gen_atomic_cmpxchg_i32(load
, addr
, cmp
, DREG(ext
, 6),
2361 /* update flags before setting cmp to load */
2362 gen_update_cc_cmp(s
, load
, cmp
, opsize
);
2363 gen_partset_reg(opsize
, DREG(ext
, 0), load
);
2365 switch (extract32(insn
, 3, 3)) {
2366 case 3: /* Indirect postincrement. */
2367 tcg_gen_addi_i32(AREG(insn
, 0), addr
, opsize_bytes(opsize
));
2369 case 4: /* Indirect predecrememnt. */
2370 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2377 uint16_t ext1
, ext2
;
2380 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2382 ext1
= read_im16(env
, s
);
2384 if (ext1
& 0x8000) {
2385 /* Address Register */
2386 addr1
= AREG(ext1
, 12);
2389 addr1
= DREG(ext1
, 12);
2392 ext2
= read_im16(env
, s
);
2393 if (ext2
& 0x8000) {
2394 /* Address Register */
2395 addr2
= AREG(ext2
, 12);
2398 addr2
= DREG(ext2
, 12);
2402 * if (R1) == Dc1 && (R2) == Dc2 then
2410 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2411 gen_helper_exit_atomic(tcg_env
);
2413 TCGv regs
= tcg_constant_i32(REG(ext2
, 6) |
2414 (REG(ext1
, 6) << 3) |
2415 (REG(ext2
, 0) << 6) |
2416 (REG(ext1
, 0) << 9));
2417 gen_helper_cas2w(tcg_env
, regs
, addr1
, addr2
);
2420 /* Note that cas2w also assigned to env->cc_op. */
2421 s
->cc_op
= CC_OP_CMPW
;
2422 s
->cc_op_synced
= 1;
2427 uint16_t ext1
, ext2
;
2428 TCGv addr1
, addr2
, regs
;
2430 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2432 ext1
= read_im16(env
, s
);
2434 if (ext1
& 0x8000) {
2435 /* Address Register */
2436 addr1
= AREG(ext1
, 12);
2439 addr1
= DREG(ext1
, 12);
2442 ext2
= read_im16(env
, s
);
2443 if (ext2
& 0x8000) {
2444 /* Address Register */
2445 addr2
= AREG(ext2
, 12);
2448 addr2
= DREG(ext2
, 12);
2452 * if (R1) == Dc1 && (R2) == Dc2 then
2460 regs
= tcg_constant_i32(REG(ext2
, 6) |
2461 (REG(ext1
, 6) << 3) |
2462 (REG(ext2
, 0) << 6) |
2463 (REG(ext1
, 0) << 9));
2464 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2465 gen_helper_cas2l_parallel(tcg_env
, regs
, addr1
, addr2
);
2467 gen_helper_cas2l(tcg_env
, regs
, addr1
, addr2
);
2470 /* Note that cas2l also assigned to env->cc_op. */
2471 s
->cc_op
= CC_OP_CMPL
;
2472 s
->cc_op_synced
= 1;
2479 reg
= DREG(insn
, 0);
2480 tcg_gen_bswap32_i32(reg
, reg
);
2490 switch (insn
>> 12) {
2491 case 1: /* move.b */
2494 case 2: /* move.l */
2497 case 3: /* move.w */
2503 SRC_EA(env
, src
, opsize
, 1, NULL
);
2504 op
= (insn
>> 6) & 7;
2507 /* The value will already have been sign extended. */
2508 dest
= AREG(insn
, 9);
2509 tcg_gen_mov_i32(dest
, src
);
2513 dest_ea
= ((insn
>> 9) & 7) | (op
<< 3);
2514 DEST_EA(env
, dest_ea
, opsize
, src
, NULL
);
2515 /* This will be correct because loads sign extend. */
2516 gen_logic_cc(s
, src
, opsize
);
2527 opsize
= insn_opsize(insn
);
2528 SRC_EA(env
, src
, opsize
, 1, &addr
);
2530 gen_flush_flags(s
); /* compute old Z */
2533 * Perform subtract with borrow.
2534 * (X, N) = -(src + X);
2537 z
= tcg_constant_i32(0);
2538 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, z
, QREG_CC_X
, z
);
2539 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, z
, z
, QREG_CC_N
, QREG_CC_X
);
2540 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
2542 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
2545 * Compute signed-overflow for negation. The normal formula for
2546 * subtraction is (res ^ src) & (src ^ dest), but with dest==0
2547 * this simplifies to res & src.
2550 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_N
, src
);
2552 /* Copy the rest of the results into place. */
2553 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
2554 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
2556 set_cc_op(s
, CC_OP_FLAGS
);
2558 /* result is in QREG_CC_N */
2560 DEST_EA(env
, insn
, opsize
, QREG_CC_N
, &addr
);
2568 reg
= AREG(insn
, 9);
2569 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2570 if (IS_NULL_QREG(tmp
)) {
2574 tcg_gen_mov_i32(reg
, tmp
);
2582 zero
= tcg_constant_i32(0);
2583 opsize
= insn_opsize(insn
);
2584 DEST_EA(env
, insn
, opsize
, zero
, NULL
);
2585 gen_logic_cc(s
, zero
, opsize
);
2588 DISAS_INSN(move_from_ccr
)
2592 ccr
= gen_get_ccr(s
);
2593 DEST_EA(env
, insn
, OS_WORD
, ccr
, NULL
);
2603 opsize
= insn_opsize(insn
);
2604 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2605 dest
= tcg_temp_new();
2606 tcg_gen_neg_i32(dest
, src1
);
2607 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2608 gen_update_cc_add(dest
, src1
, opsize
);
2609 tcg_gen_setcondi_i32(TCG_COND_NE
, QREG_CC_X
, dest
, 0);
2610 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2613 DISAS_INSN(move_to_ccr
)
2615 gen_move_to_sr(env
, s
, insn
, true);
2625 opsize
= insn_opsize(insn
);
2626 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2627 dest
= tcg_temp_new();
2628 tcg_gen_not_i32(dest
, src1
);
2629 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2630 gen_logic_cc(s
, dest
, opsize
);
2639 src1
= tcg_temp_new();
2640 src2
= tcg_temp_new();
2641 reg
= DREG(insn
, 0);
2642 tcg_gen_shli_i32(src1
, reg
, 16);
2643 tcg_gen_shri_i32(src2
, reg
, 16);
2644 tcg_gen_or_i32(reg
, src1
, src2
);
2645 gen_logic_cc(s
, reg
, OS_LONG
);
2650 #if defined(CONFIG_USER_ONLY)
2651 gen_exception(s
, s
->base
.pc_next
, EXCP_DEBUG
);
2653 /* BKPT #0 is the alternate semihosting instruction. */
2654 if ((insn
& 7) == 0 && semihosting_test(s
)) {
2655 gen_exception(s
, s
->pc
, EXCP_SEMIHOSTING
);
2658 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2666 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2667 if (IS_NULL_QREG(tmp
)) {
2680 reg
= DREG(insn
, 0);
2681 op
= (insn
>> 6) & 7;
2682 tmp
= tcg_temp_new();
2684 tcg_gen_ext16s_i32(tmp
, reg
);
2686 tcg_gen_ext8s_i32(tmp
, reg
);
2688 gen_partset_reg(OS_WORD
, reg
, tmp
);
2690 tcg_gen_mov_i32(reg
, tmp
);
2691 gen_logic_cc(s
, tmp
, OS_LONG
);
2699 opsize
= insn_opsize(insn
);
2700 SRC_EA(env
, tmp
, opsize
, 1, NULL
);
2701 gen_logic_cc(s
, tmp
, opsize
);
2706 /* Implemented as a NOP. */
2711 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2716 int mode
= extract32(insn
, 3, 3);
2717 int reg0
= REG(insn
, 0);
2720 /* data register direct */
2721 TCGv dest
= cpu_dregs
[reg0
];
2722 gen_logic_cc(s
, dest
, OS_BYTE
);
2723 tcg_gen_ori_tl(dest
, dest
, 0x80);
2727 addr
= gen_lea_mode(env
, s
, mode
, reg0
, OS_BYTE
);
2728 if (IS_NULL_QREG(addr
)) {
2732 src1
= tcg_temp_new();
2733 tcg_gen_atomic_fetch_or_tl(src1
, addr
, tcg_constant_tl(0x80),
2735 gen_logic_cc(s
, src1
, OS_BYTE
);
2738 case 3: /* Indirect postincrement. */
2739 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 1);
2741 case 4: /* Indirect predecrememnt. */
2742 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2754 ext
= read_im16(env
, s
);
2759 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
2760 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
2764 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2767 tcg_gen_muls2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2769 tcg_gen_mulu2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2771 /* if Dl == Dh, 68040 returns low word */
2772 tcg_gen_mov_i32(DREG(ext
, 0), QREG_CC_N
);
2773 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_Z
);
2774 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
);
2776 tcg_gen_movi_i32(QREG_CC_V
, 0);
2777 tcg_gen_movi_i32(QREG_CC_C
, 0);
2779 set_cc_op(s
, CC_OP_FLAGS
);
2782 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2783 if (m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
2784 tcg_gen_movi_i32(QREG_CC_C
, 0);
2786 tcg_gen_muls2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2787 /* QREG_CC_V is -(QREG_CC_V != (QREG_CC_N >> 31)) */
2788 tcg_gen_sari_i32(QREG_CC_Z
, QREG_CC_N
, 31);
2789 tcg_gen_negsetcond_i32(TCG_COND_NE
, QREG_CC_V
,
2790 QREG_CC_V
, QREG_CC_Z
);
2792 tcg_gen_mulu2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2793 /* QREG_CC_V is -(QREG_CC_V != 0), use QREG_CC_C as 0 */
2794 tcg_gen_negsetcond_i32(TCG_COND_NE
, QREG_CC_V
,
2795 QREG_CC_V
, QREG_CC_C
);
2797 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_N
);
2799 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
2801 set_cc_op(s
, CC_OP_FLAGS
);
2804 * The upper 32 bits of the product are discarded, so
2805 * muls.l and mulu.l are functionally equivalent.
2807 tcg_gen_mul_i32(DREG(ext
, 12), src1
, DREG(ext
, 12));
2808 gen_logic_cc(s
, DREG(ext
, 12), OS_LONG
);
2812 static void gen_link(DisasContext
*s
, uint16_t insn
, int32_t offset
)
2817 reg
= AREG(insn
, 0);
2818 tmp
= tcg_temp_new();
2819 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
2820 gen_store(s
, OS_LONG
, tmp
, reg
, IS_USER(s
));
2821 if ((insn
& 7) != 7) {
2822 tcg_gen_mov_i32(reg
, tmp
);
2824 tcg_gen_addi_i32(QREG_SP
, tmp
, offset
);
2831 offset
= read_im16(env
, s
);
2832 gen_link(s
, insn
, offset
);
2839 offset
= read_im32(env
, s
);
2840 gen_link(s
, insn
, offset
);
2849 src
= tcg_temp_new();
2850 reg
= AREG(insn
, 0);
2851 tcg_gen_mov_i32(src
, reg
);
2852 tmp
= gen_load(s
, OS_LONG
, src
, 0, IS_USER(s
));
2853 tcg_gen_mov_i32(reg
, tmp
);
2854 tcg_gen_addi_i32(QREG_SP
, src
, 4);
2857 #if !defined(CONFIG_USER_ONLY)
2861 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
2865 gen_helper_reset(tcg_env
);
2876 int16_t offset
= read_im16(env
, s
);
2878 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
2879 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, offset
+ 4);
2889 sp
= tcg_temp_new();
2890 ccr
= gen_load(s
, OS_WORD
, QREG_SP
, 0, IS_USER(s
));
2891 tcg_gen_addi_i32(sp
, QREG_SP
, 2);
2892 tmp
= gen_load(s
, OS_LONG
, sp
, 0, IS_USER(s
));
2893 tcg_gen_addi_i32(QREG_SP
, sp
, 4);
2895 gen_set_sr(s
, ccr
, true);
2904 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0, IS_USER(s
));
2905 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, 4);
2914 * Load the target address first to ensure correct exception
2917 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2918 if (IS_NULL_QREG(tmp
)) {
2922 if ((insn
& 0x40) == 0) {
2924 gen_push(s
, tcg_constant_i32(s
->pc
));
2938 if ((insn
& 070) == 010) {
2939 /* Operation on address register is always long. */
2942 opsize
= insn_opsize(insn
);
2944 SRC_EA(env
, src
, opsize
, 1, &addr
);
2945 imm
= (insn
>> 9) & 7;
2949 val
= tcg_constant_i32(imm
);
2950 dest
= tcg_temp_new();
2951 tcg_gen_mov_i32(dest
, src
);
2952 if ((insn
& 0x38) == 0x08) {
2954 * Don't update condition codes if the destination is an
2957 if (insn
& 0x0100) {
2958 tcg_gen_sub_i32(dest
, dest
, val
);
2960 tcg_gen_add_i32(dest
, dest
, val
);
2963 if (insn
& 0x0100) {
2964 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
2965 tcg_gen_sub_i32(dest
, dest
, val
);
2966 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2968 tcg_gen_add_i32(dest
, dest
, val
);
2969 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
2970 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2972 gen_update_cc_add(dest
, val
, opsize
);
2974 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2984 op
= (insn
>> 8) & 0xf;
2985 offset
= (int8_t)insn
;
2987 offset
= (int16_t)read_im16(env
, s
);
2988 } else if (offset
== -1) {
2989 offset
= read_im32(env
, s
);
2993 gen_push(s
, tcg_constant_i32(s
->pc
));
2997 TCGLabel
*l1
= gen_new_label();
2998 gen_jmpcc(s
, ((insn
>> 8) & 0xf) ^ 1, l1
);
2999 gen_jmp_tb(s
, 1, base
+ offset
, s
->base
.pc_next
);
3001 gen_jmp_tb(s
, 0, s
->pc
, s
->base
.pc_next
);
3003 /* Unconditional branch. */
3005 gen_jmp_tb(s
, 0, base
+ offset
, s
->base
.pc_next
);
3011 tcg_gen_movi_i32(DREG(insn
, 9), (int8_t)insn
);
3012 gen_logic_cc(s
, DREG(insn
, 9), OS_LONG
);
3025 SRC_EA(env
, src
, opsize
, (insn
& 0x80) == 0, NULL
);
3026 reg
= DREG(insn
, 9);
3027 tcg_gen_mov_i32(reg
, src
);
3028 gen_logic_cc(s
, src
, opsize
);
3039 opsize
= insn_opsize(insn
);
3040 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 0);
3041 dest
= tcg_temp_new();
3043 SRC_EA(env
, src
, opsize
, 0, &addr
);
3044 tcg_gen_or_i32(dest
, src
, reg
);
3045 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3047 SRC_EA(env
, src
, opsize
, 0, NULL
);
3048 tcg_gen_or_i32(dest
, src
, reg
);
3049 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
3051 gen_logic_cc(s
, dest
, opsize
);
3059 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3060 reg
= AREG(insn
, 9);
3061 tcg_gen_sub_i32(reg
, reg
, src
);
3064 static inline void gen_subx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3068 gen_flush_flags(s
); /* compute old Z */
3071 * Perform subtract with borrow.
3072 * (X, N) = dest - (src + X);
3075 zero
= tcg_constant_i32(0);
3076 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, zero
, QREG_CC_X
, zero
);
3077 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, dest
, zero
, QREG_CC_N
, QREG_CC_X
);
3078 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3079 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
3081 /* Compute signed-overflow for subtract. */
3083 tmp
= tcg_temp_new();
3084 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, dest
);
3085 tcg_gen_xor_i32(tmp
, dest
, src
);
3086 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3088 /* Copy the rest of the results into place. */
3089 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3090 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3092 set_cc_op(s
, CC_OP_FLAGS
);
3094 /* result is in QREG_CC_N */
3097 DISAS_INSN(subx_reg
)
3103 opsize
= insn_opsize(insn
);
3105 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3106 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3108 gen_subx(s
, src
, dest
, opsize
);
3110 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3113 DISAS_INSN(subx_mem
)
3121 opsize
= insn_opsize(insn
);
3123 addr_src
= AREG(insn
, 0);
3124 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3125 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3127 addr_dest
= AREG(insn
, 9);
3128 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3129 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3131 gen_subx(s
, src
, dest
, opsize
);
3133 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3141 val
= (insn
>> 9) & 7;
3145 src
= tcg_constant_i32(val
);
3146 gen_logic_cc(s
, src
, OS_LONG
);
3147 DEST_EA(env
, insn
, OS_LONG
, src
, NULL
);
3156 opsize
= insn_opsize(insn
);
3157 SRC_EA(env
, src
, opsize
, 1, NULL
);
3158 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3159 gen_update_cc_cmp(s
, reg
, src
, opsize
);
3173 SRC_EA(env
, src
, opsize
, 1, NULL
);
3174 reg
= AREG(insn
, 9);
3175 gen_update_cc_cmp(s
, reg
, src
, OS_LONG
);
3180 int opsize
= insn_opsize(insn
);
3183 /* Post-increment load (mode 3) from Ay. */
3184 src
= gen_ea_mode(env
, s
, 3, REG(insn
, 0), opsize
,
3185 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3186 /* Post-increment load (mode 3) from Ax. */
3187 dst
= gen_ea_mode(env
, s
, 3, REG(insn
, 9), opsize
,
3188 NULL_QREG
, NULL
, EA_LOADS
, IS_USER(s
));
3190 gen_update_cc_cmp(s
, dst
, src
, opsize
);
3200 opsize
= insn_opsize(insn
);
3202 SRC_EA(env
, src
, opsize
, 0, &addr
);
3203 dest
= tcg_temp_new();
3204 tcg_gen_xor_i32(dest
, src
, DREG(insn
, 9));
3205 gen_logic_cc(s
, dest
, opsize
);
3206 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3209 static void do_exg(TCGv reg1
, TCGv reg2
)
3211 TCGv temp
= tcg_temp_new();
3212 tcg_gen_mov_i32(temp
, reg1
);
3213 tcg_gen_mov_i32(reg1
, reg2
);
3214 tcg_gen_mov_i32(reg2
, temp
);
3219 /* exchange Dx and Dy */
3220 do_exg(DREG(insn
, 9), DREG(insn
, 0));
3225 /* exchange Ax and Ay */
3226 do_exg(AREG(insn
, 9), AREG(insn
, 0));
3231 /* exchange Dx and Ay */
3232 do_exg(DREG(insn
, 9), AREG(insn
, 0));
3243 dest
= tcg_temp_new();
3245 opsize
= insn_opsize(insn
);
3246 reg
= DREG(insn
, 9);
3248 SRC_EA(env
, src
, opsize
, 0, &addr
);
3249 tcg_gen_and_i32(dest
, src
, reg
);
3250 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3252 SRC_EA(env
, src
, opsize
, 0, NULL
);
3253 tcg_gen_and_i32(dest
, src
, reg
);
3254 gen_partset_reg(opsize
, reg
, dest
);
3256 gen_logic_cc(s
, dest
, opsize
);
3264 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3265 reg
= AREG(insn
, 9);
3266 tcg_gen_add_i32(reg
, reg
, src
);
3269 static inline void gen_addx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3273 gen_flush_flags(s
); /* compute old Z */
3276 * Perform addition with carry.
3277 * (X, N) = src + dest + X;
3280 zero
= tcg_constant_i32(0);
3281 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_X
, zero
, dest
, zero
);
3282 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_N
, QREG_CC_X
, src
, zero
);
3283 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3285 /* Compute signed-overflow for addition. */
3287 tmp
= tcg_temp_new();
3288 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3289 tcg_gen_xor_i32(tmp
, dest
, src
);
3290 tcg_gen_andc_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3292 /* Copy the rest of the results into place. */
3293 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3294 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3296 set_cc_op(s
, CC_OP_FLAGS
);
3298 /* result is in QREG_CC_N */
3301 DISAS_INSN(addx_reg
)
3307 opsize
= insn_opsize(insn
);
3309 dest
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
3310 src
= gen_extend(s
, DREG(insn
, 0), opsize
, 1);
3312 gen_addx(s
, src
, dest
, opsize
);
3314 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3317 DISAS_INSN(addx_mem
)
3325 opsize
= insn_opsize(insn
);
3327 addr_src
= AREG(insn
, 0);
3328 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3329 src
= gen_load(s
, opsize
, addr_src
, 1, IS_USER(s
));
3331 addr_dest
= AREG(insn
, 9);
3332 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3333 dest
= gen_load(s
, opsize
, addr_dest
, 1, IS_USER(s
));
3335 gen_addx(s
, src
, dest
, opsize
);
3337 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
, IS_USER(s
));
3340 static inline void shift_im(DisasContext
*s
, uint16_t insn
, int opsize
)
3342 int count
= (insn
>> 9) & 7;
3343 int logical
= insn
& 8;
3344 int left
= insn
& 0x100;
3345 int bits
= opsize_bytes(opsize
) * 8;
3346 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3352 tcg_gen_movi_i32(QREG_CC_V
, 0);
3354 tcg_gen_shri_i32(QREG_CC_C
, reg
, bits
- count
);
3355 tcg_gen_shli_i32(QREG_CC_N
, reg
, count
);
3358 * Note that ColdFire always clears V (done above),
3359 * while M68000 sets if the most significant bit is changed at
3360 * any time during the shift operation.
3362 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
3363 /* if shift count >= bits, V is (reg != 0) */
3364 if (count
>= bits
) {
3365 tcg_gen_negsetcond_i32(TCG_COND_NE
, QREG_CC_V
, reg
, QREG_CC_V
);
3367 TCGv t0
= tcg_temp_new();
3368 tcg_gen_sari_i32(QREG_CC_V
, reg
, bits
- 1);
3369 tcg_gen_sari_i32(t0
, reg
, bits
- count
- 1);
3370 tcg_gen_negsetcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, t0
);
3374 tcg_gen_shri_i32(QREG_CC_C
, reg
, count
- 1);
3376 tcg_gen_shri_i32(QREG_CC_N
, reg
, count
);
3378 tcg_gen_sari_i32(QREG_CC_N
, reg
, count
);
3382 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3383 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3384 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3385 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3387 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3388 set_cc_op(s
, CC_OP_FLAGS
);
3391 static inline void shift_reg(DisasContext
*s
, uint16_t insn
, int opsize
)
3393 int logical
= insn
& 8;
3394 int left
= insn
& 0x100;
3395 int bits
= opsize_bytes(opsize
) * 8;
3396 TCGv reg
= gen_extend(s
, DREG(insn
, 0), opsize
, !logical
);
3400 t64
= tcg_temp_new_i64();
3401 s64
= tcg_temp_new_i64();
3402 s32
= tcg_temp_new();
3405 * Note that m68k truncates the shift count modulo 64, not 32.
3406 * In addition, a 64-bit shift makes it easy to find "the last
3407 * bit shifted out", for the carry flag.
3409 tcg_gen_andi_i32(s32
, DREG(insn
, 9), 63);
3410 tcg_gen_extu_i32_i64(s64
, s32
);
3411 tcg_gen_extu_i32_i64(t64
, reg
);
3413 /* Optimistically set V=0. Also used as a zero source below. */
3414 tcg_gen_movi_i32(QREG_CC_V
, 0);
3416 tcg_gen_shl_i64(t64
, t64
, s64
);
3418 if (opsize
== OS_LONG
) {
3419 tcg_gen_extr_i64_i32(QREG_CC_N
, QREG_CC_C
, t64
);
3420 /* Note that C=0 if shift count is 0, and we get that for free. */
3422 TCGv zero
= tcg_constant_i32(0);
3423 tcg_gen_extrl_i64_i32(QREG_CC_N
, t64
);
3424 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_N
, bits
);
3425 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3426 s32
, zero
, zero
, QREG_CC_C
);
3428 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3430 /* X = C, but only if the shift count was non-zero. */
3431 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3432 QREG_CC_C
, QREG_CC_X
);
3435 * M68000 sets V if the most significant bit is changed at
3436 * any time during the shift operation. Do this via creating
3437 * an extension of the sign bit, comparing, and discarding
3438 * the bits below the sign bit. I.e.
3439 * int64_t s = (intN_t)reg;
3440 * int64_t t = (int64_t)(intN_t)reg << count;
3441 * V = ((s ^ t) & (-1 << (bits - 1))) != 0
3443 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
3444 TCGv_i64 tt
= tcg_constant_i64(32);
3445 /* if shift is greater than 32, use 32 */
3446 tcg_gen_movcond_i64(TCG_COND_GT
, s64
, s64
, tt
, tt
, s64
);
3447 /* Sign extend the input to 64 bits; re-do the shift. */
3448 tcg_gen_ext_i32_i64(t64
, reg
);
3449 tcg_gen_shl_i64(s64
, t64
, s64
);
3450 /* Clear all bits that are unchanged. */
3451 tcg_gen_xor_i64(t64
, t64
, s64
);
3452 /* Ignore the bits below the sign bit. */
3453 tcg_gen_andi_i64(t64
, t64
, -1ULL << (bits
- 1));
3454 /* If any bits remain set, we have overflow. */
3455 tcg_gen_negsetcond_i64(TCG_COND_NE
, t64
, t64
, tcg_constant_i64(0));
3456 tcg_gen_extrl_i64_i32(QREG_CC_V
, t64
);
3459 tcg_gen_shli_i64(t64
, t64
, 32);
3461 tcg_gen_shr_i64(t64
, t64
, s64
);
3463 tcg_gen_sar_i64(t64
, t64
, s64
);
3465 tcg_gen_extr_i64_i32(QREG_CC_C
, QREG_CC_N
, t64
);
3467 /* Note that C=0 if shift count is 0, and we get that for free. */
3468 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_C
, 31);
3470 /* X = C, but only if the shift count was non-zero. */
3471 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3472 QREG_CC_C
, QREG_CC_X
);
3474 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3475 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3477 /* Write back the result. */
3478 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3479 set_cc_op(s
, CC_OP_FLAGS
);
3482 DISAS_INSN(shift8_im
)
3484 shift_im(s
, insn
, OS_BYTE
);
3487 DISAS_INSN(shift16_im
)
3489 shift_im(s
, insn
, OS_WORD
);
3492 DISAS_INSN(shift_im
)
3494 shift_im(s
, insn
, OS_LONG
);
3497 DISAS_INSN(shift8_reg
)
3499 shift_reg(s
, insn
, OS_BYTE
);
3502 DISAS_INSN(shift16_reg
)
3504 shift_reg(s
, insn
, OS_WORD
);
3507 DISAS_INSN(shift_reg
)
3509 shift_reg(s
, insn
, OS_LONG
);
3512 DISAS_INSN(shift_mem
)
3514 int logical
= insn
& 8;
3515 int left
= insn
& 0x100;
3519 SRC_EA(env
, src
, OS_WORD
, !logical
, &addr
);
3520 tcg_gen_movi_i32(QREG_CC_V
, 0);
3522 tcg_gen_shri_i32(QREG_CC_C
, src
, 15);
3523 tcg_gen_shli_i32(QREG_CC_N
, src
, 1);
3526 * Note that ColdFire always clears V,
3527 * while M68000 sets if the most significant bit is changed at
3528 * any time during the shift operation
3530 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68K
)) {
3531 src
= gen_extend(s
, src
, OS_WORD
, 1);
3532 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3535 tcg_gen_mov_i32(QREG_CC_C
, src
);
3537 tcg_gen_shri_i32(QREG_CC_N
, src
, 1);
3539 tcg_gen_sari_i32(QREG_CC_N
, src
, 1);
3543 gen_ext(QREG_CC_N
, QREG_CC_N
, OS_WORD
, 1);
3544 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3545 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3546 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3548 DEST_EA(env
, insn
, OS_WORD
, QREG_CC_N
, &addr
);
3549 set_cc_op(s
, CC_OP_FLAGS
);
3552 static void rotate(TCGv reg
, TCGv shift
, int left
, int size
)
3556 /* Replicate the 8-bit input so that a 32-bit rotate works. */
3557 tcg_gen_ext8u_i32(reg
, reg
);
3558 tcg_gen_muli_i32(reg
, reg
, 0x01010101);
3561 /* Replicate the 16-bit input so that a 32-bit rotate works. */
3562 tcg_gen_deposit_i32(reg
, reg
, reg
, 16, 16);
3567 tcg_gen_rotl_i32(reg
, reg
, shift
);
3569 tcg_gen_rotr_i32(reg
, reg
, shift
);
3577 tcg_gen_ext8s_i32(reg
, reg
);
3580 tcg_gen_ext16s_i32(reg
, reg
);
3586 /* QREG_CC_X is not affected */
3588 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3589 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3592 tcg_gen_andi_i32(QREG_CC_C
, reg
, 1);
3594 tcg_gen_shri_i32(QREG_CC_C
, reg
, 31);
3597 tcg_gen_movi_i32(QREG_CC_V
, 0); /* always cleared */
3600 static void rotate_x_flags(TCGv reg
, TCGv X
, int size
)
3604 tcg_gen_ext8s_i32(reg
, reg
);
3607 tcg_gen_ext16s_i32(reg
, reg
);
3612 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3613 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3614 tcg_gen_mov_i32(QREG_CC_X
, X
);
3615 tcg_gen_mov_i32(QREG_CC_C
, X
);
3616 tcg_gen_movi_i32(QREG_CC_V
, 0);
3619 /* Result of rotate_x() is valid if 0 <= shift <= size */
3620 static TCGv
rotate_x(TCGv reg
, TCGv shift
, int left
, int size
)
3622 TCGv X
, shl
, shr
, shx
, sz
, zero
;
3624 sz
= tcg_constant_i32(size
);
3626 shr
= tcg_temp_new();
3627 shl
= tcg_temp_new();
3628 shx
= tcg_temp_new();
3630 tcg_gen_mov_i32(shl
, shift
); /* shl = shift */
3631 tcg_gen_movi_i32(shr
, size
+ 1);
3632 tcg_gen_sub_i32(shr
, shr
, shift
); /* shr = size + 1 - shift */
3633 tcg_gen_subi_i32(shx
, shift
, 1); /* shx = shift - 1 */
3634 /* shx = shx < 0 ? size : shx; */
3635 zero
= tcg_constant_i32(0);
3636 tcg_gen_movcond_i32(TCG_COND_LT
, shx
, shx
, zero
, sz
, shx
);
3638 tcg_gen_mov_i32(shr
, shift
); /* shr = shift */
3639 tcg_gen_movi_i32(shl
, size
+ 1);
3640 tcg_gen_sub_i32(shl
, shl
, shift
); /* shl = size + 1 - shift */
3641 tcg_gen_sub_i32(shx
, sz
, shift
); /* shx = size - shift */
3644 /* reg = (reg << shl) | (reg >> shr) | (x << shx); */
3646 tcg_gen_shl_i32(shl
, reg
, shl
);
3647 tcg_gen_shr_i32(shr
, reg
, shr
);
3648 tcg_gen_or_i32(reg
, shl
, shr
);
3649 tcg_gen_shl_i32(shx
, QREG_CC_X
, shx
);
3650 tcg_gen_or_i32(reg
, reg
, shx
);
3652 /* X = (reg >> size) & 1 */
3655 tcg_gen_extract_i32(X
, reg
, size
, 1);
3660 /* Result of rotate32_x() is valid if 0 <= shift < 33 */
3661 static TCGv
rotate32_x(TCGv reg
, TCGv shift
, int left
)
3663 TCGv_i64 t0
, shift64
;
3664 TCGv X
, lo
, hi
, zero
;
3666 shift64
= tcg_temp_new_i64();
3667 tcg_gen_extu_i32_i64(shift64
, shift
);
3669 t0
= tcg_temp_new_i64();
3672 lo
= tcg_temp_new();
3673 hi
= tcg_temp_new();
3676 /* create [reg:X:..] */
3678 tcg_gen_shli_i32(lo
, QREG_CC_X
, 31);
3679 tcg_gen_concat_i32_i64(t0
, lo
, reg
);
3683 tcg_gen_rotl_i64(t0
, t0
, shift64
);
3685 /* result is [reg:..:reg:X] */
3687 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3688 tcg_gen_andi_i32(X
, lo
, 1);
3690 tcg_gen_shri_i32(lo
, lo
, 1);
3692 /* create [..:X:reg] */
3694 tcg_gen_concat_i32_i64(t0
, reg
, QREG_CC_X
);
3696 tcg_gen_rotr_i64(t0
, t0
, shift64
);
3698 /* result is value: [X:reg:..:reg] */
3700 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3704 tcg_gen_shri_i32(X
, hi
, 31);
3706 /* extract result */
3708 tcg_gen_shli_i32(hi
, hi
, 1);
3710 tcg_gen_or_i32(lo
, lo
, hi
);
3712 /* if shift == 0, register and X are not affected */
3714 zero
= tcg_constant_i32(0);
3715 tcg_gen_movcond_i32(TCG_COND_EQ
, X
, shift
, zero
, QREG_CC_X
, X
);
3716 tcg_gen_movcond_i32(TCG_COND_EQ
, reg
, shift
, zero
, reg
, lo
);
3721 DISAS_INSN(rotate_im
)
3725 int left
= (insn
& 0x100);
3727 tmp
= (insn
>> 9) & 7;
3732 shift
= tcg_constant_i32(tmp
);
3734 rotate(DREG(insn
, 0), shift
, left
, 32);
3736 TCGv X
= rotate32_x(DREG(insn
, 0), shift
, left
);
3737 rotate_x_flags(DREG(insn
, 0), X
, 32);
3740 set_cc_op(s
, CC_OP_FLAGS
);
3743 DISAS_INSN(rotate8_im
)
3745 int left
= (insn
& 0x100);
3750 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3752 tmp
= (insn
>> 9) & 7;
3757 shift
= tcg_constant_i32(tmp
);
3759 rotate(reg
, shift
, left
, 8);
3761 TCGv X
= rotate_x(reg
, shift
, left
, 8);
3762 rotate_x_flags(reg
, X
, 8);
3764 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3765 set_cc_op(s
, CC_OP_FLAGS
);
3768 DISAS_INSN(rotate16_im
)
3770 int left
= (insn
& 0x100);
3775 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
3776 tmp
= (insn
>> 9) & 7;
3781 shift
= tcg_constant_i32(tmp
);
3783 rotate(reg
, shift
, left
, 16);
3785 TCGv X
= rotate_x(reg
, shift
, left
, 16);
3786 rotate_x_flags(reg
, X
, 16);
3788 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3789 set_cc_op(s
, CC_OP_FLAGS
);
3792 DISAS_INSN(rotate_reg
)
3797 int left
= (insn
& 0x100);
3799 reg
= DREG(insn
, 0);
3800 src
= DREG(insn
, 9);
3801 /* shift in [0..63] */
3802 t0
= tcg_temp_new();
3803 tcg_gen_andi_i32(t0
, src
, 63);
3804 t1
= tcg_temp_new_i32();
3806 tcg_gen_andi_i32(t1
, src
, 31);
3807 rotate(reg
, t1
, left
, 32);
3808 /* if shift == 0, clear C */
3809 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3810 t0
, QREG_CC_V
/* 0 */,
3811 QREG_CC_V
/* 0 */, QREG_CC_C
);
3815 tcg_gen_movi_i32(t1
, 33);
3816 tcg_gen_remu_i32(t1
, t0
, t1
);
3817 X
= rotate32_x(DREG(insn
, 0), t1
, left
);
3818 rotate_x_flags(DREG(insn
, 0), X
, 32);
3820 set_cc_op(s
, CC_OP_FLAGS
);
3823 DISAS_INSN(rotate8_reg
)
3828 int left
= (insn
& 0x100);
3830 reg
= gen_extend(s
, DREG(insn
, 0), OS_BYTE
, 0);
3831 src
= DREG(insn
, 9);
3832 /* shift in [0..63] */
3833 t0
= tcg_temp_new_i32();
3834 tcg_gen_andi_i32(t0
, src
, 63);
3835 t1
= tcg_temp_new_i32();
3837 tcg_gen_andi_i32(t1
, src
, 7);
3838 rotate(reg
, t1
, left
, 8);
3839 /* if shift == 0, clear C */
3840 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3841 t0
, QREG_CC_V
/* 0 */,
3842 QREG_CC_V
/* 0 */, QREG_CC_C
);
3846 tcg_gen_movi_i32(t1
, 9);
3847 tcg_gen_remu_i32(t1
, t0
, t1
);
3848 X
= rotate_x(reg
, t1
, left
, 8);
3849 rotate_x_flags(reg
, X
, 8);
3851 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3852 set_cc_op(s
, CC_OP_FLAGS
);
3855 DISAS_INSN(rotate16_reg
)
3860 int left
= (insn
& 0x100);
3862 reg
= gen_extend(s
, DREG(insn
, 0), OS_WORD
, 0);
3863 src
= DREG(insn
, 9);
3864 /* shift in [0..63] */
3865 t0
= tcg_temp_new_i32();
3866 tcg_gen_andi_i32(t0
, src
, 63);
3867 t1
= tcg_temp_new_i32();
3869 tcg_gen_andi_i32(t1
, src
, 15);
3870 rotate(reg
, t1
, left
, 16);
3871 /* if shift == 0, clear C */
3872 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3873 t0
, QREG_CC_V
/* 0 */,
3874 QREG_CC_V
/* 0 */, QREG_CC_C
);
3878 tcg_gen_movi_i32(t1
, 17);
3879 tcg_gen_remu_i32(t1
, t0
, t1
);
3880 X
= rotate_x(reg
, t1
, left
, 16);
3881 rotate_x_flags(reg
, X
, 16);
3883 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3884 set_cc_op(s
, CC_OP_FLAGS
);
3887 DISAS_INSN(rotate_mem
)
3892 int left
= (insn
& 0x100);
3894 SRC_EA(env
, src
, OS_WORD
, 0, &addr
);
3896 shift
= tcg_constant_i32(1);
3897 if (insn
& 0x0200) {
3898 rotate(src
, shift
, left
, 16);
3900 TCGv X
= rotate_x(src
, shift
, left
, 16);
3901 rotate_x_flags(src
, X
, 16);
3903 DEST_EA(env
, insn
, OS_WORD
, src
, &addr
);
3904 set_cc_op(s
, CC_OP_FLAGS
);
3907 DISAS_INSN(bfext_reg
)
3909 int ext
= read_im16(env
, s
);
3910 int is_sign
= insn
& 0x200;
3911 TCGv src
= DREG(insn
, 0);
3912 TCGv dst
= DREG(ext
, 12);
3913 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
3914 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
3915 int pos
= 32 - ofs
- len
; /* little bit-endian */
3916 TCGv tmp
= tcg_temp_new();
3920 * In general, we're going to rotate the field so that it's at the
3921 * top of the word and then right-shift by the complement of the
3922 * width to extend the field.
3925 /* Variable width. */
3927 /* Variable offset. */
3928 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
3929 tcg_gen_rotl_i32(tmp
, src
, tmp
);
3931 tcg_gen_rotli_i32(tmp
, src
, ofs
);
3934 shift
= tcg_temp_new();
3935 tcg_gen_neg_i32(shift
, DREG(ext
, 0));
3936 tcg_gen_andi_i32(shift
, shift
, 31);
3937 tcg_gen_sar_i32(QREG_CC_N
, tmp
, shift
);
3939 tcg_gen_mov_i32(dst
, QREG_CC_N
);
3941 tcg_gen_shr_i32(dst
, tmp
, shift
);
3944 /* Immediate width. */
3946 /* Variable offset */
3947 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
3948 tcg_gen_rotl_i32(tmp
, src
, tmp
);
3953 * Immediate offset. If the field doesn't wrap around the
3954 * end of the word, rely on (s)extract completely.
3957 tcg_gen_rotli_i32(tmp
, src
, ofs
);
3963 tcg_gen_sextract_i32(QREG_CC_N
, src
, pos
, len
);
3965 tcg_gen_mov_i32(dst
, QREG_CC_N
);
3967 tcg_gen_extract_i32(dst
, src
, pos
, len
);
3971 set_cc_op(s
, CC_OP_LOGIC
);
3974 DISAS_INSN(bfext_mem
)
3976 int ext
= read_im16(env
, s
);
3977 int is_sign
= insn
& 0x200;
3978 TCGv dest
= DREG(ext
, 12);
3979 TCGv addr
, len
, ofs
;
3981 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
3982 if (IS_NULL_QREG(addr
)) {
3990 len
= tcg_constant_i32(extract32(ext
, 0, 5));
3995 ofs
= tcg_constant_i32(extract32(ext
, 6, 5));
3999 gen_helper_bfexts_mem(dest
, tcg_env
, addr
, ofs
, len
);
4000 tcg_gen_mov_i32(QREG_CC_N
, dest
);
4002 TCGv_i64 tmp
= tcg_temp_new_i64();
4003 gen_helper_bfextu_mem(tmp
, tcg_env
, addr
, ofs
, len
);
4004 tcg_gen_extr_i64_i32(dest
, QREG_CC_N
, tmp
);
4006 set_cc_op(s
, CC_OP_LOGIC
);
4009 DISAS_INSN(bfop_reg
)
4011 int ext
= read_im16(env
, s
);
4012 TCGv src
= DREG(insn
, 0);
4013 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4014 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4015 TCGv mask
, tofs
= NULL
, tlen
= NULL
;
4016 bool is_bfffo
= (insn
& 0x0f00) == 0x0d00;
4018 if ((ext
& 0x820) == 0) {
4019 /* Immediate width and offset. */
4020 uint32_t maski
= 0x7fffffffu
>> (len
- 1);
4021 if (ofs
+ len
<= 32) {
4022 tcg_gen_shli_i32(QREG_CC_N
, src
, ofs
);
4024 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4026 tcg_gen_andi_i32(QREG_CC_N
, QREG_CC_N
, ~maski
);
4028 mask
= tcg_constant_i32(ror32(maski
, ofs
));
4030 tofs
= tcg_constant_i32(ofs
);
4031 tlen
= tcg_constant_i32(len
);
4034 TCGv tmp
= tcg_temp_new();
4036 mask
= tcg_temp_new();
4038 /* Variable width */
4039 tcg_gen_subi_i32(tmp
, DREG(ext
, 0), 1);
4040 tcg_gen_andi_i32(tmp
, tmp
, 31);
4041 tcg_gen_shr_i32(mask
, tcg_constant_i32(0x7fffffffu
), tmp
);
4043 tlen
= tcg_temp_new();
4044 tcg_gen_addi_i32(tlen
, tmp
, 1);
4047 /* Immediate width */
4048 tcg_gen_movi_i32(mask
, 0x7fffffffu
>> (len
- 1));
4050 tlen
= tcg_constant_i32(len
);
4055 /* Variable offset */
4056 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
4057 tcg_gen_rotl_i32(QREG_CC_N
, src
, tmp
);
4058 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4059 tcg_gen_rotr_i32(mask
, mask
, tmp
);
4064 /* Immediate offset (and variable width) */
4065 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4066 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4067 tcg_gen_rotri_i32(mask
, mask
, ofs
);
4069 tofs
= tcg_constant_i32(ofs
);
4073 set_cc_op(s
, CC_OP_LOGIC
);
4075 switch (insn
& 0x0f00) {
4076 case 0x0a00: /* bfchg */
4077 tcg_gen_eqv_i32(src
, src
, mask
);
4079 case 0x0c00: /* bfclr */
4080 tcg_gen_and_i32(src
, src
, mask
);
4082 case 0x0d00: /* bfffo */
4083 gen_helper_bfffo_reg(DREG(ext
, 12), QREG_CC_N
, tofs
, tlen
);
4085 case 0x0e00: /* bfset */
4086 tcg_gen_orc_i32(src
, src
, mask
);
4088 case 0x0800: /* bftst */
4089 /* flags already set; no other work to do. */
4092 g_assert_not_reached();
4096 DISAS_INSN(bfop_mem
)
4098 int ext
= read_im16(env
, s
);
4099 TCGv addr
, len
, ofs
;
4102 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4103 if (IS_NULL_QREG(addr
)) {
4111 len
= tcg_constant_i32(extract32(ext
, 0, 5));
4116 ofs
= tcg_constant_i32(extract32(ext
, 6, 5));
4119 switch (insn
& 0x0f00) {
4120 case 0x0a00: /* bfchg */
4121 gen_helper_bfchg_mem(QREG_CC_N
, tcg_env
, addr
, ofs
, len
);
4123 case 0x0c00: /* bfclr */
4124 gen_helper_bfclr_mem(QREG_CC_N
, tcg_env
, addr
, ofs
, len
);
4126 case 0x0d00: /* bfffo */
4127 t64
= tcg_temp_new_i64();
4128 gen_helper_bfffo_mem(t64
, tcg_env
, addr
, ofs
, len
);
4129 tcg_gen_extr_i64_i32(DREG(ext
, 12), QREG_CC_N
, t64
);
4131 case 0x0e00: /* bfset */
4132 gen_helper_bfset_mem(QREG_CC_N
, tcg_env
, addr
, ofs
, len
);
4134 case 0x0800: /* bftst */
4135 gen_helper_bfexts_mem(QREG_CC_N
, tcg_env
, addr
, ofs
, len
);
4138 g_assert_not_reached();
4140 set_cc_op(s
, CC_OP_LOGIC
);
4143 DISAS_INSN(bfins_reg
)
4145 int ext
= read_im16(env
, s
);
4146 TCGv dst
= DREG(insn
, 0);
4147 TCGv src
= DREG(ext
, 12);
4148 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4149 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4150 int pos
= 32 - ofs
- len
; /* little bit-endian */
4153 tmp
= tcg_temp_new();
4156 /* Variable width */
4157 tcg_gen_neg_i32(tmp
, DREG(ext
, 0));
4158 tcg_gen_andi_i32(tmp
, tmp
, 31);
4159 tcg_gen_shl_i32(QREG_CC_N
, src
, tmp
);
4161 /* Immediate width */
4162 tcg_gen_shli_i32(QREG_CC_N
, src
, 32 - len
);
4164 set_cc_op(s
, CC_OP_LOGIC
);
4166 /* Immediate width and offset */
4167 if ((ext
& 0x820) == 0) {
4168 /* Check for suitability for deposit. */
4170 tcg_gen_deposit_i32(dst
, dst
, src
, pos
, len
);
4172 uint32_t maski
= -2U << (len
- 1);
4173 uint32_t roti
= (ofs
+ len
) & 31;
4174 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4175 tcg_gen_rotri_i32(tmp
, tmp
, roti
);
4176 tcg_gen_andi_i32(dst
, dst
, ror32(maski
, roti
));
4177 tcg_gen_or_i32(dst
, dst
, tmp
);
4180 TCGv mask
= tcg_temp_new();
4181 TCGv rot
= tcg_temp_new();
4184 /* Variable width */
4185 tcg_gen_subi_i32(rot
, DREG(ext
, 0), 1);
4186 tcg_gen_andi_i32(rot
, rot
, 31);
4187 tcg_gen_movi_i32(mask
, -2);
4188 tcg_gen_shl_i32(mask
, mask
, rot
);
4189 tcg_gen_mov_i32(rot
, DREG(ext
, 0));
4190 tcg_gen_andc_i32(tmp
, src
, mask
);
4192 /* Immediate width (variable offset) */
4193 uint32_t maski
= -2U << (len
- 1);
4194 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4195 tcg_gen_movi_i32(mask
, maski
);
4196 tcg_gen_movi_i32(rot
, len
& 31);
4199 /* Variable offset */
4200 tcg_gen_add_i32(rot
, rot
, DREG(ext
, 6));
4202 /* Immediate offset (variable width) */
4203 tcg_gen_addi_i32(rot
, rot
, ofs
);
4205 tcg_gen_andi_i32(rot
, rot
, 31);
4206 tcg_gen_rotr_i32(mask
, mask
, rot
);
4207 tcg_gen_rotr_i32(tmp
, tmp
, rot
);
4208 tcg_gen_and_i32(dst
, dst
, mask
);
4209 tcg_gen_or_i32(dst
, dst
, tmp
);
4213 DISAS_INSN(bfins_mem
)
4215 int ext
= read_im16(env
, s
);
4216 TCGv src
= DREG(ext
, 12);
4217 TCGv addr
, len
, ofs
;
4219 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4220 if (IS_NULL_QREG(addr
)) {
4228 len
= tcg_constant_i32(extract32(ext
, 0, 5));
4233 ofs
= tcg_constant_i32(extract32(ext
, 6, 5));
4236 gen_helper_bfins_mem(QREG_CC_N
, tcg_env
, addr
, src
, ofs
, len
);
4237 set_cc_op(s
, CC_OP_LOGIC
);
4243 reg
= DREG(insn
, 0);
4244 gen_logic_cc(s
, reg
, OS_LONG
);
4245 gen_helper_ff1(reg
, reg
);
4253 switch ((insn
>> 7) & 3) {
4258 if (m68k_feature(env
, M68K_FEATURE_CHK2
)) {
4264 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4267 SRC_EA(env
, src
, opsize
, 1, NULL
);
4268 reg
= gen_extend(s
, DREG(insn
, 9), opsize
, 1);
4271 gen_helper_chk(tcg_env
, reg
, src
);
4277 TCGv addr1
, addr2
, bound1
, bound2
, reg
;
4280 switch ((insn
>> 9) & 3) {
4291 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4295 ext
= read_im16(env
, s
);
4296 if ((ext
& 0x0800) == 0) {
4297 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4301 addr1
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4302 addr2
= tcg_temp_new();
4303 tcg_gen_addi_i32(addr2
, addr1
, opsize_bytes(opsize
));
4305 bound1
= gen_load(s
, opsize
, addr1
, 1, IS_USER(s
));
4306 bound2
= gen_load(s
, opsize
, addr2
, 1, IS_USER(s
));
4308 reg
= tcg_temp_new();
4310 tcg_gen_mov_i32(reg
, AREG(ext
, 12));
4312 gen_ext(reg
, DREG(ext
, 12), opsize
, 1);
4316 gen_helper_chk2(tcg_env
, reg
, bound1
, bound2
);
4319 static void m68k_copy_line(TCGv dst
, TCGv src
, int index
)
4324 addr
= tcg_temp_new();
4326 t0
= tcg_temp_new_i64();
4327 t1
= tcg_temp_new_i64();
4329 tcg_gen_andi_i32(addr
, src
, ~15);
4330 tcg_gen_qemu_ld_i64(t0
, addr
, index
, MO_TEUQ
);
4331 tcg_gen_addi_i32(addr
, addr
, 8);
4332 tcg_gen_qemu_ld_i64(t1
, addr
, index
, MO_TEUQ
);
4334 tcg_gen_andi_i32(addr
, dst
, ~15);
4335 tcg_gen_qemu_st_i64(t0
, addr
, index
, MO_TEUQ
);
4336 tcg_gen_addi_i32(addr
, addr
, 8);
4337 tcg_gen_qemu_st_i64(t1
, addr
, index
, MO_TEUQ
);
4340 DISAS_INSN(move16_reg
)
4342 int index
= IS_USER(s
);
4346 ext
= read_im16(env
, s
);
4347 if ((ext
& (1 << 15)) == 0) {
4348 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4351 m68k_copy_line(AREG(ext
, 12), AREG(insn
, 0), index
);
4353 /* Ax can be Ay, so save Ay before incrementing Ax */
4354 tmp
= tcg_temp_new();
4355 tcg_gen_mov_i32(tmp
, AREG(ext
, 12));
4356 tcg_gen_addi_i32(AREG(insn
, 0), AREG(insn
, 0), 16);
4357 tcg_gen_addi_i32(AREG(ext
, 12), tmp
, 16);
4360 DISAS_INSN(move16_mem
)
4362 int index
= IS_USER(s
);
4365 reg
= AREG(insn
, 0);
4366 addr
= tcg_constant_i32(read_im32(env
, s
));
4368 if ((insn
>> 3) & 1) {
4369 /* MOVE16 (xxx).L, (Ay) */
4370 m68k_copy_line(reg
, addr
, index
);
4372 /* MOVE16 (Ay), (xxx).L */
4373 m68k_copy_line(addr
, reg
, index
);
4376 if (((insn
>> 3) & 2) == 0) {
4378 tcg_gen_addi_i32(reg
, reg
, 16);
4388 ext
= read_im16(env
, s
);
4389 if (ext
!= 0x46FC) {
4390 gen_exception(s
, addr
, EXCP_ILLEGAL
);
4393 ext
= read_im16(env
, s
);
4394 if (IS_USER(s
) || (ext
& SR_S
) == 0) {
4395 gen_exception(s
, addr
, EXCP_PRIVILEGE
);
4398 gen_push(s
, gen_get_sr(s
));
4399 gen_set_sr_im(s
, ext
, 0);
4403 DISAS_INSN(move_from_sr
)
4407 if (IS_USER(s
) && m68k_feature(env
, M68K_FEATURE_MOVEFROMSR_PRIV
)) {
4408 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4412 DEST_EA(env
, insn
, OS_WORD
, sr
, NULL
);
4415 #if !defined(CONFIG_USER_ONLY)
4425 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4429 ext
= read_im16(env
, s
);
4431 opsize
= insn_opsize(insn
);
4434 /* address register */
4435 reg
= AREG(ext
, 12);
4439 reg
= DREG(ext
, 12);
4443 addr
= gen_lea(env
, s
, insn
, opsize
);
4444 if (IS_NULL_QREG(addr
)) {
4450 /* from reg to ea */
4451 gen_store(s
, opsize
, addr
, reg
, DFC_INDEX(s
));
4453 /* from ea to reg */
4454 TCGv tmp
= gen_load(s
, opsize
, addr
, 0, SFC_INDEX(s
));
4456 gen_ext(reg
, tmp
, opsize
, 1);
4458 gen_partset_reg(opsize
, reg
, tmp
);
4461 switch (extract32(insn
, 3, 3)) {
4462 case 3: /* Indirect postincrement. */
4463 tcg_gen_addi_i32(AREG(insn
, 0), addr
,
4464 REG(insn
, 0) == 7 && opsize
== OS_BYTE
4466 : opsize_bytes(opsize
));
4468 case 4: /* Indirect predecrememnt. */
4469 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4474 DISAS_INSN(move_to_sr
)
4477 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4480 gen_move_to_sr(env
, s
, insn
, false);
4484 DISAS_INSN(move_from_usp
)
4487 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4490 tcg_gen_ld_i32(AREG(insn
, 0), tcg_env
,
4491 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4494 DISAS_INSN(move_to_usp
)
4497 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4500 tcg_gen_st_i32(AREG(insn
, 0), tcg_env
,
4501 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4507 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4510 if (semihosting_test(s
)) {
4511 gen_exception(s
, s
->pc
, EXCP_SEMIHOSTING
);
4514 tcg_gen_movi_i32(cpu_halted
, 1);
4515 gen_exception(s
, s
->pc
, EXCP_HLT
);
4523 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4527 ext
= read_im16(env
, s
);
4529 gen_set_sr_im(s
, ext
, 0);
4530 tcg_gen_movi_i32(cpu_halted
, 1);
4531 gen_exception(s
, s
->pc
, EXCP_HLT
);
4537 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4540 gen_exception(s
, s
->base
.pc_next
, EXCP_RTE
);
4543 DISAS_INSN(cf_movec
)
4549 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4553 ext
= read_im16(env
, s
);
4556 reg
= AREG(ext
, 12);
4558 reg
= DREG(ext
, 12);
4560 gen_helper_cf_movec_to(tcg_env
, tcg_constant_i32(ext
& 0xfff), reg
);
4564 DISAS_INSN(m68k_movec
)
4570 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4574 ext
= read_im16(env
, s
);
4577 reg
= AREG(ext
, 12);
4579 reg
= DREG(ext
, 12);
4581 creg
= tcg_constant_i32(ext
& 0xfff);
4583 gen_helper_m68k_movec_to(tcg_env
, creg
, reg
);
4585 gen_helper_m68k_movec_from(reg
, tcg_env
, creg
);
4593 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4596 /* ICache fetch. Implement as no-op. */
4602 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4605 /* Cache push/invalidate. Implement as no-op. */
4611 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4614 /* Cache push/invalidate. Implement as no-op. */
4620 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4623 /* Invalidate cache line. Implement as no-op. */
4626 #if !defined(CONFIG_USER_ONLY)
4632 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4636 opmode
= tcg_constant_i32((insn
>> 3) & 3);
4637 gen_helper_pflush(tcg_env
, AREG(insn
, 0), opmode
);
4645 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4648 is_read
= tcg_constant_i32((insn
>> 5) & 1);
4649 gen_helper_ptest(tcg_env
, AREG(insn
, 0), is_read
);
4655 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4661 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
4664 /* TODO: Implement wdebug. */
4665 cpu_abort(env_cpu(env
), "WDEBUG not implemented");
4671 gen_exception(s
, s
->pc
, EXCP_TRAP0
+ (insn
& 0xf));
4674 static void do_trapcc(DisasContext
*s
, DisasCompare
*c
)
4676 if (c
->tcond
!= TCG_COND_NEVER
) {
4677 TCGLabel
*over
= NULL
;
4681 if (c
->tcond
!= TCG_COND_ALWAYS
) {
4682 /* Jump over if !c. */
4683 over
= gen_new_label();
4684 tcg_gen_brcond_i32(tcg_invert_cond(c
->tcond
), c
->v1
, c
->v2
, over
);
4687 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
4688 gen_raise_exception_format2(s
, EXCP_TRAPCC
, s
->base
.pc_next
);
4691 gen_set_label(over
);
4692 s
->base
.is_jmp
= DISAS_NEXT
;
4701 /* Consume and discard the immediate operand. */
4702 switch (extract32(insn
, 0, 3)) {
4703 case 2: /* trapcc.w */
4704 (void)read_im16(env
, s
);
4706 case 3: /* trapcc.l */
4707 (void)read_im32(env
, s
);
4709 case 4: /* trapcc (no operand) */
4712 /* trapcc registered with only valid opmodes */
4713 g_assert_not_reached();
4716 gen_cc_cond(&c
, s
, extract32(insn
, 8, 4));
4724 gen_cc_cond(&c
, s
, 9); /* V set */
4728 static void gen_load_fcr(DisasContext
*s
, TCGv res
, int reg
)
4732 tcg_gen_movi_i32(res
, 0);
4735 gen_helper_get_fpsr(res
, tcg_env
);
4738 tcg_gen_ld_i32(res
, tcg_env
, offsetof(CPUM68KState
, fpcr
));
4743 static void gen_store_fcr(DisasContext
*s
, TCGv val
, int reg
)
4749 gen_helper_set_fpsr(tcg_env
, val
);
4752 gen_helper_set_fpcr(tcg_env
, val
);
4757 static void gen_qemu_store_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4759 int index
= IS_USER(s
);
4762 tmp
= tcg_temp_new();
4763 gen_load_fcr(s
, tmp
, reg
);
4764 tcg_gen_qemu_st_tl(tmp
, addr
, index
, MO_TEUL
);
4767 static void gen_qemu_load_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4769 int index
= IS_USER(s
);
4772 tmp
= tcg_temp_new();
4773 tcg_gen_qemu_ld_tl(tmp
, addr
, index
, MO_TEUL
);
4774 gen_store_fcr(s
, tmp
, reg
);
4778 static void gen_op_fmove_fcr(CPUM68KState
*env
, DisasContext
*s
,
4779 uint32_t insn
, uint32_t ext
)
4781 int mask
= (ext
>> 10) & 7;
4782 int is_write
= (ext
>> 13) & 1;
4783 int mode
= extract32(insn
, 3, 3);
4789 if (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&& mask
!= M68K_FPCR
) {
4790 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4794 gen_load_fcr(s
, DREG(insn
, 0), mask
);
4796 gen_store_fcr(s
, DREG(insn
, 0), mask
);
4799 case 1: /* An, only with FPIAR */
4800 if (mask
!= M68K_FPIAR
) {
4801 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4805 gen_load_fcr(s
, AREG(insn
, 0), mask
);
4807 gen_store_fcr(s
, AREG(insn
, 0), mask
);
4810 case 7: /* Immediate */
4811 if (REG(insn
, 0) == 4) {
4813 (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&&
4814 mask
!= M68K_FPCR
)) {
4815 gen_exception(s
, s
->base
.pc_next
, EXCP_ILLEGAL
);
4818 tmp
= tcg_constant_i32(read_im32(env
, s
));
4819 gen_store_fcr(s
, tmp
, mask
);
4827 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
4828 if (IS_NULL_QREG(tmp
)) {
4833 addr
= tcg_temp_new();
4834 tcg_gen_mov_i32(addr
, tmp
);
4839 * 0b100 Floating-Point Control Register
4840 * 0b010 Floating-Point Status Register
4841 * 0b001 Floating-Point Instruction Address Register
4845 if (is_write
&& mode
== 4) {
4846 for (i
= 2; i
>= 0; i
--, mask
>>= 1) {
4848 gen_qemu_store_fcr(s
, addr
, 1 << i
);
4850 tcg_gen_subi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
4854 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4856 for (i
= 0; i
< 3; i
++, mask
>>= 1) {
4859 gen_qemu_store_fcr(s
, addr
, 1 << i
);
4861 gen_qemu_load_fcr(s
, addr
, 1 << i
);
4863 if (mask
!= 1 || mode
== 3) {
4864 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
4869 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4874 static void gen_op_fmovem(CPUM68KState
*env
, DisasContext
*s
,
4875 uint32_t insn
, uint32_t ext
)
4879 int mode
= (ext
>> 11) & 0x3;
4880 int is_load
= ((ext
& 0x2000) == 0);
4882 if (m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
4883 opsize
= OS_EXTENDED
;
4885 opsize
= OS_DOUBLE
; /* FIXME */
4888 addr
= gen_lea(env
, s
, insn
, opsize
);
4889 if (IS_NULL_QREG(addr
)) {
4894 tmp
= tcg_temp_new();
4896 /* Dynamic register list */
4897 tcg_gen_ext8u_i32(tmp
, DREG(ext
, 4));
4899 /* Static register list */
4900 tcg_gen_movi_i32(tmp
, ext
& 0xff);
4903 if (!is_load
&& (mode
& 2) == 0) {
4905 * predecrement addressing mode
4906 * only available to store register to memory
4908 if (opsize
== OS_EXTENDED
) {
4909 gen_helper_fmovemx_st_predec(tmp
, tcg_env
, addr
, tmp
);
4911 gen_helper_fmovemd_st_predec(tmp
, tcg_env
, addr
, tmp
);
4914 /* postincrement addressing mode */
4915 if (opsize
== OS_EXTENDED
) {
4917 gen_helper_fmovemx_ld_postinc(tmp
, tcg_env
, addr
, tmp
);
4919 gen_helper_fmovemx_st_postinc(tmp
, tcg_env
, addr
, tmp
);
4923 gen_helper_fmovemd_ld_postinc(tmp
, tcg_env
, addr
, tmp
);
4925 gen_helper_fmovemd_st_postinc(tmp
, tcg_env
, addr
, tmp
);
4929 if ((insn
& 070) == 030 || (insn
& 070) == 040) {
4930 tcg_gen_mov_i32(AREG(insn
, 0), tmp
);
4935 * ??? FP exceptions are not implemented. Most exceptions are deferred until
4936 * immediately before the next FP instruction is executed.
4943 TCGv_ptr cpu_src
, cpu_dest
;
4945 ext
= read_im16(env
, s
);
4946 opmode
= ext
& 0x7f;
4947 switch ((ext
>> 13) & 7) {
4953 if (insn
== 0xf200 && (ext
& 0xfc00) == 0x5c00) {
4955 TCGv rom_offset
= tcg_constant_i32(opmode
);
4956 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
4957 gen_helper_fconst(tcg_env
, cpu_dest
, rom_offset
);
4961 case 3: /* fmove out */
4962 cpu_src
= gen_fp_ptr(REG(ext
, 7));
4963 opsize
= ext_opsize(ext
, 10);
4964 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
4965 EA_STORE
, IS_USER(s
)) == -1) {
4968 gen_helper_ftst(tcg_env
, cpu_src
);
4970 case 4: /* fmove to control register. */
4971 case 5: /* fmove from control register. */
4972 gen_op_fmove_fcr(env
, s
, insn
, ext
);
4974 case 6: /* fmovem */
4976 if ((ext
& 0x1000) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
4979 gen_op_fmovem(env
, s
, insn
, ext
);
4982 if (ext
& (1 << 14)) {
4983 /* Source effective address. */
4984 opsize
= ext_opsize(ext
, 10);
4985 cpu_src
= gen_fp_result_ptr();
4986 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
,
4987 EA_LOADS
, IS_USER(s
)) == -1) {
4992 /* Source register. */
4993 opsize
= OS_EXTENDED
;
4994 cpu_src
= gen_fp_ptr(REG(ext
, 10));
4996 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
4999 gen_fp_move(cpu_dest
, cpu_src
);
5001 case 0x40: /* fsmove */
5002 gen_helper_fsround(tcg_env
, cpu_dest
, cpu_src
);
5004 case 0x44: /* fdmove */
5005 gen_helper_fdround(tcg_env
, cpu_dest
, cpu_src
);
5008 gen_helper_firound(tcg_env
, cpu_dest
, cpu_src
);
5011 gen_helper_fsinh(tcg_env
, cpu_dest
, cpu_src
);
5013 case 3: /* fintrz */
5014 gen_helper_fitrunc(tcg_env
, cpu_dest
, cpu_src
);
5017 gen_helper_fsqrt(tcg_env
, cpu_dest
, cpu_src
);
5019 case 0x41: /* fssqrt */
5020 gen_helper_fssqrt(tcg_env
, cpu_dest
, cpu_src
);
5022 case 0x45: /* fdsqrt */
5023 gen_helper_fdsqrt(tcg_env
, cpu_dest
, cpu_src
);
5025 case 0x06: /* flognp1 */
5026 gen_helper_flognp1(tcg_env
, cpu_dest
, cpu_src
);
5028 case 0x08: /* fetoxm1 */
5029 gen_helper_fetoxm1(tcg_env
, cpu_dest
, cpu_src
);
5031 case 0x09: /* ftanh */
5032 gen_helper_ftanh(tcg_env
, cpu_dest
, cpu_src
);
5034 case 0x0a: /* fatan */
5035 gen_helper_fatan(tcg_env
, cpu_dest
, cpu_src
);
5037 case 0x0c: /* fasin */
5038 gen_helper_fasin(tcg_env
, cpu_dest
, cpu_src
);
5040 case 0x0d: /* fatanh */
5041 gen_helper_fatanh(tcg_env
, cpu_dest
, cpu_src
);
5043 case 0x0e: /* fsin */
5044 gen_helper_fsin(tcg_env
, cpu_dest
, cpu_src
);
5046 case 0x0f: /* ftan */
5047 gen_helper_ftan(tcg_env
, cpu_dest
, cpu_src
);
5049 case 0x10: /* fetox */
5050 gen_helper_fetox(tcg_env
, cpu_dest
, cpu_src
);
5052 case 0x11: /* ftwotox */
5053 gen_helper_ftwotox(tcg_env
, cpu_dest
, cpu_src
);
5055 case 0x12: /* ftentox */
5056 gen_helper_ftentox(tcg_env
, cpu_dest
, cpu_src
);
5058 case 0x14: /* flogn */
5059 gen_helper_flogn(tcg_env
, cpu_dest
, cpu_src
);
5061 case 0x15: /* flog10 */
5062 gen_helper_flog10(tcg_env
, cpu_dest
, cpu_src
);
5064 case 0x16: /* flog2 */
5065 gen_helper_flog2(tcg_env
, cpu_dest
, cpu_src
);
5067 case 0x18: /* fabs */
5068 gen_helper_fabs(tcg_env
, cpu_dest
, cpu_src
);
5070 case 0x58: /* fsabs */
5071 gen_helper_fsabs(tcg_env
, cpu_dest
, cpu_src
);
5073 case 0x5c: /* fdabs */
5074 gen_helper_fdabs(tcg_env
, cpu_dest
, cpu_src
);
5076 case 0x19: /* fcosh */
5077 gen_helper_fcosh(tcg_env
, cpu_dest
, cpu_src
);
5079 case 0x1a: /* fneg */
5080 gen_helper_fneg(tcg_env
, cpu_dest
, cpu_src
);
5082 case 0x5a: /* fsneg */
5083 gen_helper_fsneg(tcg_env
, cpu_dest
, cpu_src
);
5085 case 0x5e: /* fdneg */
5086 gen_helper_fdneg(tcg_env
, cpu_dest
, cpu_src
);
5088 case 0x1c: /* facos */
5089 gen_helper_facos(tcg_env
, cpu_dest
, cpu_src
);
5091 case 0x1d: /* fcos */
5092 gen_helper_fcos(tcg_env
, cpu_dest
, cpu_src
);
5094 case 0x1e: /* fgetexp */
5095 gen_helper_fgetexp(tcg_env
, cpu_dest
, cpu_src
);
5097 case 0x1f: /* fgetman */
5098 gen_helper_fgetman(tcg_env
, cpu_dest
, cpu_src
);
5100 case 0x20: /* fdiv */
5101 gen_helper_fdiv(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5103 case 0x60: /* fsdiv */
5104 gen_helper_fsdiv(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5106 case 0x64: /* fddiv */
5107 gen_helper_fddiv(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5109 case 0x21: /* fmod */
5110 gen_helper_fmod(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5112 case 0x22: /* fadd */
5113 gen_helper_fadd(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5115 case 0x62: /* fsadd */
5116 gen_helper_fsadd(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5118 case 0x66: /* fdadd */
5119 gen_helper_fdadd(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5121 case 0x23: /* fmul */
5122 gen_helper_fmul(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5124 case 0x63: /* fsmul */
5125 gen_helper_fsmul(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5127 case 0x67: /* fdmul */
5128 gen_helper_fdmul(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5130 case 0x24: /* fsgldiv */
5131 gen_helper_fsgldiv(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5133 case 0x25: /* frem */
5134 gen_helper_frem(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5136 case 0x26: /* fscale */
5137 gen_helper_fscale(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5139 case 0x27: /* fsglmul */
5140 gen_helper_fsglmul(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5142 case 0x28: /* fsub */
5143 gen_helper_fsub(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5145 case 0x68: /* fssub */
5146 gen_helper_fssub(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5148 case 0x6c: /* fdsub */
5149 gen_helper_fdsub(tcg_env
, cpu_dest
, cpu_src
, cpu_dest
);
5151 case 0x30: case 0x31: case 0x32:
5152 case 0x33: case 0x34: case 0x35:
5153 case 0x36: case 0x37: {
5154 TCGv_ptr cpu_dest2
= gen_fp_ptr(REG(ext
, 0));
5155 gen_helper_fsincos(tcg_env
, cpu_dest
, cpu_dest2
, cpu_src
);
5158 case 0x38: /* fcmp */
5159 gen_helper_fcmp(tcg_env
, cpu_src
, cpu_dest
);
5161 case 0x3a: /* ftst */
5162 gen_helper_ftst(tcg_env
, cpu_src
);
5167 gen_helper_ftst(tcg_env
, cpu_dest
);
5170 /* FIXME: Is this right for offset addressing modes? */
5172 disas_undef_fpu(env
, s
, insn
);
5175 static void gen_fcc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
5180 /* TODO: Raise BSUN exception. */
5181 fpsr
= tcg_temp_new();
5182 gen_load_fcr(s
, fpsr
, M68K_FPSR
);
5187 case 16: /* Signaling False */
5188 c
->tcond
= TCG_COND_NEVER
;
5190 case 1: /* EQual Z */
5191 case 17: /* Signaling EQual Z */
5193 c
->tcond
= TCG_COND_TSTNE
;
5195 case 2: /* Ordered Greater Than !(A || Z || N) */
5196 case 18: /* Greater Than !(A || Z || N) */
5197 imm
= FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
;
5198 c
->tcond
= TCG_COND_TSTEQ
;
5200 case 3: /* Ordered Greater than or Equal Z || !(A || N) */
5201 case 19: /* Greater than or Equal Z || !(A || N) */
5202 c
->v1
= tcg_temp_new();
5203 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5204 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
5205 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5206 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5207 imm
= FPSR_CC_Z
| FPSR_CC_N
;
5208 c
->tcond
= TCG_COND_TSTNE
;
5210 case 4: /* Ordered Less Than !(!N || A || Z); */
5211 case 20: /* Less Than !(!N || A || Z); */
5212 c
->v1
= tcg_temp_new();
5213 tcg_gen_xori_i32(c
->v1
, fpsr
, FPSR_CC_N
);
5214 imm
= FPSR_CC_N
| FPSR_CC_A
| FPSR_CC_Z
;
5215 c
->tcond
= TCG_COND_TSTEQ
;
5217 case 5: /* Ordered Less than or Equal Z || (N && !A) */
5218 case 21: /* Less than or Equal Z || (N && !A) */
5219 c
->v1
= tcg_temp_new();
5220 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
5221 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
5222 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5223 imm
= FPSR_CC_Z
| FPSR_CC_N
;
5224 c
->tcond
= TCG_COND_TSTNE
;
5226 case 6: /* Ordered Greater or Less than !(A || Z) */
5227 case 22: /* Greater or Less than !(A || Z) */
5228 imm
= FPSR_CC_A
| FPSR_CC_Z
;
5229 c
->tcond
= TCG_COND_TSTEQ
;
5231 case 7: /* Ordered !A */
5232 case 23: /* Greater, Less or Equal !A */
5234 c
->tcond
= TCG_COND_TSTEQ
;
5236 case 8: /* Unordered A */
5237 case 24: /* Not Greater, Less or Equal A */
5239 c
->tcond
= TCG_COND_TSTNE
;
5241 case 9: /* Unordered or Equal A || Z */
5242 case 25: /* Not Greater or Less then A || Z */
5243 imm
= FPSR_CC_A
| FPSR_CC_Z
;
5244 c
->tcond
= TCG_COND_TSTNE
;
5246 case 10: /* Unordered or Greater Than A || !(N || Z)) */
5247 case 26: /* Not Less or Equal A || !(N || Z)) */
5248 c
->v1
= tcg_temp_new();
5249 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5250 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
5251 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
5252 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
5253 imm
= FPSR_CC_A
| FPSR_CC_N
;
5254 c
->tcond
= TCG_COND_TSTNE
;
5256 case 11: /* Unordered or Greater or Equal A || Z || !N */
5257 case 27: /* Not Less Than A || Z || !N */
5258 c
->v1
= tcg_temp_new();
5259 tcg_gen_xori_i32(c
->v1
, fpsr
, FPSR_CC_N
);
5260 imm
= FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
;
5261 c
->tcond
= TCG_COND_TSTNE
;
5263 case 12: /* Unordered or Less Than A || (N && !Z) */
5264 case 28: /* Not Greater than or Equal A || (N && !Z) */
5265 c
->v1
= tcg_temp_new();
5266 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
5267 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
5268 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
5269 imm
= FPSR_CC_A
| FPSR_CC_N
;
5270 c
->tcond
= TCG_COND_TSTNE
;
5272 case 13: /* Unordered or Less or Equal A || Z || N */
5273 case 29: /* Not Greater Than A || Z || N */
5274 imm
= FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
;
5275 c
->tcond
= TCG_COND_TSTNE
;
5277 case 14: /* Not Equal !Z */
5278 case 30: /* Signaling Not Equal !Z */
5280 c
->tcond
= TCG_COND_TSTEQ
;
5283 case 31: /* Signaling True */
5284 c
->tcond
= TCG_COND_ALWAYS
;
5287 c
->v2
= tcg_constant_i32(imm
);
5290 static void gen_fjmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
5294 gen_fcc_cond(&c
, s
, cond
);
5296 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
5306 offset
= (int16_t)read_im16(env
, s
);
5307 if (insn
& (1 << 6)) {
5308 offset
= (offset
<< 16) | read_im16(env
, s
);
5311 l1
= gen_new_label();
5313 gen_fjmpcc(s
, insn
& 0x3f, l1
);
5314 gen_jmp_tb(s
, 0, s
->pc
, s
->base
.pc_next
);
5316 gen_jmp_tb(s
, 1, base
+ offset
, s
->base
.pc_next
);
5326 ext
= read_im16(env
, s
);
5328 gen_fcc_cond(&c
, s
, cond
);
5330 tmp
= tcg_temp_new();
5331 tcg_gen_negsetcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
5333 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
5342 ext
= read_im16(env
, s
);
5345 /* Consume and discard the immediate operand. */
5346 switch (extract32(insn
, 0, 3)) {
5347 case 2: /* ftrapcc.w */
5348 (void)read_im16(env
, s
);
5350 case 3: /* ftrapcc.l */
5351 (void)read_im32(env
, s
);
5353 case 4: /* ftrapcc (no operand) */
5356 /* ftrapcc registered with only valid opmodes */
5357 g_assert_not_reached();
5360 gen_fcc_cond(&c
, s
, cond
);
5364 #if !defined(CONFIG_USER_ONLY)
5365 DISAS_INSN(frestore
)
5370 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5373 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5374 SRC_EA(env
, addr
, OS_LONG
, 0, NULL
);
5375 /* FIXME: check the state frame */
5377 disas_undef(env
, s
, insn
);
5384 gen_exception(s
, s
->base
.pc_next
, EXCP_PRIVILEGE
);
5388 if (m68k_feature(s
->env
, M68K_FEATURE_M68040
)) {
5389 /* always write IDLE */
5390 TCGv idle
= tcg_constant_i32(0x41000000);
5391 DEST_EA(env
, insn
, OS_LONG
, idle
, NULL
);
5393 disas_undef(env
, s
, insn
);
5398 static inline TCGv
gen_mac_extract_word(DisasContext
*s
, TCGv val
, int upper
)
5400 TCGv tmp
= tcg_temp_new();
5401 if (s
->env
->macsr
& MACSR_FI
) {
5403 tcg_gen_andi_i32(tmp
, val
, 0xffff0000);
5405 tcg_gen_shli_i32(tmp
, val
, 16);
5406 } else if (s
->env
->macsr
& MACSR_SU
) {
5408 tcg_gen_sari_i32(tmp
, val
, 16);
5410 tcg_gen_ext16s_i32(tmp
, val
);
5413 tcg_gen_shri_i32(tmp
, val
, 16);
5415 tcg_gen_ext16u_i32(tmp
, val
);
5420 static void gen_mac_clear_flags(void)
5422 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
,
5423 ~(MACSR_V
| MACSR_Z
| MACSR_N
| MACSR_EV
));
5439 s
->mactmp
= tcg_temp_new_i64();
5443 ext
= read_im16(env
, s
);
5445 acc
= ((insn
>> 7) & 1) | ((ext
>> 3) & 2);
5446 dual
= ((insn
& 0x30) != 0 && (ext
& 3) != 0);
5447 if (dual
&& !m68k_feature(s
->env
, M68K_FEATURE_CF_EMAC_B
)) {
5448 disas_undef(env
, s
, insn
);
5452 /* MAC with load. */
5453 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
5454 addr
= tcg_temp_new();
5455 tcg_gen_and_i32(addr
, tmp
, QREG_MAC_MASK
);
5457 * Load the value now to ensure correct exception behavior.
5458 * Perform writeback after reading the MAC inputs.
5460 loadval
= gen_load(s
, OS_LONG
, addr
, 0, IS_USER(s
));
5463 rx
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(insn
, 12);
5464 ry
= (ext
& 8) ? AREG(ext
, 0) : DREG(ext
, 0);
5466 loadval
= addr
= NULL_QREG
;
5467 rx
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5468 ry
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5471 gen_mac_clear_flags();
5474 /* Disabled because conditional branches clobber temporary vars. */
5475 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && !dual
) {
5476 /* Skip the multiply if we know we will ignore it. */
5477 l1
= gen_new_label();
5478 tmp
= tcg_temp_new();
5479 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 1 << (acc
+ 8));
5480 gen_op_jmp_nz32(tmp
, l1
);
5484 if ((ext
& 0x0800) == 0) {
5486 rx
= gen_mac_extract_word(s
, rx
, (ext
& 0x80) != 0);
5487 ry
= gen_mac_extract_word(s
, ry
, (ext
& 0x40) != 0);
5489 if (s
->env
->macsr
& MACSR_FI
) {
5490 gen_helper_macmulf(s
->mactmp
, tcg_env
, rx
, ry
);
5492 if (s
->env
->macsr
& MACSR_SU
)
5493 gen_helper_macmuls(s
->mactmp
, tcg_env
, rx
, ry
);
5495 gen_helper_macmulu(s
->mactmp
, tcg_env
, rx
, ry
);
5496 switch ((ext
>> 9) & 3) {
5498 tcg_gen_shli_i64(s
->mactmp
, s
->mactmp
, 1);
5501 tcg_gen_shri_i64(s
->mactmp
, s
->mactmp
, 1);
5507 /* Save the overflow flag from the multiply. */
5508 saved_flags
= tcg_temp_new();
5509 tcg_gen_mov_i32(saved_flags
, QREG_MACSR
);
5511 saved_flags
= NULL_QREG
;
5515 /* Disabled because conditional branches clobber temporary vars. */
5516 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && dual
) {
5517 /* Skip the accumulate if the value is already saturated. */
5518 l1
= gen_new_label();
5519 tmp
= tcg_temp_new();
5520 gen_op_and32(tmp
, QREG_MACSR
, tcg_constant_i32(MACSR_PAV0
<< acc
));
5521 gen_op_jmp_nz32(tmp
, l1
);
5526 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5528 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5530 if (s
->env
->macsr
& MACSR_FI
)
5531 gen_helper_macsatf(tcg_env
, tcg_constant_i32(acc
));
5532 else if (s
->env
->macsr
& MACSR_SU
)
5533 gen_helper_macsats(tcg_env
, tcg_constant_i32(acc
));
5535 gen_helper_macsatu(tcg_env
, tcg_constant_i32(acc
));
5538 /* Disabled because conditional branches clobber temporary vars. */
5544 /* Dual accumulate variant. */
5545 acc
= (ext
>> 2) & 3;
5546 /* Restore the overflow flag from the multiplier. */
5547 tcg_gen_mov_i32(QREG_MACSR
, saved_flags
);
5549 /* Disabled because conditional branches clobber temporary vars. */
5550 if ((s
->env
->macsr
& MACSR_OMC
) != 0) {
5551 /* Skip the accumulate if the value is already saturated. */
5552 l1
= gen_new_label();
5553 tmp
= tcg_temp_new();
5554 gen_op_and32(tmp
, QREG_MACSR
, tcg_constant_i32(MACSR_PAV0
<< acc
));
5555 gen_op_jmp_nz32(tmp
, l1
);
5559 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5561 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5562 if (s
->env
->macsr
& MACSR_FI
)
5563 gen_helper_macsatf(tcg_env
, tcg_constant_i32(acc
));
5564 else if (s
->env
->macsr
& MACSR_SU
)
5565 gen_helper_macsats(tcg_env
, tcg_constant_i32(acc
));
5567 gen_helper_macsatu(tcg_env
, tcg_constant_i32(acc
));
5569 /* Disabled because conditional branches clobber temporary vars. */
5574 gen_helper_mac_set_flags(tcg_env
, tcg_constant_i32(acc
));
5578 rw
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5579 tcg_gen_mov_i32(rw
, loadval
);
5581 * FIXME: Should address writeback happen with the masked or
5584 switch ((insn
>> 3) & 7) {
5585 case 3: /* Post-increment. */
5586 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 4);
5588 case 4: /* Pre-decrement. */
5589 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5594 DISAS_INSN(from_mac
)
5600 rx
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5601 accnum
= (insn
>> 9) & 3;
5602 acc
= MACREG(accnum
);
5603 if (s
->env
->macsr
& MACSR_FI
) {
5604 gen_helper_get_macf(rx
, tcg_env
, acc
);
5605 } else if ((s
->env
->macsr
& MACSR_OMC
) == 0) {
5606 tcg_gen_extrl_i64_i32(rx
, acc
);
5607 } else if (s
->env
->macsr
& MACSR_SU
) {
5608 gen_helper_get_macs(rx
, acc
);
5610 gen_helper_get_macu(rx
, acc
);
5613 tcg_gen_movi_i64(acc
, 0);
5614 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5618 DISAS_INSN(move_mac
)
5620 /* FIXME: This can be done without a helper. */
5624 dest
= tcg_constant_i32((insn
>> 9) & 3);
5625 gen_helper_mac_move(tcg_env
, dest
, tcg_constant_i32(src
));
5626 gen_mac_clear_flags();
5627 gen_helper_mac_set_flags(tcg_env
, dest
);
5630 DISAS_INSN(from_macsr
)
5634 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5635 tcg_gen_mov_i32(reg
, QREG_MACSR
);
5638 DISAS_INSN(from_mask
)
5641 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5642 tcg_gen_mov_i32(reg
, QREG_MAC_MASK
);
5645 DISAS_INSN(from_mext
)
5649 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5650 acc
= tcg_constant_i32((insn
& 0x400) ? 2 : 0);
5651 if (s
->env
->macsr
& MACSR_FI
)
5652 gen_helper_get_mac_extf(reg
, tcg_env
, acc
);
5654 gen_helper_get_mac_exti(reg
, tcg_env
, acc
);
5657 DISAS_INSN(macsr_to_ccr
)
5659 TCGv tmp
= tcg_temp_new();
5661 /* Note that X and C are always cleared. */
5662 tcg_gen_andi_i32(tmp
, QREG_MACSR
, CCF_N
| CCF_Z
| CCF_V
);
5663 gen_helper_set_ccr(tcg_env
, tmp
);
5664 set_cc_op(s
, CC_OP_FLAGS
);
5672 accnum
= (insn
>> 9) & 3;
5673 acc
= MACREG(accnum
);
5674 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5675 if (s
->env
->macsr
& MACSR_FI
) {
5676 tcg_gen_ext_i32_i64(acc
, val
);
5677 tcg_gen_shli_i64(acc
, acc
, 8);
5678 } else if (s
->env
->macsr
& MACSR_SU
) {
5679 tcg_gen_ext_i32_i64(acc
, val
);
5681 tcg_gen_extu_i32_i64(acc
, val
);
5683 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5684 gen_mac_clear_flags();
5685 gen_helper_mac_set_flags(tcg_env
, tcg_constant_i32(accnum
));
5688 DISAS_INSN(to_macsr
)
5691 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5692 gen_helper_set_macsr(tcg_env
, val
);
5699 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5700 tcg_gen_ori_i32(QREG_MAC_MASK
, val
, 0xffff0000);
5707 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5708 acc
= tcg_constant_i32((insn
& 0x400) ? 2 : 0);
5709 if (s
->env
->macsr
& MACSR_FI
)
5710 gen_helper_set_mac_extf(tcg_env
, val
, acc
);
5711 else if (s
->env
->macsr
& MACSR_SU
)
5712 gen_helper_set_mac_exts(tcg_env
, val
, acc
);
5714 gen_helper_set_mac_extu(tcg_env
, val
, acc
);
5717 static disas_proc opcode_table
[65536];
5720 register_opcode (disas_proc proc
, uint16_t opcode
, uint16_t mask
)
5726 /* Sanity check. All set bits must be included in the mask. */
5727 if (opcode
& ~mask
) {
5729 "qemu internal error: bogus opcode definition %04x/%04x\n",
5734 * This could probably be cleverer. For now just optimize the case where
5735 * the top bits are known.
5737 /* Find the first zero bit in the mask. */
5739 while ((i
& mask
) != 0)
5741 /* Iterate over all combinations of this and lower bits. */
5746 from
= opcode
& ~(i
- 1);
5748 for (i
= from
; i
< to
; i
++) {
5749 if ((i
& mask
) == opcode
)
5750 opcode_table
[i
] = proc
;
5755 * Register m68k opcode handlers. Order is important.
5756 * Later insn override earlier ones.
5758 void register_m68k_insns (CPUM68KState
*env
)
5761 * Build the opcode table only once to avoid
5762 * multithreading issues.
5764 if (opcode_table
[0] != NULL
) {
5769 * use BASE() for instruction available
5770 * for CF_ISA_A and M68000.
5772 #define BASE(name, opcode, mask) \
5773 register_opcode(disas_##name, 0x##opcode, 0x##mask)
5774 #define INSN(name, opcode, mask, feature) do { \
5775 if (m68k_feature(env, M68K_FEATURE_##feature)) \
5776 BASE(name, opcode, mask); \
5778 BASE(undef
, 0000, 0000);
5779 INSN(arith_im
, 0080, fff8
, CF_ISA_A
);
5780 INSN(arith_im
, 0000, ff00
, M68K
);
5781 INSN(chk2
, 00c0
, f9c0
, CHK2
);
5782 INSN(bitrev
, 00c0
, fff8
, CF_ISA_APLUSC
);
5783 BASE(bitop_reg
, 0100, f1c0
);
5784 BASE(bitop_reg
, 0140, f1c0
);
5785 BASE(bitop_reg
, 0180, f1c0
);
5786 BASE(bitop_reg
, 01c0
, f1c0
);
5787 INSN(movep
, 0108, f138
, MOVEP
);
5788 INSN(arith_im
, 0280, fff8
, CF_ISA_A
);
5789 INSN(arith_im
, 0200, ff00
, M68K
);
5790 INSN(undef
, 02c0
, ffc0
, M68K
);
5791 INSN(byterev
, 02c0
, fff8
, CF_ISA_APLUSC
);
5792 INSN(arith_im
, 0480, fff8
, CF_ISA_A
);
5793 INSN(arith_im
, 0400, ff00
, M68K
);
5794 INSN(undef
, 04c0
, ffc0
, M68K
);
5795 INSN(arith_im
, 0600, ff00
, M68K
);
5796 INSN(undef
, 06c0
, ffc0
, M68K
);
5797 INSN(ff1
, 04c0
, fff8
, CF_ISA_APLUSC
);
5798 INSN(arith_im
, 0680, fff8
, CF_ISA_A
);
5799 INSN(arith_im
, 0c00
, ff38
, CF_ISA_A
);
5800 INSN(arith_im
, 0c00
, ff00
, M68K
);
5801 BASE(bitop_im
, 0800, ffc0
);
5802 BASE(bitop_im
, 0840, ffc0
);
5803 BASE(bitop_im
, 0880, ffc0
);
5804 BASE(bitop_im
, 08c0
, ffc0
);
5805 INSN(arith_im
, 0a80
, fff8
, CF_ISA_A
);
5806 INSN(arith_im
, 0a00
, ff00
, M68K
);
5807 #if !defined(CONFIG_USER_ONLY)
5808 INSN(moves
, 0e00
, ff00
, M68K
);
5810 INSN(cas
, 0ac0
, ffc0
, CAS
);
5811 INSN(cas
, 0cc0
, ffc0
, CAS
);
5812 INSN(cas
, 0ec0
, ffc0
, CAS
);
5813 INSN(cas2w
, 0cfc
, ffff
, CAS
);
5814 INSN(cas2l
, 0efc
, ffff
, CAS
);
5815 BASE(move
, 1000, f000
);
5816 BASE(move
, 2000, f000
);
5817 BASE(move
, 3000, f000
);
5818 INSN(chk
, 4000, f040
, M68K
);
5819 INSN(strldsr
, 40e7
, ffff
, CF_ISA_APLUSC
);
5820 INSN(negx
, 4080, fff8
, CF_ISA_A
);
5821 INSN(negx
, 4000, ff00
, M68K
);
5822 INSN(undef
, 40c0
, ffc0
, M68K
);
5823 INSN(move_from_sr
, 40c0
, fff8
, CF_ISA_A
);
5824 INSN(move_from_sr
, 40c0
, ffc0
, M68K
);
5825 BASE(lea
, 41c0
, f1c0
);
5826 BASE(clr
, 4200, ff00
);
5827 BASE(undef
, 42c0
, ffc0
);
5828 INSN(move_from_ccr
, 42c0
, fff8
, CF_ISA_A
);
5829 INSN(move_from_ccr
, 42c0
, ffc0
, M68K
);
5830 INSN(neg
, 4480, fff8
, CF_ISA_A
);
5831 INSN(neg
, 4400, ff00
, M68K
);
5832 INSN(undef
, 44c0
, ffc0
, M68K
);
5833 BASE(move_to_ccr
, 44c0
, ffc0
);
5834 INSN(not, 4680, fff8
, CF_ISA_A
);
5835 INSN(not, 4600, ff00
, M68K
);
5836 #if !defined(CONFIG_USER_ONLY)
5837 BASE(move_to_sr
, 46c0
, ffc0
);
5839 INSN(nbcd
, 4800, ffc0
, M68K
);
5840 INSN(linkl
, 4808, fff8
, M68K
);
5841 BASE(pea
, 4840, ffc0
);
5842 BASE(swap
, 4840, fff8
);
5843 INSN(bkpt
, 4848, fff8
, BKPT
);
5844 INSN(movem
, 48d0
, fbf8
, CF_ISA_A
);
5845 INSN(movem
, 48e8
, fbf8
, CF_ISA_A
);
5846 INSN(movem
, 4880, fb80
, M68K
);
5847 BASE(ext
, 4880, fff8
);
5848 BASE(ext
, 48c0
, fff8
);
5849 BASE(ext
, 49c0
, fff8
);
5850 BASE(tst
, 4a00
, ff00
);
5851 INSN(tas
, 4ac0
, ffc0
, CF_ISA_B
);
5852 INSN(tas
, 4ac0
, ffc0
, M68K
);
5853 #if !defined(CONFIG_USER_ONLY)
5854 INSN(halt
, 4ac8
, ffff
, CF_ISA_A
);
5855 INSN(halt
, 4ac8
, ffff
, M68K
);
5857 INSN(pulse
, 4acc
, ffff
, CF_ISA_A
);
5858 BASE(illegal
, 4afc
, ffff
);
5859 INSN(mull
, 4c00
, ffc0
, CF_ISA_A
);
5860 INSN(mull
, 4c00
, ffc0
, LONG_MULDIV
);
5861 INSN(divl
, 4c40
, ffc0
, CF_ISA_A
);
5862 INSN(divl
, 4c40
, ffc0
, LONG_MULDIV
);
5863 INSN(sats
, 4c80
, fff8
, CF_ISA_B
);
5864 BASE(trap
, 4e40
, fff0
);
5865 BASE(link
, 4e50
, fff8
);
5866 BASE(unlk
, 4e58
, fff8
);
5867 #if !defined(CONFIG_USER_ONLY)
5868 INSN(move_to_usp
, 4e60
, fff8
, USP
);
5869 INSN(move_from_usp
, 4e68
, fff8
, USP
);
5870 INSN(reset
, 4e70
, ffff
, M68K
);
5871 BASE(stop
, 4e72
, ffff
);
5872 BASE(rte
, 4e73
, ffff
);
5873 INSN(cf_movec
, 4e7b
, ffff
, CF_ISA_A
);
5874 INSN(m68k_movec
, 4e7a
, fffe
, MOVEC
);
5876 BASE(nop
, 4e71
, ffff
);
5877 INSN(rtd
, 4e74
, ffff
, RTD
);
5878 BASE(rts
, 4e75
, ffff
);
5879 INSN(trapv
, 4e76
, ffff
, M68K
);
5880 INSN(rtr
, 4e77
, ffff
, M68K
);
5881 BASE(jump
, 4e80
, ffc0
);
5882 BASE(jump
, 4ec0
, ffc0
);
5883 INSN(addsubq
, 5000, f080
, M68K
);
5884 BASE(addsubq
, 5080, f0c0
);
5885 INSN(scc
, 50c0
, f0f8
, CF_ISA_A
); /* Scc.B Dx */
5886 INSN(scc
, 50c0
, f0c0
, M68K
); /* Scc.B <EA> */
5887 INSN(dbcc
, 50c8
, f0f8
, M68K
);
5888 INSN(trapcc
, 50fa
, f0fe
, TRAPCC
); /* opmode 010, 011 */
5889 INSN(trapcc
, 50fc
, f0ff
, TRAPCC
); /* opmode 100 */
5890 INSN(trapcc
, 51fa
, fffe
, CF_ISA_A
); /* TPF (trapf) opmode 010, 011 */
5891 INSN(trapcc
, 51fc
, ffff
, CF_ISA_A
); /* TPF (trapf) opmode 100 */
5893 /* Branch instructions. */
5894 BASE(branch
, 6000, f000
);
5895 /* Disable long branch instructions, then add back the ones we want. */
5896 BASE(undef
, 60ff
, f0ff
); /* All long branches. */
5897 INSN(branch
, 60ff
, f0ff
, CF_ISA_B
);
5898 INSN(undef
, 60ff
, ffff
, CF_ISA_B
); /* bra.l */
5899 INSN(branch
, 60ff
, ffff
, BRAL
);
5900 INSN(branch
, 60ff
, f0ff
, BCCL
);
5902 BASE(moveq
, 7000, f100
);
5903 INSN(mvzs
, 7100, f100
, CF_ISA_B
);
5904 BASE(or, 8000, f000
);
5905 BASE(divw
, 80c0
, f0c0
);
5906 INSN(sbcd_reg
, 8100, f1f8
, M68K
);
5907 INSN(sbcd_mem
, 8108, f1f8
, M68K
);
5908 BASE(addsub
, 9000, f000
);
5909 INSN(undef
, 90c0
, f0c0
, CF_ISA_A
);
5910 INSN(subx_reg
, 9180, f1f8
, CF_ISA_A
);
5911 INSN(subx_reg
, 9100, f138
, M68K
);
5912 INSN(subx_mem
, 9108, f138
, M68K
);
5913 INSN(suba
, 91c0
, f1c0
, CF_ISA_A
);
5914 INSN(suba
, 90c0
, f0c0
, M68K
);
5916 BASE(undef_mac
, a000
, f000
);
5917 INSN(mac
, a000
, f100
, CF_EMAC
);
5918 INSN(from_mac
, a180
, f9b0
, CF_EMAC
);
5919 INSN(move_mac
, a110
, f9fc
, CF_EMAC
);
5920 INSN(from_macsr
,a980
, f9f0
, CF_EMAC
);
5921 INSN(from_mask
, ad80
, fff0
, CF_EMAC
);
5922 INSN(from_mext
, ab80
, fbf0
, CF_EMAC
);
5923 INSN(macsr_to_ccr
, a9c0
, ffff
, CF_EMAC
);
5924 INSN(to_mac
, a100
, f9c0
, CF_EMAC
);
5925 INSN(to_macsr
, a900
, ffc0
, CF_EMAC
);
5926 INSN(to_mext
, ab00
, fbc0
, CF_EMAC
);
5927 INSN(to_mask
, ad00
, ffc0
, CF_EMAC
);
5929 INSN(mov3q
, a140
, f1c0
, CF_ISA_B
);
5930 INSN(cmp
, b000
, f1c0
, CF_ISA_B
); /* cmp.b */
5931 INSN(cmp
, b040
, f1c0
, CF_ISA_B
); /* cmp.w */
5932 INSN(cmpa
, b0c0
, f1c0
, CF_ISA_B
); /* cmpa.w */
5933 INSN(cmp
, b080
, f1c0
, CF_ISA_A
);
5934 INSN(cmpa
, b1c0
, f1c0
, CF_ISA_A
);
5935 INSN(cmp
, b000
, f100
, M68K
);
5936 INSN(eor
, b100
, f100
, M68K
);
5937 INSN(cmpm
, b108
, f138
, M68K
);
5938 INSN(cmpa
, b0c0
, f0c0
, M68K
);
5939 INSN(eor
, b180
, f1c0
, CF_ISA_A
);
5940 BASE(and, c000
, f000
);
5941 INSN(exg_dd
, c140
, f1f8
, M68K
);
5942 INSN(exg_aa
, c148
, f1f8
, M68K
);
5943 INSN(exg_da
, c188
, f1f8
, M68K
);
5944 BASE(mulw
, c0c0
, f0c0
);
5945 INSN(abcd_reg
, c100
, f1f8
, M68K
);
5946 INSN(abcd_mem
, c108
, f1f8
, M68K
);
5947 BASE(addsub
, d000
, f000
);
5948 INSN(undef
, d0c0
, f0c0
, CF_ISA_A
);
5949 INSN(addx_reg
, d180
, f1f8
, CF_ISA_A
);
5950 INSN(addx_reg
, d100
, f138
, M68K
);
5951 INSN(addx_mem
, d108
, f138
, M68K
);
5952 INSN(adda
, d1c0
, f1c0
, CF_ISA_A
);
5953 INSN(adda
, d0c0
, f0c0
, M68K
);
5954 INSN(shift_im
, e080
, f0f0
, CF_ISA_A
);
5955 INSN(shift_reg
, e0a0
, f0f0
, CF_ISA_A
);
5956 INSN(shift8_im
, e000
, f0f0
, M68K
);
5957 INSN(shift16_im
, e040
, f0f0
, M68K
);
5958 INSN(shift_im
, e080
, f0f0
, M68K
);
5959 INSN(shift8_reg
, e020
, f0f0
, M68K
);
5960 INSN(shift16_reg
, e060
, f0f0
, M68K
);
5961 INSN(shift_reg
, e0a0
, f0f0
, M68K
);
5962 INSN(shift_mem
, e0c0
, fcc0
, M68K
);
5963 INSN(rotate_im
, e090
, f0f0
, M68K
);
5964 INSN(rotate8_im
, e010
, f0f0
, M68K
);
5965 INSN(rotate16_im
, e050
, f0f0
, M68K
);
5966 INSN(rotate_reg
, e0b0
, f0f0
, M68K
);
5967 INSN(rotate8_reg
, e030
, f0f0
, M68K
);
5968 INSN(rotate16_reg
, e070
, f0f0
, M68K
);
5969 INSN(rotate_mem
, e4c0
, fcc0
, M68K
);
5970 INSN(bfext_mem
, e9c0
, fdc0
, BITFIELD
); /* bfextu & bfexts */
5971 INSN(bfext_reg
, e9c0
, fdf8
, BITFIELD
);
5972 INSN(bfins_mem
, efc0
, ffc0
, BITFIELD
);
5973 INSN(bfins_reg
, efc0
, fff8
, BITFIELD
);
5974 INSN(bfop_mem
, eac0
, ffc0
, BITFIELD
); /* bfchg */
5975 INSN(bfop_reg
, eac0
, fff8
, BITFIELD
); /* bfchg */
5976 INSN(bfop_mem
, ecc0
, ffc0
, BITFIELD
); /* bfclr */
5977 INSN(bfop_reg
, ecc0
, fff8
, BITFIELD
); /* bfclr */
5978 INSN(bfop_mem
, edc0
, ffc0
, BITFIELD
); /* bfffo */
5979 INSN(bfop_reg
, edc0
, fff8
, BITFIELD
); /* bfffo */
5980 INSN(bfop_mem
, eec0
, ffc0
, BITFIELD
); /* bfset */
5981 INSN(bfop_reg
, eec0
, fff8
, BITFIELD
); /* bfset */
5982 INSN(bfop_mem
, e8c0
, ffc0
, BITFIELD
); /* bftst */
5983 INSN(bfop_reg
, e8c0
, fff8
, BITFIELD
); /* bftst */
5984 BASE(undef_fpu
, f000
, f000
);
5985 INSN(fpu
, f200
, ffc0
, CF_FPU
);
5986 INSN(fbcc
, f280
, ffc0
, CF_FPU
);
5987 INSN(fpu
, f200
, ffc0
, FPU
);
5988 INSN(fscc
, f240
, ffc0
, FPU
);
5989 INSN(ftrapcc
, f27a
, fffe
, FPU
); /* opmode 010, 011 */
5990 INSN(ftrapcc
, f27c
, ffff
, FPU
); /* opmode 100 */
5991 INSN(fbcc
, f280
, ff80
, FPU
);
5992 #if !defined(CONFIG_USER_ONLY)
5993 INSN(frestore
, f340
, ffc0
, CF_FPU
);
5994 INSN(fsave
, f300
, ffc0
, CF_FPU
);
5995 INSN(frestore
, f340
, ffc0
, FPU
);
5996 INSN(fsave
, f300
, ffc0
, FPU
);
5997 INSN(intouch
, f340
, ffc0
, CF_ISA_A
);
5998 INSN(cpushl
, f428
, ff38
, CF_ISA_A
);
5999 INSN(cpush
, f420
, ff20
, M68040
);
6000 INSN(cinv
, f400
, ff20
, M68040
);
6001 INSN(pflush
, f500
, ffe0
, M68040
);
6002 INSN(ptest
, f548
, ffd8
, M68040
);
6003 INSN(wddata
, fb00
, ff00
, CF_ISA_A
);
6004 INSN(wdebug
, fbc0
, ffc0
, CF_ISA_A
);
6006 INSN(move16_mem
, f600
, ffe0
, M68040
);
6007 INSN(move16_reg
, f620
, fff8
, M68040
);
6011 static void m68k_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cpu
)
6013 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6014 CPUM68KState
*env
= cpu_env(cpu
);
6017 dc
->pc
= dc
->base
.pc_first
;
6018 /* This value will always be filled in properly before m68k_tr_tb_stop. */
6019 dc
->pc_prev
= 0xdeadbeef;
6020 dc
->cc_op
= CC_OP_DYNAMIC
;
6021 dc
->cc_op_synced
= 1;
6023 dc
->writeback_mask
= 0;
6025 dc
->ss_active
= (M68K_SR_TRACE(env
->sr
) == M68K_SR_TRACE_ANY_INS
);
6026 /* If architectural single step active, limit to 1 */
6027 if (dc
->ss_active
) {
6028 dc
->base
.max_insns
= 1;
6032 static void m68k_tr_tb_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6036 static void m68k_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
6038 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6039 tcg_gen_insn_start(dc
->base
.pc_next
, dc
->cc_op
);
6042 static void m68k_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
6044 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6045 CPUM68KState
*env
= cpu_env(cpu
);
6046 uint16_t insn
= read_im16(env
, dc
);
6048 opcode_table
[insn
](env
, dc
, insn
);
6051 dc
->pc_prev
= dc
->base
.pc_next
;
6052 dc
->base
.pc_next
= dc
->pc
;
6054 if (dc
->base
.is_jmp
== DISAS_NEXT
) {
6056 * Stop translation when the next insn might touch a new page.
6057 * This ensures that prefetch aborts at the right place.
6059 * We cannot determine the size of the next insn without
6060 * completely decoding it. However, the maximum insn size
6061 * is 32 bytes, so end if we do not have that much remaining.
6062 * This may produce several small TBs at the end of each page,
6063 * but they will all be linked with goto_tb.
6065 * ??? ColdFire maximum is 4 bytes; MC68000's maximum is also
6066 * smaller than MC68020's.
6068 target_ulong start_page_offset
6069 = dc
->pc
- (dc
->base
.pc_first
& TARGET_PAGE_MASK
);
6071 if (start_page_offset
>= TARGET_PAGE_SIZE
- 32) {
6072 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
6077 static void m68k_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
6079 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
6081 switch (dc
->base
.is_jmp
) {
6082 case DISAS_NORETURN
:
6084 case DISAS_TOO_MANY
:
6086 gen_jmp_tb(dc
, 0, dc
->pc
, dc
->pc_prev
);
6089 /* We updated CC_OP and PC in gen_jmp/gen_jmp_im. */
6090 if (dc
->ss_active
) {
6091 gen_raise_exception_format2(dc
, EXCP_TRACE
, dc
->pc_prev
);
6093 tcg_gen_lookup_and_goto_ptr();
6098 * We updated CC_OP and PC in gen_exit_tb, but also modified
6099 * other state that may require returning to the main loop.
6101 if (dc
->ss_active
) {
6102 gen_raise_exception_format2(dc
, EXCP_TRACE
, dc
->pc_prev
);
6104 tcg_gen_exit_tb(NULL
, 0);
6108 g_assert_not_reached();
6112 static const TranslatorOps m68k_tr_ops
= {
6113 .init_disas_context
= m68k_tr_init_disas_context
,
6114 .tb_start
= m68k_tr_tb_start
,
6115 .insn_start
= m68k_tr_insn_start
,
6116 .translate_insn
= m68k_tr_translate_insn
,
6117 .tb_stop
= m68k_tr_tb_stop
,
6120 void gen_intermediate_code(CPUState
*cpu
, TranslationBlock
*tb
, int *max_insns
,
6121 vaddr pc
, void *host_pc
)
6124 translator_loop(cpu
, tb
, max_insns
, pc
, host_pc
, &m68k_tr_ops
, &dc
.base
);
6127 static double floatx80_to_double(CPUM68KState
*env
, uint16_t high
, uint64_t low
)
6129 floatx80 a
= { .high
= high
, .low
= low
};
6135 u
.f64
= floatx80_to_float64(a
, &env
->fp_status
);
6139 void m68k_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
6141 CPUM68KState
*env
= cpu_env(cs
);
6144 for (i
= 0; i
< 8; i
++) {
6145 qemu_fprintf(f
, "D%d = %08x A%d = %08x "
6146 "F%d = %04x %016"PRIx64
" (%12g)\n",
6147 i
, env
->dregs
[i
], i
, env
->aregs
[i
],
6148 i
, env
->fregs
[i
].l
.upper
, env
->fregs
[i
].l
.lower
,
6149 floatx80_to_double(env
, env
->fregs
[i
].l
.upper
,
6150 env
->fregs
[i
].l
.lower
));
6152 qemu_fprintf(f
, "PC = %08x ", env
->pc
);
6153 sr
= env
->sr
| cpu_m68k_get_ccr(env
);
6154 qemu_fprintf(f
, "SR = %04x T:%x I:%x %c%c %c%c%c%c%c\n",
6155 sr
, (sr
& SR_T
) >> SR_T_SHIFT
, (sr
& SR_I
) >> SR_I_SHIFT
,
6156 (sr
& SR_S
) ? 'S' : 'U', (sr
& SR_M
) ? '%' : 'I',
6157 (sr
& CCF_X
) ? 'X' : '-', (sr
& CCF_N
) ? 'N' : '-',
6158 (sr
& CCF_Z
) ? 'Z' : '-', (sr
& CCF_V
) ? 'V' : '-',
6159 (sr
& CCF_C
) ? 'C' : '-');
6160 qemu_fprintf(f
, "FPSR = %08x %c%c%c%c ", env
->fpsr
,
6161 (env
->fpsr
& FPSR_CC_A
) ? 'A' : '-',
6162 (env
->fpsr
& FPSR_CC_I
) ? 'I' : '-',
6163 (env
->fpsr
& FPSR_CC_Z
) ? 'Z' : '-',
6164 (env
->fpsr
& FPSR_CC_N
) ? 'N' : '-');
6165 qemu_fprintf(f
, "\n "
6166 "FPCR = %04x ", env
->fpcr
);
6167 switch (env
->fpcr
& FPCR_PREC_MASK
) {
6169 qemu_fprintf(f
, "X ");
6172 qemu_fprintf(f
, "S ");
6175 qemu_fprintf(f
, "D ");
6178 switch (env
->fpcr
& FPCR_RND_MASK
) {
6180 qemu_fprintf(f
, "RN ");
6183 qemu_fprintf(f
, "RZ ");
6186 qemu_fprintf(f
, "RM ");
6189 qemu_fprintf(f
, "RP ");
6192 qemu_fprintf(f
, "\n");
6193 #ifndef CONFIG_USER_ONLY
6194 qemu_fprintf(f
, "%sA7(MSP) = %08x %sA7(USP) = %08x %sA7(ISP) = %08x\n",
6195 env
->current_sp
== M68K_SSP
? "->" : " ", env
->sp
[M68K_SSP
],
6196 env
->current_sp
== M68K_USP
? "->" : " ", env
->sp
[M68K_USP
],
6197 env
->current_sp
== M68K_ISP
? "->" : " ", env
->sp
[M68K_ISP
]);
6198 qemu_fprintf(f
, "VBR = 0x%08x\n", env
->vbr
);
6199 qemu_fprintf(f
, "SFC = %x DFC %x\n", env
->sfc
, env
->dfc
);
6200 qemu_fprintf(f
, "SSW %08x TCR %08x URP %08x SRP %08x\n",
6201 env
->mmu
.ssw
, env
->mmu
.tcr
, env
->mmu
.urp
, env
->mmu
.srp
);
6202 qemu_fprintf(f
, "DTTR0/1: %08x/%08x ITTR0/1: %08x/%08x\n",
6203 env
->mmu
.ttr
[M68K_DTTR0
], env
->mmu
.ttr
[M68K_DTTR1
],
6204 env
->mmu
.ttr
[M68K_ITTR0
], env
->mmu
.ttr
[M68K_ITTR1
]);
6205 qemu_fprintf(f
, "MMUSR %08x, fault at %08x\n",
6206 env
->mmu
.mmusr
, env
->mmu
.ar
);
6207 #endif /* !CONFIG_USER_ONLY */