4 * Copyright (c) 2005-2007 CodeSourcery
5 * Written by Paul Brook
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
23 #include "disas/disas.h"
24 #include "exec/exec-all.h"
27 #include "exec/cpu_ldst.h"
29 #include "exec/helper-proto.h"
30 #include "exec/helper-gen.h"
32 #include "trace-tcg.h"
35 //#define DEBUG_DISPATCH 1
37 #define DEFO32(name, offset) static TCGv QREG_##name;
38 #define DEFO64(name, offset) static TCGv_i64 QREG_##name;
43 static TCGv_i32 cpu_halted
;
44 static TCGv_i32 cpu_exception_index
;
46 static TCGv_env cpu_env
;
48 static char cpu_reg_names
[2 * 8 * 3 + 5 * 4];
49 static TCGv cpu_dregs
[8];
50 static TCGv cpu_aregs
[8];
51 static TCGv_i64 cpu_macc
[4];
53 #define REG(insn, pos) (((insn) >> (pos)) & 7)
54 #define DREG(insn, pos) cpu_dregs[REG(insn, pos)]
55 #define AREG(insn, pos) get_areg(s, REG(insn, pos))
56 #define MACREG(acc) cpu_macc[acc]
57 #define QREG_SP get_areg(s, 7)
59 static TCGv NULL_QREG
;
60 #define IS_NULL_QREG(t) (TCGV_EQUAL(t, NULL_QREG))
61 /* Used to distinguish stores from bad addressing modes. */
62 static TCGv store_dummy
;
64 #include "exec/gen-icount.h"
66 void m68k_tcg_init(void)
71 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
72 tcg_ctx
.tcg_env
= cpu_env
;
74 #define DEFO32(name, offset) \
75 QREG_##name = tcg_global_mem_new_i32(cpu_env, \
76 offsetof(CPUM68KState, offset), #name);
77 #define DEFO64(name, offset) \
78 QREG_##name = tcg_global_mem_new_i64(cpu_env, \
79 offsetof(CPUM68KState, offset), #name);
84 cpu_halted
= tcg_global_mem_new_i32(cpu_env
,
85 -offsetof(M68kCPU
, env
) +
86 offsetof(CPUState
, halted
), "HALTED");
87 cpu_exception_index
= tcg_global_mem_new_i32(cpu_env
,
88 -offsetof(M68kCPU
, env
) +
89 offsetof(CPUState
, exception_index
),
93 for (i
= 0; i
< 8; i
++) {
95 cpu_dregs
[i
] = tcg_global_mem_new(cpu_env
,
96 offsetof(CPUM68KState
, dregs
[i
]), p
);
99 cpu_aregs
[i
] = tcg_global_mem_new(cpu_env
,
100 offsetof(CPUM68KState
, aregs
[i
]), p
);
103 for (i
= 0; i
< 4; i
++) {
104 sprintf(p
, "ACC%d", i
);
105 cpu_macc
[i
] = tcg_global_mem_new_i64(cpu_env
,
106 offsetof(CPUM68KState
, macc
[i
]), p
);
110 NULL_QREG
= tcg_global_mem_new(cpu_env
, -4, "NULL");
111 store_dummy
= tcg_global_mem_new(cpu_env
, -8, "NULL");
114 /* internal defines */
115 typedef struct DisasContext
{
117 target_ulong insn_pc
; /* Start of the current instruction. */
120 CCOp cc_op
; /* Current CC operation */
123 struct TranslationBlock
*tb
;
124 int singlestep_enabled
;
131 static TCGv
get_areg(DisasContext
*s
, unsigned regno
)
133 if (s
->writeback_mask
& (1 << regno
)) {
134 return s
->writeback
[regno
];
136 return cpu_aregs
[regno
];
140 static void delay_set_areg(DisasContext
*s
, unsigned regno
,
141 TCGv val
, bool give_temp
)
143 if (s
->writeback_mask
& (1 << regno
)) {
145 tcg_temp_free(s
->writeback
[regno
]);
146 s
->writeback
[regno
] = val
;
148 tcg_gen_mov_i32(s
->writeback
[regno
], val
);
151 s
->writeback_mask
|= 1 << regno
;
153 s
->writeback
[regno
] = val
;
155 TCGv tmp
= tcg_temp_new();
156 s
->writeback
[regno
] = tmp
;
157 tcg_gen_mov_i32(tmp
, val
);
162 static void do_writebacks(DisasContext
*s
)
164 unsigned mask
= s
->writeback_mask
;
166 s
->writeback_mask
= 0;
168 unsigned regno
= ctz32(mask
);
169 tcg_gen_mov_i32(cpu_aregs
[regno
], s
->writeback
[regno
]);
170 tcg_temp_free(s
->writeback
[regno
]);
176 #define DISAS_JUMP_NEXT 4
178 #if defined(CONFIG_USER_ONLY)
181 #define IS_USER(s) s->user
184 /* XXX: move that elsewhere */
185 /* ??? Fix exceptions. */
186 static void *gen_throws_exception
;
187 #define gen_last_qop NULL
189 typedef void (*disas_proc
)(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
);
191 #ifdef DEBUG_DISPATCH
192 #define DISAS_INSN(name) \
193 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
195 static void disas_##name(CPUM68KState *env, DisasContext *s, \
198 qemu_log("Dispatch " #name "\n"); \
199 real_disas_##name(env, s, insn); \
201 static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
204 #define DISAS_INSN(name) \
205 static void disas_##name(CPUM68KState *env, DisasContext *s, \
209 static const uint8_t cc_op_live
[CC_OP_NB
] = {
210 [CC_OP_FLAGS
] = CCF_C
| CCF_V
| CCF_Z
| CCF_N
| CCF_X
,
211 [CC_OP_ADDB
... CC_OP_ADDL
] = CCF_X
| CCF_N
| CCF_V
,
212 [CC_OP_SUBB
... CC_OP_SUBL
] = CCF_X
| CCF_N
| CCF_V
,
213 [CC_OP_CMPB
... CC_OP_CMPL
] = CCF_X
| CCF_N
| CCF_V
,
214 [CC_OP_LOGIC
] = CCF_X
| CCF_N
217 static void set_cc_op(DisasContext
*s
, CCOp op
)
219 CCOp old_op
= s
->cc_op
;
228 /* Discard CC computation that will no longer be used.
229 Note that X and N are never dead. */
230 dead
= cc_op_live
[old_op
] & ~cc_op_live
[op
];
232 tcg_gen_discard_i32(QREG_CC_C
);
235 tcg_gen_discard_i32(QREG_CC_Z
);
238 tcg_gen_discard_i32(QREG_CC_V
);
242 /* Update the CPU env CC_OP state. */
243 static void update_cc_op(DisasContext
*s
)
245 if (!s
->cc_op_synced
) {
247 tcg_gen_movi_i32(QREG_CC_OP
, s
->cc_op
);
251 /* Generate a jump to an immediate address. */
252 static void gen_jmp_im(DisasContext
*s
, uint32_t dest
)
255 tcg_gen_movi_i32(QREG_PC
, dest
);
256 s
->is_jmp
= DISAS_JUMP
;
259 /* Generate a jump to the address in qreg DEST. */
260 static void gen_jmp(DisasContext
*s
, TCGv dest
)
263 tcg_gen_mov_i32(QREG_PC
, dest
);
264 s
->is_jmp
= DISAS_JUMP
;
267 static void gen_raise_exception(int nr
)
269 TCGv_i32 tmp
= tcg_const_i32(nr
);
271 gen_helper_raise_exception(cpu_env
, tmp
);
272 tcg_temp_free_i32(tmp
);
275 static void gen_exception(DisasContext
*s
, uint32_t where
, int nr
)
278 gen_jmp_im(s
, where
);
279 gen_raise_exception(nr
);
282 static inline void gen_addr_fault(DisasContext
*s
)
284 gen_exception(s
, s
->insn_pc
, EXCP_ADDRESS
);
287 /* Generate a load from the specified address. Narrow values are
288 sign extended to full register width. */
289 static inline TCGv
gen_load(DisasContext
* s
, int opsize
, TCGv addr
, int sign
)
292 int index
= IS_USER(s
);
293 tmp
= tcg_temp_new_i32();
297 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
299 tcg_gen_qemu_ld8u(tmp
, addr
, index
);
303 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
305 tcg_gen_qemu_ld16u(tmp
, addr
, index
);
308 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
311 g_assert_not_reached();
313 gen_throws_exception
= gen_last_qop
;
317 /* Generate a store. */
318 static inline void gen_store(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
)
320 int index
= IS_USER(s
);
323 tcg_gen_qemu_st8(val
, addr
, index
);
326 tcg_gen_qemu_st16(val
, addr
, index
);
329 tcg_gen_qemu_st32(val
, addr
, index
);
332 g_assert_not_reached();
334 gen_throws_exception
= gen_last_qop
;
343 /* Generate an unsigned load if VAL is 0 a signed load if val is -1,
344 otherwise generate a store. */
345 static TCGv
gen_ldst(DisasContext
*s
, int opsize
, TCGv addr
, TCGv val
,
348 if (what
== EA_STORE
) {
349 gen_store(s
, opsize
, addr
, val
);
352 return gen_load(s
, opsize
, addr
, what
== EA_LOADS
);
356 /* Read a 16-bit immediate constant */
357 static inline uint16_t read_im16(CPUM68KState
*env
, DisasContext
*s
)
360 im
= cpu_lduw_code(env
, 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
);
408 /* Handle a base + index + displacement effective addresss.
409 A NULL_QREG base means pc-relative. */
410 static TCGv
gen_lea_indexed(CPUM68KState
*env
, DisasContext
*s
, TCGv base
)
419 ext
= read_im16(env
, s
);
421 if ((ext
& 0x800) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_WORD_INDEX
))
424 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
) &&
425 !m68k_feature(s
->env
, M68K_FEATURE_SCALED_INDEX
)) {
430 /* full extension word format */
431 if (!m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
))
434 if ((ext
& 0x30) > 0x10) {
435 /* base displacement */
436 if ((ext
& 0x30) == 0x20) {
437 bd
= (int16_t)read_im16(env
, s
);
439 bd
= read_im32(env
, s
);
444 tmp
= tcg_temp_new();
445 if ((ext
& 0x44) == 0) {
447 add
= gen_addr_index(s
, ext
, tmp
);
451 if ((ext
& 0x80) == 0) {
452 /* base not suppressed */
453 if (IS_NULL_QREG(base
)) {
454 base
= tcg_const_i32(offset
+ bd
);
457 if (!IS_NULL_QREG(add
)) {
458 tcg_gen_add_i32(tmp
, add
, base
);
464 if (!IS_NULL_QREG(add
)) {
466 tcg_gen_addi_i32(tmp
, add
, bd
);
470 add
= tcg_const_i32(bd
);
472 if ((ext
& 3) != 0) {
473 /* memory indirect */
474 base
= gen_load(s
, OS_LONG
, add
, 0);
475 if ((ext
& 0x44) == 4) {
476 add
= gen_addr_index(s
, ext
, tmp
);
477 tcg_gen_add_i32(tmp
, add
, base
);
483 /* outer displacement */
484 if ((ext
& 3) == 2) {
485 od
= (int16_t)read_im16(env
, s
);
487 od
= read_im32(env
, s
);
493 tcg_gen_addi_i32(tmp
, add
, od
);
498 /* brief extension word format */
499 tmp
= tcg_temp_new();
500 add
= gen_addr_index(s
, ext
, tmp
);
501 if (!IS_NULL_QREG(base
)) {
502 tcg_gen_add_i32(tmp
, add
, base
);
504 tcg_gen_addi_i32(tmp
, tmp
, (int8_t)ext
);
506 tcg_gen_addi_i32(tmp
, add
, offset
+ (int8_t)ext
);
513 /* Sign or zero extend a value. */
515 static inline void gen_ext(TCGv res
, TCGv val
, int opsize
, int sign
)
520 tcg_gen_ext8s_i32(res
, val
);
522 tcg_gen_ext8u_i32(res
, val
);
527 tcg_gen_ext16s_i32(res
, val
);
529 tcg_gen_ext16u_i32(res
, val
);
533 tcg_gen_mov_i32(res
, val
);
536 g_assert_not_reached();
540 /* Evaluate all the CC flags. */
542 static void gen_flush_flags(DisasContext
*s
)
553 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
554 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
555 /* Compute signed overflow for addition. */
558 tcg_gen_sub_i32(t0
, QREG_CC_N
, QREG_CC_V
);
559 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_ADDB
, 1);
560 tcg_gen_xor_i32(t1
, QREG_CC_N
, QREG_CC_V
);
561 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
563 tcg_gen_andc_i32(QREG_CC_V
, t1
, QREG_CC_V
);
570 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
571 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
572 /* Compute signed overflow for subtraction. */
575 tcg_gen_add_i32(t0
, QREG_CC_N
, QREG_CC_V
);
576 gen_ext(t0
, t0
, s
->cc_op
- CC_OP_SUBB
, 1);
577 tcg_gen_xor_i32(t1
, QREG_CC_N
, t0
);
578 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, t0
);
580 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t1
);
587 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_C
, QREG_CC_N
, QREG_CC_V
);
588 tcg_gen_sub_i32(QREG_CC_Z
, QREG_CC_N
, QREG_CC_V
);
589 gen_ext(QREG_CC_Z
, QREG_CC_Z
, s
->cc_op
- CC_OP_CMPB
, 1);
590 /* Compute signed overflow for subtraction. */
592 tcg_gen_xor_i32(t0
, QREG_CC_Z
, QREG_CC_N
);
593 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_V
, QREG_CC_N
);
594 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, t0
);
596 tcg_gen_mov_i32(QREG_CC_N
, QREG_CC_Z
);
600 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
601 tcg_gen_movi_i32(QREG_CC_C
, 0);
602 tcg_gen_movi_i32(QREG_CC_V
, 0);
606 gen_helper_flush_flags(cpu_env
, QREG_CC_OP
);
611 t0
= tcg_const_i32(s
->cc_op
);
612 gen_helper_flush_flags(cpu_env
, t0
);
618 /* Note that flush_flags also assigned to env->cc_op. */
619 s
->cc_op
= CC_OP_FLAGS
;
622 static inline TCGv
gen_extend(TCGv val
, int opsize
, int sign
)
626 if (opsize
== OS_LONG
) {
629 tmp
= tcg_temp_new();
630 gen_ext(tmp
, val
, opsize
, sign
);
636 static void gen_logic_cc(DisasContext
*s
, TCGv val
, int opsize
)
638 gen_ext(QREG_CC_N
, val
, opsize
, 1);
639 set_cc_op(s
, CC_OP_LOGIC
);
642 static void gen_update_cc_cmp(DisasContext
*s
, TCGv dest
, TCGv src
, int opsize
)
644 tcg_gen_mov_i32(QREG_CC_N
, dest
);
645 tcg_gen_mov_i32(QREG_CC_V
, src
);
646 set_cc_op(s
, CC_OP_CMPB
+ opsize
);
649 static void gen_update_cc_add(TCGv dest
, TCGv src
, int opsize
)
651 gen_ext(QREG_CC_N
, dest
, opsize
, 1);
652 tcg_gen_mov_i32(QREG_CC_V
, src
);
655 static inline int opsize_bytes(int opsize
)
658 case OS_BYTE
: return 1;
659 case OS_WORD
: return 2;
660 case OS_LONG
: return 4;
661 case OS_SINGLE
: return 4;
662 case OS_DOUBLE
: return 8;
663 case OS_EXTENDED
: return 12;
664 case OS_PACKED
: return 12;
666 g_assert_not_reached();
670 static inline int insn_opsize(int insn
)
672 switch ((insn
>> 6) & 3) {
673 case 0: return OS_BYTE
;
674 case 1: return OS_WORD
;
675 case 2: return OS_LONG
;
677 g_assert_not_reached();
681 static inline int ext_opsize(int ext
, int pos
)
683 switch ((ext
>> pos
) & 7) {
684 case 0: return OS_LONG
;
685 case 1: return OS_SINGLE
;
686 case 2: return OS_EXTENDED
;
687 case 3: return OS_PACKED
;
688 case 4: return OS_WORD
;
689 case 5: return OS_DOUBLE
;
690 case 6: return OS_BYTE
;
692 g_assert_not_reached();
696 /* Assign value to a register. If the width is less than the register width
697 only the low part of the register is set. */
698 static void gen_partset_reg(int opsize
, TCGv reg
, TCGv val
)
703 tcg_gen_andi_i32(reg
, reg
, 0xffffff00);
704 tmp
= tcg_temp_new();
705 tcg_gen_ext8u_i32(tmp
, val
);
706 tcg_gen_or_i32(reg
, reg
, tmp
);
710 tcg_gen_andi_i32(reg
, reg
, 0xffff0000);
711 tmp
= tcg_temp_new();
712 tcg_gen_ext16u_i32(tmp
, val
);
713 tcg_gen_or_i32(reg
, reg
, tmp
);
718 tcg_gen_mov_i32(reg
, val
);
721 g_assert_not_reached();
725 /* Generate code for an "effective address". Does not adjust the base
726 register for autoincrement addressing modes. */
727 static TCGv
gen_lea_mode(CPUM68KState
*env
, DisasContext
*s
,
728 int mode
, int reg0
, int opsize
)
736 case 0: /* Data register direct. */
737 case 1: /* Address register direct. */
739 case 3: /* Indirect postincrement. */
740 if (opsize
== OS_UNSIZED
) {
744 case 2: /* Indirect register */
745 return get_areg(s
, reg0
);
746 case 4: /* Indirect predecrememnt. */
747 if (opsize
== OS_UNSIZED
) {
750 reg
= get_areg(s
, reg0
);
751 tmp
= tcg_temp_new();
752 if (reg0
== 7 && opsize
== OS_BYTE
&&
753 m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
754 tcg_gen_subi_i32(tmp
, reg
, 2);
756 tcg_gen_subi_i32(tmp
, reg
, opsize_bytes(opsize
));
759 case 5: /* Indirect displacement. */
760 reg
= get_areg(s
, reg0
);
761 tmp
= tcg_temp_new();
762 ext
= read_im16(env
, s
);
763 tcg_gen_addi_i32(tmp
, reg
, (int16_t)ext
);
765 case 6: /* Indirect index + displacement. */
766 reg
= get_areg(s
, reg0
);
767 return gen_lea_indexed(env
, s
, reg
);
770 case 0: /* Absolute short. */
771 offset
= (int16_t)read_im16(env
, s
);
772 return tcg_const_i32(offset
);
773 case 1: /* Absolute long. */
774 offset
= read_im32(env
, s
);
775 return tcg_const_i32(offset
);
776 case 2: /* pc displacement */
778 offset
+= (int16_t)read_im16(env
, s
);
779 return tcg_const_i32(offset
);
780 case 3: /* pc index+displacement. */
781 return gen_lea_indexed(env
, s
, NULL_QREG
);
782 case 4: /* Immediate. */
787 /* Should never happen. */
791 static TCGv
gen_lea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
794 int mode
= extract32(insn
, 3, 3);
795 int reg0
= REG(insn
, 0);
796 return gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
799 /* Generate code to load/store a value from/into an EA. If WHAT > 0 this is
800 a write otherwise it is a read (0 == sign extend, -1 == zero extend).
801 ADDRP is non-null for readwrite operands. */
802 static TCGv
gen_ea_mode(CPUM68KState
*env
, DisasContext
*s
, int mode
, int reg0
,
803 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
)
805 TCGv reg
, tmp
, result
;
809 case 0: /* Data register direct. */
810 reg
= cpu_dregs
[reg0
];
811 if (what
== EA_STORE
) {
812 gen_partset_reg(opsize
, reg
, val
);
815 return gen_extend(reg
, opsize
, what
== EA_LOADS
);
817 case 1: /* Address register direct. */
818 reg
= get_areg(s
, reg0
);
819 if (what
== EA_STORE
) {
820 tcg_gen_mov_i32(reg
, val
);
823 return gen_extend(reg
, opsize
, what
== EA_LOADS
);
825 case 2: /* Indirect register */
826 reg
= get_areg(s
, reg0
);
827 return gen_ldst(s
, opsize
, reg
, val
, what
);
828 case 3: /* Indirect postincrement. */
829 reg
= get_areg(s
, reg0
);
830 result
= gen_ldst(s
, opsize
, reg
, val
, what
);
831 if (what
== EA_STORE
|| !addrp
) {
832 TCGv tmp
= tcg_temp_new();
833 if (reg0
== 7 && opsize
== OS_BYTE
&&
834 m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
835 tcg_gen_addi_i32(tmp
, reg
, 2);
837 tcg_gen_addi_i32(tmp
, reg
, opsize_bytes(opsize
));
839 delay_set_areg(s
, reg0
, tmp
, true);
842 case 4: /* Indirect predecrememnt. */
843 if (addrp
&& what
== EA_STORE
) {
846 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
847 if (IS_NULL_QREG(tmp
)) {
854 result
= gen_ldst(s
, opsize
, tmp
, val
, what
);
855 if (what
== EA_STORE
|| !addrp
) {
856 delay_set_areg(s
, reg0
, tmp
, false);
859 case 5: /* Indirect displacement. */
860 case 6: /* Indirect index + displacement. */
862 if (addrp
&& what
== EA_STORE
) {
865 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
866 if (IS_NULL_QREG(tmp
)) {
873 return gen_ldst(s
, opsize
, tmp
, val
, what
);
876 case 0: /* Absolute short. */
877 case 1: /* Absolute long. */
878 case 2: /* pc displacement */
879 case 3: /* pc index+displacement. */
881 case 4: /* Immediate. */
882 /* Sign extend values for consistency. */
885 if (what
== EA_LOADS
) {
886 offset
= (int8_t)read_im8(env
, s
);
888 offset
= read_im8(env
, s
);
892 if (what
== EA_LOADS
) {
893 offset
= (int16_t)read_im16(env
, s
);
895 offset
= read_im16(env
, s
);
899 offset
= read_im32(env
, s
);
902 g_assert_not_reached();
904 return tcg_const_i32(offset
);
909 /* Should never happen. */
913 static TCGv
gen_ea(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
914 int opsize
, TCGv val
, TCGv
*addrp
, ea_what what
)
916 int mode
= extract32(insn
, 3, 3);
917 int reg0
= REG(insn
, 0);
918 return gen_ea_mode(env
, s
, mode
, reg0
, opsize
, val
, addrp
, what
);
921 static TCGv_ptr
gen_fp_ptr(int freg
)
923 TCGv_ptr fp
= tcg_temp_new_ptr();
924 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fregs
[freg
]));
928 static TCGv_ptr
gen_fp_result_ptr(void)
930 TCGv_ptr fp
= tcg_temp_new_ptr();
931 tcg_gen_addi_ptr(fp
, cpu_env
, offsetof(CPUM68KState
, fp_result
));
935 static void gen_fp_move(TCGv_ptr dest
, TCGv_ptr src
)
940 t32
= tcg_temp_new();
941 tcg_gen_ld16u_i32(t32
, src
, offsetof(FPReg
, l
.upper
));
942 tcg_gen_st16_i32(t32
, dest
, offsetof(FPReg
, l
.upper
));
945 t64
= tcg_temp_new_i64();
946 tcg_gen_ld_i64(t64
, src
, offsetof(FPReg
, l
.lower
));
947 tcg_gen_st_i64(t64
, dest
, offsetof(FPReg
, l
.lower
));
948 tcg_temp_free_i64(t64
);
951 static void gen_load_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
)
955 int index
= IS_USER(s
);
957 t64
= tcg_temp_new_i64();
958 tmp
= tcg_temp_new();
961 tcg_gen_qemu_ld8s(tmp
, addr
, index
);
962 gen_helper_exts32(cpu_env
, fp
, tmp
);
965 tcg_gen_qemu_ld16s(tmp
, addr
, index
);
966 gen_helper_exts32(cpu_env
, fp
, tmp
);
969 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
970 gen_helper_exts32(cpu_env
, fp
, tmp
);
973 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
974 gen_helper_extf32(cpu_env
, fp
, tmp
);
977 tcg_gen_qemu_ld64(t64
, addr
, index
);
978 gen_helper_extf64(cpu_env
, fp
, t64
);
979 tcg_temp_free_i64(t64
);
982 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
983 gen_exception(s
, s
->insn_pc
, EXCP_FP_UNIMP
);
986 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
987 tcg_gen_shri_i32(tmp
, tmp
, 16);
988 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
989 tcg_gen_addi_i32(tmp
, addr
, 4);
990 tcg_gen_qemu_ld64(t64
, tmp
, index
);
991 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
994 /* unimplemented data type on 68040/ColdFire
995 * FIXME if needed for another FPU
997 gen_exception(s
, s
->insn_pc
, EXCP_FP_UNIMP
);
1000 g_assert_not_reached();
1003 tcg_temp_free_i64(t64
);
1004 gen_throws_exception
= gen_last_qop
;
1007 static void gen_store_fp(DisasContext
*s
, int opsize
, TCGv addr
, TCGv_ptr fp
)
1011 int index
= IS_USER(s
);
1013 t64
= tcg_temp_new_i64();
1014 tmp
= tcg_temp_new();
1017 gen_helper_reds32(tmp
, cpu_env
, fp
);
1018 tcg_gen_qemu_st8(tmp
, addr
, index
);
1021 gen_helper_reds32(tmp
, cpu_env
, fp
);
1022 tcg_gen_qemu_st16(tmp
, addr
, index
);
1025 gen_helper_reds32(tmp
, cpu_env
, fp
);
1026 tcg_gen_qemu_st32(tmp
, addr
, index
);
1029 gen_helper_redf32(tmp
, cpu_env
, fp
);
1030 tcg_gen_qemu_st32(tmp
, addr
, index
);
1033 gen_helper_redf64(t64
, cpu_env
, fp
);
1034 tcg_gen_qemu_st64(t64
, addr
, index
);
1037 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1038 gen_exception(s
, s
->insn_pc
, EXCP_FP_UNIMP
);
1041 tcg_gen_ld16u_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1042 tcg_gen_shli_i32(tmp
, tmp
, 16);
1043 tcg_gen_qemu_st32(tmp
, addr
, index
);
1044 tcg_gen_addi_i32(tmp
, addr
, 4);
1045 tcg_gen_ld_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1046 tcg_gen_qemu_st64(t64
, tmp
, index
);
1049 /* unimplemented data type on 68040/ColdFire
1050 * FIXME if needed for another FPU
1052 gen_exception(s
, s
->insn_pc
, EXCP_FP_UNIMP
);
1055 g_assert_not_reached();
1058 tcg_temp_free_i64(t64
);
1059 gen_throws_exception
= gen_last_qop
;
1062 static void gen_ldst_fp(DisasContext
*s
, int opsize
, TCGv addr
,
1063 TCGv_ptr fp
, ea_what what
)
1065 if (what
== EA_STORE
) {
1066 gen_store_fp(s
, opsize
, addr
, fp
);
1068 gen_load_fp(s
, opsize
, addr
, fp
);
1072 static int gen_ea_mode_fp(CPUM68KState
*env
, DisasContext
*s
, int mode
,
1073 int reg0
, int opsize
, TCGv_ptr fp
, ea_what what
)
1075 TCGv reg
, addr
, tmp
;
1079 case 0: /* Data register direct. */
1080 reg
= cpu_dregs
[reg0
];
1081 if (what
== EA_STORE
) {
1086 gen_helper_reds32(reg
, cpu_env
, fp
);
1089 gen_helper_redf32(reg
, cpu_env
, fp
);
1092 g_assert_not_reached();
1095 tmp
= tcg_temp_new();
1098 tcg_gen_ext8s_i32(tmp
, reg
);
1099 gen_helper_exts32(cpu_env
, fp
, tmp
);
1102 tcg_gen_ext16s_i32(tmp
, reg
);
1103 gen_helper_exts32(cpu_env
, fp
, tmp
);
1106 gen_helper_exts32(cpu_env
, fp
, reg
);
1109 gen_helper_extf32(cpu_env
, fp
, reg
);
1112 g_assert_not_reached();
1117 case 1: /* Address register direct. */
1119 case 2: /* Indirect register */
1120 addr
= get_areg(s
, reg0
);
1121 gen_ldst_fp(s
, opsize
, addr
, fp
, what
);
1123 case 3: /* Indirect postincrement. */
1124 addr
= cpu_aregs
[reg0
];
1125 gen_ldst_fp(s
, opsize
, addr
, fp
, what
);
1126 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(opsize
));
1128 case 4: /* Indirect predecrememnt. */
1129 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1130 if (IS_NULL_QREG(addr
)) {
1133 gen_ldst_fp(s
, opsize
, addr
, fp
, what
);
1134 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
1136 case 5: /* Indirect displacement. */
1137 case 6: /* Indirect index + displacement. */
1139 addr
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
1140 if (IS_NULL_QREG(addr
)) {
1143 gen_ldst_fp(s
, opsize
, addr
, fp
, what
);
1147 case 0: /* Absolute short. */
1148 case 1: /* Absolute long. */
1149 case 2: /* pc displacement */
1150 case 3: /* pc index+displacement. */
1152 case 4: /* Immediate. */
1153 if (what
== EA_STORE
) {
1158 tmp
= tcg_const_i32((int8_t)read_im8(env
, s
));
1159 gen_helper_exts32(cpu_env
, fp
, tmp
);
1163 tmp
= tcg_const_i32((int16_t)read_im16(env
, s
));
1164 gen_helper_exts32(cpu_env
, fp
, tmp
);
1168 tmp
= tcg_const_i32(read_im32(env
, s
));
1169 gen_helper_exts32(cpu_env
, fp
, tmp
);
1173 tmp
= tcg_const_i32(read_im32(env
, s
));
1174 gen_helper_extf32(cpu_env
, fp
, tmp
);
1178 t64
= tcg_const_i64(read_im64(env
, s
));
1179 gen_helper_extf64(cpu_env
, fp
, t64
);
1180 tcg_temp_free_i64(t64
);
1183 if (m68k_feature(s
->env
, M68K_FEATURE_CF_FPU
)) {
1184 gen_exception(s
, s
->insn_pc
, EXCP_FP_UNIMP
);
1187 tmp
= tcg_const_i32(read_im32(env
, s
) >> 16);
1188 tcg_gen_st16_i32(tmp
, fp
, offsetof(FPReg
, l
.upper
));
1190 t64
= tcg_const_i64(read_im64(env
, s
));
1191 tcg_gen_st_i64(t64
, fp
, offsetof(FPReg
, l
.lower
));
1192 tcg_temp_free_i64(t64
);
1195 /* unimplemented data type on 68040/ColdFire
1196 * FIXME if needed for another FPU
1198 gen_exception(s
, s
->insn_pc
, EXCP_FP_UNIMP
);
1201 g_assert_not_reached();
1211 static int gen_ea_fp(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
1212 int opsize
, TCGv_ptr fp
, ea_what what
)
1214 int mode
= extract32(insn
, 3, 3);
1215 int reg0
= REG(insn
, 0);
1216 return gen_ea_mode_fp(env
, s
, mode
, reg0
, opsize
, fp
, what
);
1227 static void gen_cc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
1233 /* The CC_OP_CMP form can handle most normal comparisons directly. */
1234 if (op
== CC_OP_CMPB
|| op
== CC_OP_CMPW
|| op
== CC_OP_CMPL
) {
1241 tcond
= TCG_COND_LEU
;
1245 tcond
= TCG_COND_LTU
;
1249 tcond
= TCG_COND_EQ
;
1254 c
->v2
= tcg_const_i32(0);
1255 c
->v1
= tmp
= tcg_temp_new();
1256 tcg_gen_sub_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1257 gen_ext(tmp
, tmp
, op
- CC_OP_CMPB
, 1);
1261 tcond
= TCG_COND_LT
;
1265 tcond
= TCG_COND_LE
;
1272 c
->v2
= tcg_const_i32(0);
1278 tcond
= TCG_COND_NEVER
;
1280 case 14: /* GT (!(Z || (N ^ V))) */
1281 case 15: /* LE (Z || (N ^ V)) */
1282 /* Logic operations clear V, which simplifies LE to (Z || N),
1283 and since Z and N are co-located, this becomes a normal
1285 if (op
== CC_OP_LOGIC
) {
1287 tcond
= TCG_COND_LE
;
1291 case 12: /* GE (!(N ^ V)) */
1292 case 13: /* LT (N ^ V) */
1293 /* Logic operations clear V, which simplifies this to N. */
1294 if (op
!= CC_OP_LOGIC
) {
1298 case 10: /* PL (!N) */
1299 case 11: /* MI (N) */
1300 /* Several cases represent N normally. */
1301 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1302 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1303 op
== CC_OP_LOGIC
) {
1305 tcond
= TCG_COND_LT
;
1309 case 6: /* NE (!Z) */
1310 case 7: /* EQ (Z) */
1311 /* Some cases fold Z into N. */
1312 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1313 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
||
1314 op
== CC_OP_LOGIC
) {
1315 tcond
= TCG_COND_EQ
;
1320 case 4: /* CC (!C) */
1321 case 5: /* CS (C) */
1322 /* Some cases fold C into X. */
1323 if (op
== CC_OP_ADDB
|| op
== CC_OP_ADDW
|| op
== CC_OP_ADDL
||
1324 op
== CC_OP_SUBB
|| op
== CC_OP_SUBW
|| op
== CC_OP_SUBL
) {
1325 tcond
= TCG_COND_NE
;
1330 case 8: /* VC (!V) */
1331 case 9: /* VS (V) */
1332 /* Logic operations clear V and C. */
1333 if (op
== CC_OP_LOGIC
) {
1334 tcond
= TCG_COND_NEVER
;
1341 /* Otherwise, flush flag state to CC_OP_FLAGS. */
1348 /* Invalid, or handled above. */
1350 case 2: /* HI (!C && !Z) -> !(C || Z)*/
1351 case 3: /* LS (C || Z) */
1352 c
->v1
= tmp
= tcg_temp_new();
1354 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1355 tcg_gen_or_i32(tmp
, tmp
, QREG_CC_C
);
1356 tcond
= TCG_COND_NE
;
1358 case 4: /* CC (!C) */
1359 case 5: /* CS (C) */
1361 tcond
= TCG_COND_NE
;
1363 case 6: /* NE (!Z) */
1364 case 7: /* EQ (Z) */
1366 tcond
= TCG_COND_EQ
;
1368 case 8: /* VC (!V) */
1369 case 9: /* VS (V) */
1371 tcond
= TCG_COND_LT
;
1373 case 10: /* PL (!N) */
1374 case 11: /* MI (N) */
1376 tcond
= TCG_COND_LT
;
1378 case 12: /* GE (!(N ^ V)) */
1379 case 13: /* LT (N ^ V) */
1380 c
->v1
= tmp
= tcg_temp_new();
1382 tcg_gen_xor_i32(tmp
, QREG_CC_N
, QREG_CC_V
);
1383 tcond
= TCG_COND_LT
;
1385 case 14: /* GT (!(Z || (N ^ V))) */
1386 case 15: /* LE (Z || (N ^ V)) */
1387 c
->v1
= tmp
= tcg_temp_new();
1389 tcg_gen_setcond_i32(TCG_COND_EQ
, tmp
, QREG_CC_Z
, c
->v2
);
1390 tcg_gen_neg_i32(tmp
, tmp
);
1391 tmp2
= tcg_temp_new();
1392 tcg_gen_xor_i32(tmp2
, QREG_CC_N
, QREG_CC_V
);
1393 tcg_gen_or_i32(tmp
, tmp
, tmp2
);
1394 tcg_temp_free(tmp2
);
1395 tcond
= TCG_COND_LT
;
1400 if ((cond
& 1) == 0) {
1401 tcond
= tcg_invert_cond(tcond
);
1406 static void free_cond(DisasCompare
*c
)
1409 tcg_temp_free(c
->v1
);
1412 tcg_temp_free(c
->v2
);
1416 static void gen_jmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
1420 gen_cc_cond(&c
, s
, cond
);
1422 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
1426 /* Force a TB lookup after an instruction that changes the CPU state. */
1427 static void gen_lookup_tb(DisasContext
*s
)
1430 tcg_gen_movi_i32(QREG_PC
, s
->pc
);
1431 s
->is_jmp
= DISAS_UPDATE
;
1434 #define SRC_EA(env, result, opsize, op_sign, addrp) do { \
1435 result = gen_ea(env, s, insn, opsize, NULL_QREG, addrp, \
1436 op_sign ? EA_LOADS : EA_LOADU); \
1437 if (IS_NULL_QREG(result)) { \
1438 gen_addr_fault(s); \
1443 #define DEST_EA(env, insn, opsize, val, addrp) do { \
1444 TCGv ea_result = gen_ea(env, s, insn, opsize, val, addrp, EA_STORE); \
1445 if (IS_NULL_QREG(ea_result)) { \
1446 gen_addr_fault(s); \
1451 static inline bool use_goto_tb(DisasContext
*s
, uint32_t dest
)
1453 #ifndef CONFIG_USER_ONLY
1454 return (s
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) ||
1455 (s
->insn_pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
1461 /* Generate a jump to an immediate address. */
1462 static void gen_jmp_tb(DisasContext
*s
, int n
, uint32_t dest
)
1464 if (unlikely(s
->singlestep_enabled
)) {
1465 gen_exception(s
, dest
, EXCP_DEBUG
);
1466 } else if (use_goto_tb(s
, dest
)) {
1468 tcg_gen_movi_i32(QREG_PC
, dest
);
1469 tcg_gen_exit_tb((uintptr_t)s
->tb
+ n
);
1471 gen_jmp_im(s
, dest
);
1474 s
->is_jmp
= DISAS_TB_JUMP
;
1483 cond
= (insn
>> 8) & 0xf;
1484 gen_cc_cond(&c
, s
, cond
);
1486 tmp
= tcg_temp_new();
1487 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
1490 tcg_gen_neg_i32(tmp
, tmp
);
1491 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
1503 reg
= DREG(insn
, 0);
1505 offset
= (int16_t)read_im16(env
, s
);
1506 l1
= gen_new_label();
1507 gen_jmpcc(s
, (insn
>> 8) & 0xf, l1
);
1509 tmp
= tcg_temp_new();
1510 tcg_gen_ext16s_i32(tmp
, reg
);
1511 tcg_gen_addi_i32(tmp
, tmp
, -1);
1512 gen_partset_reg(OS_WORD
, reg
, tmp
);
1513 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, -1, l1
);
1514 gen_jmp_tb(s
, 1, base
+ offset
);
1516 gen_jmp_tb(s
, 0, s
->pc
);
1519 DISAS_INSN(undef_mac
)
1521 gen_exception(s
, s
->pc
- 2, EXCP_LINEA
);
1524 DISAS_INSN(undef_fpu
)
1526 gen_exception(s
, s
->pc
- 2, EXCP_LINEF
);
1531 /* ??? This is both instructions that are as yet unimplemented
1532 for the 680x0 series, as well as those that are implemented
1533 but actually illegal for CPU32 or pre-68020. */
1534 qemu_log_mask(LOG_UNIMP
, "Illegal instruction: %04x @ %08x",
1536 gen_exception(s
, s
->pc
- 2, EXCP_UNSUPPORTED
);
1546 sign
= (insn
& 0x100) != 0;
1547 reg
= DREG(insn
, 9);
1548 tmp
= tcg_temp_new();
1550 tcg_gen_ext16s_i32(tmp
, reg
);
1552 tcg_gen_ext16u_i32(tmp
, reg
);
1553 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1554 tcg_gen_mul_i32(tmp
, tmp
, src
);
1555 tcg_gen_mov_i32(reg
, tmp
);
1556 gen_logic_cc(s
, tmp
, OS_LONG
);
1566 /* divX.w <EA>,Dn 32/16 -> 16r:16q */
1568 sign
= (insn
& 0x100) != 0;
1570 /* dest.l / src.w */
1572 SRC_EA(env
, src
, OS_WORD
, sign
, NULL
);
1573 destr
= tcg_const_i32(REG(insn
, 9));
1575 gen_helper_divsw(cpu_env
, destr
, src
);
1577 gen_helper_divuw(cpu_env
, destr
, src
);
1579 tcg_temp_free(destr
);
1581 set_cc_op(s
, CC_OP_FLAGS
);
1590 ext
= read_im16(env
, s
);
1592 sign
= (ext
& 0x0800) != 0;
1595 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
1596 gen_exception(s
, s
->insn_pc
, EXCP_ILLEGAL
);
1600 /* divX.l <EA>, Dr:Dq 64/32 -> 32r:32q */
1602 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1603 num
= tcg_const_i32(REG(ext
, 12));
1604 reg
= tcg_const_i32(REG(ext
, 0));
1606 gen_helper_divsll(cpu_env
, num
, reg
, den
);
1608 gen_helper_divull(cpu_env
, num
, reg
, den
);
1612 set_cc_op(s
, CC_OP_FLAGS
);
1616 /* divX.l <EA>, Dq 32/32 -> 32q */
1617 /* divXl.l <EA>, Dr:Dq 32/32 -> 32r:32q */
1619 SRC_EA(env
, den
, OS_LONG
, 0, NULL
);
1620 num
= tcg_const_i32(REG(ext
, 12));
1621 reg
= tcg_const_i32(REG(ext
, 0));
1623 gen_helper_divsl(cpu_env
, num
, reg
, den
);
1625 gen_helper_divul(cpu_env
, num
, reg
, den
);
1630 set_cc_op(s
, CC_OP_FLAGS
);
1633 static void bcd_add(TCGv dest
, TCGv src
)
1637 /* dest10 = dest10 + src10 + X
1641 * t3 = t2 + dest + X
1645 * t7 = (t6 >> 2) | (t6 >> 3)
1649 /* t1 = (src + 0x066) + dest + X
1650 * = result with some possible exceding 0x6
1653 t0
= tcg_const_i32(0x066);
1654 tcg_gen_add_i32(t0
, t0
, src
);
1656 t1
= tcg_temp_new();
1657 tcg_gen_add_i32(t1
, t0
, dest
);
1658 tcg_gen_add_i32(t1
, t1
, QREG_CC_X
);
1660 /* we will remove exceding 0x6 where there is no carry */
1662 /* t0 = (src + 0x0066) ^ dest
1663 * = t1 without carries
1666 tcg_gen_xor_i32(t0
, t0
, dest
);
1668 /* extract the carries
1670 * = only the carries
1673 tcg_gen_xor_i32(t0
, t0
, t1
);
1675 /* generate 0x1 where there is no carry
1676 * and for each 0x10, generate a 0x6
1679 tcg_gen_shri_i32(t0
, t0
, 3);
1680 tcg_gen_not_i32(t0
, t0
);
1681 tcg_gen_andi_i32(t0
, t0
, 0x22);
1682 tcg_gen_add_i32(dest
, t0
, t0
);
1683 tcg_gen_add_i32(dest
, dest
, t0
);
1686 /* remove the exceding 0x6
1687 * for digits that have not generated a carry
1690 tcg_gen_sub_i32(dest
, t1
, dest
);
1694 static void bcd_sub(TCGv dest
, TCGv src
)
1698 /* dest10 = dest10 - src10 - X
1699 * = bcd_add(dest + 1 - X, 0x199 - src)
1702 /* t0 = 0x066 + (0x199 - src) */
1704 t0
= tcg_temp_new();
1705 tcg_gen_subfi_i32(t0
, 0x1ff, src
);
1707 /* t1 = t0 + dest + 1 - X*/
1709 t1
= tcg_temp_new();
1710 tcg_gen_add_i32(t1
, t0
, dest
);
1711 tcg_gen_addi_i32(t1
, t1
, 1);
1712 tcg_gen_sub_i32(t1
, t1
, QREG_CC_X
);
1714 /* t2 = t0 ^ dest */
1716 t2
= tcg_temp_new();
1717 tcg_gen_xor_i32(t2
, t0
, dest
);
1721 tcg_gen_xor_i32(t0
, t1
, t2
);
1724 * t0 = (t2 >> 2) | (t2 >> 3)
1726 * to fit on 8bit operands, changed in:
1728 * t2 = ~(t0 >> 3) & 0x22
1733 tcg_gen_shri_i32(t2
, t0
, 3);
1734 tcg_gen_not_i32(t2
, t2
);
1735 tcg_gen_andi_i32(t2
, t2
, 0x22);
1736 tcg_gen_add_i32(t0
, t2
, t2
);
1737 tcg_gen_add_i32(t0
, t0
, t2
);
1740 /* return t1 - t0 */
1742 tcg_gen_sub_i32(dest
, t1
, t0
);
1747 static void bcd_flags(TCGv val
)
1749 tcg_gen_andi_i32(QREG_CC_C
, val
, 0x0ff);
1750 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_C
);
1752 tcg_gen_extract_i32(QREG_CC_C
, val
, 8, 1);
1754 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
1757 DISAS_INSN(abcd_reg
)
1762 gen_flush_flags(s
); /* !Z is sticky */
1764 src
= gen_extend(DREG(insn
, 0), OS_BYTE
, 0);
1765 dest
= gen_extend(DREG(insn
, 9), OS_BYTE
, 0);
1767 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1772 DISAS_INSN(abcd_mem
)
1774 TCGv src
, dest
, addr
;
1776 gen_flush_flags(s
); /* !Z is sticky */
1778 /* Indirect pre-decrement load (mode 4) */
1780 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1781 NULL_QREG
, NULL
, EA_LOADU
);
1782 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1783 NULL_QREG
, &addr
, EA_LOADU
);
1787 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
, EA_STORE
);
1792 DISAS_INSN(sbcd_reg
)
1796 gen_flush_flags(s
); /* !Z is sticky */
1798 src
= gen_extend(DREG(insn
, 0), OS_BYTE
, 0);
1799 dest
= gen_extend(DREG(insn
, 9), OS_BYTE
, 0);
1803 gen_partset_reg(OS_BYTE
, DREG(insn
, 9), dest
);
1808 DISAS_INSN(sbcd_mem
)
1810 TCGv src
, dest
, addr
;
1812 gen_flush_flags(s
); /* !Z is sticky */
1814 /* Indirect pre-decrement load (mode 4) */
1816 src
= gen_ea_mode(env
, s
, 4, REG(insn
, 0), OS_BYTE
,
1817 NULL_QREG
, NULL
, EA_LOADU
);
1818 dest
= gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
,
1819 NULL_QREG
, &addr
, EA_LOADU
);
1823 gen_ea_mode(env
, s
, 4, REG(insn
, 9), OS_BYTE
, dest
, &addr
, EA_STORE
);
1833 gen_flush_flags(s
); /* !Z is sticky */
1835 SRC_EA(env
, src
, OS_BYTE
, 0, &addr
);
1837 dest
= tcg_const_i32(0);
1840 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
1844 tcg_temp_free(dest
);
1857 add
= (insn
& 0x4000) != 0;
1858 opsize
= insn_opsize(insn
);
1859 reg
= gen_extend(DREG(insn
, 9), opsize
, 1);
1860 dest
= tcg_temp_new();
1862 SRC_EA(env
, tmp
, opsize
, 1, &addr
);
1866 SRC_EA(env
, src
, opsize
, 1, NULL
);
1869 tcg_gen_add_i32(dest
, tmp
, src
);
1870 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, src
);
1871 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
1873 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, tmp
, src
);
1874 tcg_gen_sub_i32(dest
, tmp
, src
);
1875 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
1877 gen_update_cc_add(dest
, src
, opsize
);
1879 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1881 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
1883 tcg_temp_free(dest
);
1886 /* Reverse the order of the bits in REG. */
1890 reg
= DREG(insn
, 0);
1891 gen_helper_bitrev(reg
, reg
);
1894 DISAS_INSN(bitop_reg
)
1904 if ((insn
& 0x38) != 0)
1908 op
= (insn
>> 6) & 3;
1909 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
1912 src2
= tcg_temp_new();
1913 if (opsize
== OS_BYTE
)
1914 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 7);
1916 tcg_gen_andi_i32(src2
, DREG(insn
, 9), 31);
1918 tmp
= tcg_const_i32(1);
1919 tcg_gen_shl_i32(tmp
, tmp
, src2
);
1920 tcg_temp_free(src2
);
1922 tcg_gen_and_i32(QREG_CC_Z
, src1
, tmp
);
1924 dest
= tcg_temp_new();
1927 tcg_gen_xor_i32(dest
, src1
, tmp
);
1930 tcg_gen_andc_i32(dest
, src1
, tmp
);
1933 tcg_gen_or_i32(dest
, src1
, tmp
);
1940 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
1942 tcg_temp_free(dest
);
1948 reg
= DREG(insn
, 0);
1950 gen_helper_sats(reg
, reg
, QREG_CC_V
);
1951 gen_logic_cc(s
, reg
, OS_LONG
);
1954 static void gen_push(DisasContext
*s
, TCGv val
)
1958 tmp
= tcg_temp_new();
1959 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
1960 gen_store(s
, OS_LONG
, tmp
, val
);
1961 tcg_gen_mov_i32(QREG_SP
, tmp
);
1965 static TCGv
mreg(int reg
)
1969 return cpu_dregs
[reg
];
1972 return cpu_aregs
[reg
& 7];
1977 TCGv addr
, incr
, tmp
, r
[16];
1978 int is_load
= (insn
& 0x0400) != 0;
1979 int opsize
= (insn
& 0x40) != 0 ? OS_LONG
: OS_WORD
;
1980 uint16_t mask
= read_im16(env
, s
);
1981 int mode
= extract32(insn
, 3, 3);
1982 int reg0
= REG(insn
, 0);
1985 tmp
= cpu_aregs
[reg0
];
1988 case 0: /* data register direct */
1989 case 1: /* addr register direct */
1994 case 2: /* indirect */
1997 case 3: /* indirect post-increment */
1999 /* post-increment is not allowed */
2004 case 4: /* indirect pre-decrement */
2006 /* pre-decrement is not allowed */
2009 /* We want a bare copy of the address reg, without any pre-decrement
2010 adjustment, as gen_lea would provide. */
2014 tmp
= gen_lea_mode(env
, s
, mode
, reg0
, opsize
);
2015 if (IS_NULL_QREG(tmp
)) {
2021 addr
= tcg_temp_new();
2022 tcg_gen_mov_i32(addr
, tmp
);
2023 incr
= tcg_const_i32(opsize_bytes(opsize
));
2026 /* memory to register */
2027 for (i
= 0; i
< 16; i
++) {
2028 if (mask
& (1 << i
)) {
2029 r
[i
] = gen_load(s
, opsize
, addr
, 1);
2030 tcg_gen_add_i32(addr
, addr
, incr
);
2033 for (i
= 0; i
< 16; i
++) {
2034 if (mask
& (1 << i
)) {
2035 tcg_gen_mov_i32(mreg(i
), r
[i
]);
2036 tcg_temp_free(r
[i
]);
2040 /* post-increment: movem (An)+,X */
2041 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2044 /* register to memory */
2046 /* pre-decrement: movem X,-(An) */
2047 for (i
= 15; i
>= 0; i
--) {
2048 if ((mask
<< i
) & 0x8000) {
2049 tcg_gen_sub_i32(addr
, addr
, incr
);
2050 if (reg0
+ 8 == i
&&
2051 m68k_feature(s
->env
, M68K_FEATURE_EXT_FULL
)) {
2052 /* M68020+: if the addressing register is the
2053 * register moved to memory, the value written
2054 * is the initial value decremented by the size of
2055 * the operation, regardless of how many actual
2056 * stores have been performed until this point.
2057 * M68000/M68010: the value is the initial value.
2059 tmp
= tcg_temp_new();
2060 tcg_gen_sub_i32(tmp
, cpu_aregs
[reg0
], incr
);
2061 gen_store(s
, opsize
, addr
, tmp
);
2064 gen_store(s
, opsize
, addr
, mreg(i
));
2068 tcg_gen_mov_i32(cpu_aregs
[reg0
], addr
);
2070 for (i
= 0; i
< 16; i
++) {
2071 if (mask
& (1 << i
)) {
2072 gen_store(s
, opsize
, addr
, mreg(i
));
2073 tcg_gen_add_i32(addr
, addr
, incr
);
2079 tcg_temp_free(incr
);
2080 tcg_temp_free(addr
);
2083 DISAS_INSN(bitop_im
)
2093 if ((insn
& 0x38) != 0)
2097 op
= (insn
>> 6) & 3;
2099 bitnum
= read_im16(env
, s
);
2100 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
2101 if (bitnum
& 0xfe00) {
2102 disas_undef(env
, s
, insn
);
2106 if (bitnum
& 0xff00) {
2107 disas_undef(env
, s
, insn
);
2112 SRC_EA(env
, src1
, opsize
, 0, op
? &addr
: NULL
);
2115 if (opsize
== OS_BYTE
)
2121 tcg_gen_andi_i32(QREG_CC_Z
, src1
, mask
);
2124 tmp
= tcg_temp_new();
2127 tcg_gen_xori_i32(tmp
, src1
, mask
);
2130 tcg_gen_andi_i32(tmp
, src1
, ~mask
);
2133 tcg_gen_ori_i32(tmp
, src1
, mask
);
2138 DEST_EA(env
, insn
, opsize
, tmp
, &addr
);
2143 DISAS_INSN(arith_im
)
2152 op
= (insn
>> 9) & 7;
2153 opsize
= insn_opsize(insn
);
2156 im
= tcg_const_i32((int8_t)read_im8(env
, s
));
2159 im
= tcg_const_i32((int16_t)read_im16(env
, s
));
2162 im
= tcg_const_i32(read_im32(env
, s
));
2167 SRC_EA(env
, src1
, opsize
, 1, (op
== 6) ? NULL
: &addr
);
2168 dest
= tcg_temp_new();
2171 tcg_gen_or_i32(dest
, src1
, im
);
2172 gen_logic_cc(s
, dest
, opsize
);
2175 tcg_gen_and_i32(dest
, src1
, im
);
2176 gen_logic_cc(s
, dest
, opsize
);
2179 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, src1
, im
);
2180 tcg_gen_sub_i32(dest
, src1
, im
);
2181 gen_update_cc_add(dest
, im
, opsize
);
2182 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2185 tcg_gen_add_i32(dest
, src1
, im
);
2186 gen_update_cc_add(dest
, im
, opsize
);
2187 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, im
);
2188 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2191 tcg_gen_xor_i32(dest
, src1
, im
);
2192 gen_logic_cc(s
, dest
, opsize
);
2195 gen_update_cc_cmp(s
, src1
, im
, opsize
);
2202 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2204 tcg_temp_free(dest
);
2216 switch ((insn
>> 9) & 3) {
2230 g_assert_not_reached();
2233 ext
= read_im16(env
, s
);
2235 /* cas Dc,Du,<EA> */
2237 addr
= gen_lea(env
, s
, insn
, opsize
);
2238 if (IS_NULL_QREG(addr
)) {
2243 cmp
= gen_extend(DREG(ext
, 0), opsize
, 1);
2245 /* if <EA> == Dc then
2247 * Dc = <EA> (because <EA> == Dc)
2252 load
= tcg_temp_new();
2253 tcg_gen_atomic_cmpxchg_i32(load
, addr
, cmp
, DREG(ext
, 6),
2255 /* update flags before setting cmp to load */
2256 gen_update_cc_cmp(s
, load
, cmp
, opsize
);
2257 gen_partset_reg(opsize
, DREG(ext
, 0), load
);
2259 tcg_temp_free(load
);
2261 switch (extract32(insn
, 3, 3)) {
2262 case 3: /* Indirect postincrement. */
2263 tcg_gen_addi_i32(AREG(insn
, 0), addr
, opsize_bytes(opsize
));
2265 case 4: /* Indirect predecrememnt. */
2266 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
2273 uint16_t ext1
, ext2
;
2277 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2279 ext1
= read_im16(env
, s
);
2281 if (ext1
& 0x8000) {
2282 /* Address Register */
2283 addr1
= AREG(ext1
, 12);
2286 addr1
= DREG(ext1
, 12);
2289 ext2
= read_im16(env
, s
);
2290 if (ext2
& 0x8000) {
2291 /* Address Register */
2292 addr2
= AREG(ext2
, 12);
2295 addr2
= DREG(ext2
, 12);
2298 /* if (R1) == Dc1 && (R2) == Dc2 then
2306 regs
= tcg_const_i32(REG(ext2
, 6) |
2307 (REG(ext1
, 6) << 3) |
2308 (REG(ext2
, 0) << 6) |
2309 (REG(ext1
, 0) << 9));
2310 gen_helper_cas2w(cpu_env
, regs
, addr1
, addr2
);
2311 tcg_temp_free(regs
);
2313 /* Note that cas2w also assigned to env->cc_op. */
2314 s
->cc_op
= CC_OP_CMPW
;
2315 s
->cc_op_synced
= 1;
2320 uint16_t ext1
, ext2
;
2321 TCGv addr1
, addr2
, regs
;
2323 /* cas2 Dc1:Dc2,Du1:Du2,(Rn1):(Rn2) */
2325 ext1
= read_im16(env
, s
);
2327 if (ext1
& 0x8000) {
2328 /* Address Register */
2329 addr1
= AREG(ext1
, 12);
2332 addr1
= DREG(ext1
, 12);
2335 ext2
= read_im16(env
, s
);
2336 if (ext2
& 0x8000) {
2337 /* Address Register */
2338 addr2
= AREG(ext2
, 12);
2341 addr2
= DREG(ext2
, 12);
2344 /* if (R1) == Dc1 && (R2) == Dc2 then
2352 regs
= tcg_const_i32(REG(ext2
, 6) |
2353 (REG(ext1
, 6) << 3) |
2354 (REG(ext2
, 0) << 6) |
2355 (REG(ext1
, 0) << 9));
2356 gen_helper_cas2l(cpu_env
, regs
, addr1
, addr2
);
2357 tcg_temp_free(regs
);
2359 /* Note that cas2l also assigned to env->cc_op. */
2360 s
->cc_op
= CC_OP_CMPL
;
2361 s
->cc_op_synced
= 1;
2368 reg
= DREG(insn
, 0);
2369 tcg_gen_bswap32_i32(reg
, reg
);
2379 switch (insn
>> 12) {
2380 case 1: /* move.b */
2383 case 2: /* move.l */
2386 case 3: /* move.w */
2392 SRC_EA(env
, src
, opsize
, 1, NULL
);
2393 op
= (insn
>> 6) & 7;
2396 /* The value will already have been sign extended. */
2397 dest
= AREG(insn
, 9);
2398 tcg_gen_mov_i32(dest
, src
);
2402 dest_ea
= ((insn
>> 9) & 7) | (op
<< 3);
2403 DEST_EA(env
, dest_ea
, opsize
, src
, NULL
);
2404 /* This will be correct because loads sign extend. */
2405 gen_logic_cc(s
, src
, opsize
);
2416 opsize
= insn_opsize(insn
);
2417 SRC_EA(env
, src
, opsize
, 1, &addr
);
2419 gen_flush_flags(s
); /* compute old Z */
2421 /* Perform substract with borrow.
2422 * (X, N) = -(src + X);
2425 z
= tcg_const_i32(0);
2426 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, z
, QREG_CC_X
, z
);
2427 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, z
, z
, QREG_CC_N
, QREG_CC_X
);
2429 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
2431 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
2433 /* Compute signed-overflow for negation. The normal formula for
2434 * subtraction is (res ^ src) & (src ^ dest), but with dest==0
2435 * this simplies to res & src.
2438 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_N
, src
);
2440 /* Copy the rest of the results into place. */
2441 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
2442 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
2444 set_cc_op(s
, CC_OP_FLAGS
);
2446 /* result is in QREG_CC_N */
2448 DEST_EA(env
, insn
, opsize
, QREG_CC_N
, &addr
);
2456 reg
= AREG(insn
, 9);
2457 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2458 if (IS_NULL_QREG(tmp
)) {
2462 tcg_gen_mov_i32(reg
, tmp
);
2470 zero
= tcg_const_i32(0);
2472 opsize
= insn_opsize(insn
);
2473 DEST_EA(env
, insn
, opsize
, zero
, NULL
);
2474 gen_logic_cc(s
, zero
, opsize
);
2475 tcg_temp_free(zero
);
2478 static TCGv
gen_get_ccr(DisasContext
*s
)
2484 dest
= tcg_temp_new();
2485 gen_helper_get_ccr(dest
, cpu_env
);
2489 DISAS_INSN(move_from_ccr
)
2493 ccr
= gen_get_ccr(s
);
2494 DEST_EA(env
, insn
, OS_WORD
, ccr
, NULL
);
2504 opsize
= insn_opsize(insn
);
2505 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2506 dest
= tcg_temp_new();
2507 tcg_gen_neg_i32(dest
, src1
);
2508 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2509 gen_update_cc_add(dest
, src1
, opsize
);
2510 tcg_gen_setcondi_i32(TCG_COND_NE
, QREG_CC_X
, dest
, 0);
2511 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2512 tcg_temp_free(dest
);
2515 static void gen_set_sr_im(DisasContext
*s
, uint16_t val
, int ccr_only
)
2518 tcg_gen_movi_i32(QREG_CC_C
, val
& CCF_C
? 1 : 0);
2519 tcg_gen_movi_i32(QREG_CC_V
, val
& CCF_V
? -1 : 0);
2520 tcg_gen_movi_i32(QREG_CC_Z
, val
& CCF_Z
? 0 : 1);
2521 tcg_gen_movi_i32(QREG_CC_N
, val
& CCF_N
? -1 : 0);
2522 tcg_gen_movi_i32(QREG_CC_X
, val
& CCF_X
? 1 : 0);
2524 gen_helper_set_sr(cpu_env
, tcg_const_i32(val
));
2526 set_cc_op(s
, CC_OP_FLAGS
);
2529 static void gen_set_sr(CPUM68KState
*env
, DisasContext
*s
, uint16_t insn
,
2532 if ((insn
& 0x38) == 0) {
2534 gen_helper_set_ccr(cpu_env
, DREG(insn
, 0));
2536 gen_helper_set_sr(cpu_env
, DREG(insn
, 0));
2538 set_cc_op(s
, CC_OP_FLAGS
);
2539 } else if ((insn
& 0x3f) == 0x3c) {
2541 val
= read_im16(env
, s
);
2542 gen_set_sr_im(s
, val
, ccr_only
);
2544 disas_undef(env
, s
, insn
);
2549 DISAS_INSN(move_to_ccr
)
2551 gen_set_sr(env
, s
, insn
, 1);
2561 opsize
= insn_opsize(insn
);
2562 SRC_EA(env
, src1
, opsize
, 1, &addr
);
2563 dest
= tcg_temp_new();
2564 tcg_gen_not_i32(dest
, src1
);
2565 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2566 gen_logic_cc(s
, dest
, opsize
);
2575 src1
= tcg_temp_new();
2576 src2
= tcg_temp_new();
2577 reg
= DREG(insn
, 0);
2578 tcg_gen_shli_i32(src1
, reg
, 16);
2579 tcg_gen_shri_i32(src2
, reg
, 16);
2580 tcg_gen_or_i32(reg
, src1
, src2
);
2581 tcg_temp_free(src2
);
2582 tcg_temp_free(src1
);
2583 gen_logic_cc(s
, reg
, OS_LONG
);
2588 gen_exception(s
, s
->pc
- 2, EXCP_DEBUG
);
2595 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2596 if (IS_NULL_QREG(tmp
)) {
2609 reg
= DREG(insn
, 0);
2610 op
= (insn
>> 6) & 7;
2611 tmp
= tcg_temp_new();
2613 tcg_gen_ext16s_i32(tmp
, reg
);
2615 tcg_gen_ext8s_i32(tmp
, reg
);
2617 gen_partset_reg(OS_WORD
, reg
, tmp
);
2619 tcg_gen_mov_i32(reg
, tmp
);
2620 gen_logic_cc(s
, tmp
, OS_LONG
);
2629 opsize
= insn_opsize(insn
);
2630 SRC_EA(env
, tmp
, opsize
, 1, NULL
);
2631 gen_logic_cc(s
, tmp
, opsize
);
2636 /* Implemented as a NOP. */
2641 gen_exception(s
, s
->pc
- 2, EXCP_ILLEGAL
);
2644 /* ??? This should be atomic. */
2651 dest
= tcg_temp_new();
2652 SRC_EA(env
, src1
, OS_BYTE
, 1, &addr
);
2653 gen_logic_cc(s
, src1
, OS_BYTE
);
2654 tcg_gen_ori_i32(dest
, src1
, 0x80);
2655 DEST_EA(env
, insn
, OS_BYTE
, dest
, &addr
);
2656 tcg_temp_free(dest
);
2665 ext
= read_im16(env
, s
);
2670 if (!m68k_feature(s
->env
, M68K_FEATURE_QUAD_MULDIV
)) {
2671 gen_exception(s
, s
->pc
- 4, EXCP_UNSUPPORTED
);
2675 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2678 tcg_gen_muls2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2680 tcg_gen_mulu2_i32(QREG_CC_Z
, QREG_CC_N
, src1
, DREG(ext
, 12));
2682 /* if Dl == Dh, 68040 returns low word */
2683 tcg_gen_mov_i32(DREG(ext
, 0), QREG_CC_N
);
2684 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_Z
);
2685 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
);
2687 tcg_gen_movi_i32(QREG_CC_V
, 0);
2688 tcg_gen_movi_i32(QREG_CC_C
, 0);
2690 set_cc_op(s
, CC_OP_FLAGS
);
2693 SRC_EA(env
, src1
, OS_LONG
, 0, NULL
);
2694 if (m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
2695 tcg_gen_movi_i32(QREG_CC_C
, 0);
2697 tcg_gen_muls2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2698 /* QREG_CC_V is -(QREG_CC_V != (QREG_CC_N >> 31)) */
2699 tcg_gen_sari_i32(QREG_CC_Z
, QREG_CC_N
, 31);
2700 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_Z
);
2702 tcg_gen_mulu2_i32(QREG_CC_N
, QREG_CC_V
, src1
, DREG(ext
, 12));
2703 /* QREG_CC_V is -(QREG_CC_V != 0), use QREG_CC_C as 0 */
2704 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, QREG_CC_C
);
2706 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
2707 tcg_gen_mov_i32(DREG(ext
, 12), QREG_CC_N
);
2709 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
2711 set_cc_op(s
, CC_OP_FLAGS
);
2713 /* The upper 32 bits of the product are discarded, so
2714 muls.l and mulu.l are functionally equivalent. */
2715 tcg_gen_mul_i32(DREG(ext
, 12), src1
, DREG(ext
, 12));
2716 gen_logic_cc(s
, DREG(ext
, 12), OS_LONG
);
2720 static void gen_link(DisasContext
*s
, uint16_t insn
, int32_t offset
)
2725 reg
= AREG(insn
, 0);
2726 tmp
= tcg_temp_new();
2727 tcg_gen_subi_i32(tmp
, QREG_SP
, 4);
2728 gen_store(s
, OS_LONG
, tmp
, reg
);
2729 if ((insn
& 7) != 7) {
2730 tcg_gen_mov_i32(reg
, tmp
);
2732 tcg_gen_addi_i32(QREG_SP
, tmp
, offset
);
2740 offset
= read_im16(env
, s
);
2741 gen_link(s
, insn
, offset
);
2748 offset
= read_im32(env
, s
);
2749 gen_link(s
, insn
, offset
);
2758 src
= tcg_temp_new();
2759 reg
= AREG(insn
, 0);
2760 tcg_gen_mov_i32(src
, reg
);
2761 tmp
= gen_load(s
, OS_LONG
, src
, 0);
2762 tcg_gen_mov_i32(reg
, tmp
);
2763 tcg_gen_addi_i32(QREG_SP
, src
, 4);
2774 int16_t offset
= read_im16(env
, s
);
2776 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0);
2777 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, offset
+ 4);
2785 tmp
= gen_load(s
, OS_LONG
, QREG_SP
, 0);
2786 tcg_gen_addi_i32(QREG_SP
, QREG_SP
, 4);
2794 /* Load the target address first to ensure correct exception
2796 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
2797 if (IS_NULL_QREG(tmp
)) {
2801 if ((insn
& 0x40) == 0) {
2803 gen_push(s
, tcg_const_i32(s
->pc
));
2817 if ((insn
& 070) == 010) {
2818 /* Operation on address register is always long. */
2821 opsize
= insn_opsize(insn
);
2823 SRC_EA(env
, src
, opsize
, 1, &addr
);
2824 imm
= (insn
>> 9) & 7;
2828 val
= tcg_const_i32(imm
);
2829 dest
= tcg_temp_new();
2830 tcg_gen_mov_i32(dest
, src
);
2831 if ((insn
& 0x38) == 0x08) {
2832 /* Don't update condition codes if the destination is an
2833 address register. */
2834 if (insn
& 0x0100) {
2835 tcg_gen_sub_i32(dest
, dest
, val
);
2837 tcg_gen_add_i32(dest
, dest
, val
);
2840 if (insn
& 0x0100) {
2841 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
2842 tcg_gen_sub_i32(dest
, dest
, val
);
2843 set_cc_op(s
, CC_OP_SUBB
+ opsize
);
2845 tcg_gen_add_i32(dest
, dest
, val
);
2846 tcg_gen_setcond_i32(TCG_COND_LTU
, QREG_CC_X
, dest
, val
);
2847 set_cc_op(s
, CC_OP_ADDB
+ opsize
);
2849 gen_update_cc_add(dest
, val
, opsize
);
2852 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2853 tcg_temp_free(dest
);
2859 case 2: /* One extension word. */
2862 case 3: /* Two extension words. */
2865 case 4: /* No extension words. */
2868 disas_undef(env
, s
, insn
);
2880 op
= (insn
>> 8) & 0xf;
2881 offset
= (int8_t)insn
;
2883 offset
= (int16_t)read_im16(env
, s
);
2884 } else if (offset
== -1) {
2885 offset
= read_im32(env
, s
);
2889 gen_push(s
, tcg_const_i32(s
->pc
));
2893 l1
= gen_new_label();
2894 gen_jmpcc(s
, ((insn
>> 8) & 0xf) ^ 1, l1
);
2895 gen_jmp_tb(s
, 1, base
+ offset
);
2897 gen_jmp_tb(s
, 0, s
->pc
);
2899 /* Unconditional branch. */
2900 gen_jmp_tb(s
, 0, base
+ offset
);
2906 tcg_gen_movi_i32(DREG(insn
, 9), (int8_t)insn
);
2907 gen_logic_cc(s
, DREG(insn
, 9), OS_LONG
);
2920 SRC_EA(env
, src
, opsize
, (insn
& 0x80) == 0, NULL
);
2921 reg
= DREG(insn
, 9);
2922 tcg_gen_mov_i32(reg
, src
);
2923 gen_logic_cc(s
, src
, opsize
);
2934 opsize
= insn_opsize(insn
);
2935 reg
= gen_extend(DREG(insn
, 9), opsize
, 0);
2936 dest
= tcg_temp_new();
2938 SRC_EA(env
, src
, opsize
, 0, &addr
);
2939 tcg_gen_or_i32(dest
, src
, reg
);
2940 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
2942 SRC_EA(env
, src
, opsize
, 0, NULL
);
2943 tcg_gen_or_i32(dest
, src
, reg
);
2944 gen_partset_reg(opsize
, DREG(insn
, 9), dest
);
2946 gen_logic_cc(s
, dest
, opsize
);
2947 tcg_temp_free(dest
);
2955 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
2956 reg
= AREG(insn
, 9);
2957 tcg_gen_sub_i32(reg
, reg
, src
);
2960 static inline void gen_subx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
2964 gen_flush_flags(s
); /* compute old Z */
2966 /* Perform substract with borrow.
2967 * (X, N) = dest - (src + X);
2970 tmp
= tcg_const_i32(0);
2971 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, src
, tmp
, QREG_CC_X
, tmp
);
2972 tcg_gen_sub2_i32(QREG_CC_N
, QREG_CC_X
, dest
, tmp
, QREG_CC_N
, QREG_CC_X
);
2973 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
2974 tcg_gen_andi_i32(QREG_CC_X
, QREG_CC_X
, 1);
2976 /* Compute signed-overflow for substract. */
2978 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, dest
);
2979 tcg_gen_xor_i32(tmp
, dest
, src
);
2980 tcg_gen_and_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
2983 /* Copy the rest of the results into place. */
2984 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
2985 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
2987 set_cc_op(s
, CC_OP_FLAGS
);
2989 /* result is in QREG_CC_N */
2992 DISAS_INSN(subx_reg
)
2998 opsize
= insn_opsize(insn
);
3000 src
= gen_extend(DREG(insn
, 0), opsize
, 1);
3001 dest
= gen_extend(DREG(insn
, 9), opsize
, 1);
3003 gen_subx(s
, src
, dest
, opsize
);
3005 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3008 DISAS_INSN(subx_mem
)
3016 opsize
= insn_opsize(insn
);
3018 addr_src
= AREG(insn
, 0);
3019 tcg_gen_subi_i32(addr_src
, addr_src
, opsize
);
3020 src
= gen_load(s
, opsize
, addr_src
, 1);
3022 addr_dest
= AREG(insn
, 9);
3023 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize
);
3024 dest
= gen_load(s
, opsize
, addr_dest
, 1);
3026 gen_subx(s
, src
, dest
, opsize
);
3028 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
);
3036 val
= (insn
>> 9) & 7;
3039 src
= tcg_const_i32(val
);
3040 gen_logic_cc(s
, src
, OS_LONG
);
3041 DEST_EA(env
, insn
, OS_LONG
, src
, NULL
);
3051 opsize
= insn_opsize(insn
);
3052 SRC_EA(env
, src
, opsize
, 1, NULL
);
3053 reg
= gen_extend(DREG(insn
, 9), opsize
, 1);
3054 gen_update_cc_cmp(s
, reg
, src
, opsize
);
3068 SRC_EA(env
, src
, opsize
, 1, NULL
);
3069 reg
= AREG(insn
, 9);
3070 gen_update_cc_cmp(s
, reg
, src
, OS_LONG
);
3075 int opsize
= insn_opsize(insn
);
3078 /* Post-increment load (mode 3) from Ay. */
3079 src
= gen_ea_mode(env
, s
, 3, REG(insn
, 0), opsize
,
3080 NULL_QREG
, NULL
, EA_LOADS
);
3081 /* Post-increment load (mode 3) from Ax. */
3082 dst
= gen_ea_mode(env
, s
, 3, REG(insn
, 9), opsize
,
3083 NULL_QREG
, NULL
, EA_LOADS
);
3085 gen_update_cc_cmp(s
, dst
, src
, opsize
);
3095 opsize
= insn_opsize(insn
);
3097 SRC_EA(env
, src
, opsize
, 0, &addr
);
3098 dest
= tcg_temp_new();
3099 tcg_gen_xor_i32(dest
, src
, DREG(insn
, 9));
3100 gen_logic_cc(s
, dest
, opsize
);
3101 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3102 tcg_temp_free(dest
);
3105 static void do_exg(TCGv reg1
, TCGv reg2
)
3107 TCGv temp
= tcg_temp_new();
3108 tcg_gen_mov_i32(temp
, reg1
);
3109 tcg_gen_mov_i32(reg1
, reg2
);
3110 tcg_gen_mov_i32(reg2
, temp
);
3111 tcg_temp_free(temp
);
3116 /* exchange Dx and Dy */
3117 do_exg(DREG(insn
, 9), DREG(insn
, 0));
3122 /* exchange Ax and Ay */
3123 do_exg(AREG(insn
, 9), AREG(insn
, 0));
3128 /* exchange Dx and Ay */
3129 do_exg(DREG(insn
, 9), AREG(insn
, 0));
3140 dest
= tcg_temp_new();
3142 opsize
= insn_opsize(insn
);
3143 reg
= DREG(insn
, 9);
3145 SRC_EA(env
, src
, opsize
, 0, &addr
);
3146 tcg_gen_and_i32(dest
, src
, reg
);
3147 DEST_EA(env
, insn
, opsize
, dest
, &addr
);
3149 SRC_EA(env
, src
, opsize
, 0, NULL
);
3150 tcg_gen_and_i32(dest
, src
, reg
);
3151 gen_partset_reg(opsize
, reg
, dest
);
3153 gen_logic_cc(s
, dest
, opsize
);
3154 tcg_temp_free(dest
);
3162 SRC_EA(env
, src
, (insn
& 0x100) ? OS_LONG
: OS_WORD
, 1, NULL
);
3163 reg
= AREG(insn
, 9);
3164 tcg_gen_add_i32(reg
, reg
, src
);
3167 static inline void gen_addx(DisasContext
*s
, TCGv src
, TCGv dest
, int opsize
)
3171 gen_flush_flags(s
); /* compute old Z */
3173 /* Perform addition with carry.
3174 * (X, N) = src + dest + X;
3177 tmp
= tcg_const_i32(0);
3178 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_X
, tmp
, dest
, tmp
);
3179 tcg_gen_add2_i32(QREG_CC_N
, QREG_CC_X
, QREG_CC_N
, QREG_CC_X
, src
, tmp
);
3180 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3182 /* Compute signed-overflow for addition. */
3184 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3185 tcg_gen_xor_i32(tmp
, dest
, src
);
3186 tcg_gen_andc_i32(QREG_CC_V
, QREG_CC_V
, tmp
);
3189 /* Copy the rest of the results into place. */
3190 tcg_gen_or_i32(QREG_CC_Z
, QREG_CC_Z
, QREG_CC_N
); /* !Z is sticky */
3191 tcg_gen_mov_i32(QREG_CC_C
, QREG_CC_X
);
3193 set_cc_op(s
, CC_OP_FLAGS
);
3195 /* result is in QREG_CC_N */
3198 DISAS_INSN(addx_reg
)
3204 opsize
= insn_opsize(insn
);
3206 dest
= gen_extend(DREG(insn
, 9), opsize
, 1);
3207 src
= gen_extend(DREG(insn
, 0), opsize
, 1);
3209 gen_addx(s
, src
, dest
, opsize
);
3211 gen_partset_reg(opsize
, DREG(insn
, 9), QREG_CC_N
);
3214 DISAS_INSN(addx_mem
)
3222 opsize
= insn_opsize(insn
);
3224 addr_src
= AREG(insn
, 0);
3225 tcg_gen_subi_i32(addr_src
, addr_src
, opsize_bytes(opsize
));
3226 src
= gen_load(s
, opsize
, addr_src
, 1);
3228 addr_dest
= AREG(insn
, 9);
3229 tcg_gen_subi_i32(addr_dest
, addr_dest
, opsize_bytes(opsize
));
3230 dest
= gen_load(s
, opsize
, addr_dest
, 1);
3232 gen_addx(s
, src
, dest
, opsize
);
3234 gen_store(s
, opsize
, addr_dest
, QREG_CC_N
);
3237 static inline void shift_im(DisasContext
*s
, uint16_t insn
, int opsize
)
3239 int count
= (insn
>> 9) & 7;
3240 int logical
= insn
& 8;
3241 int left
= insn
& 0x100;
3242 int bits
= opsize_bytes(opsize
) * 8;
3243 TCGv reg
= gen_extend(DREG(insn
, 0), opsize
, !logical
);
3249 tcg_gen_movi_i32(QREG_CC_V
, 0);
3251 tcg_gen_shri_i32(QREG_CC_C
, reg
, bits
- count
);
3252 tcg_gen_shli_i32(QREG_CC_N
, reg
, count
);
3254 /* Note that ColdFire always clears V (done above),
3255 while M68000 sets if the most significant bit is changed at
3256 any time during the shift operation */
3257 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3258 /* if shift count >= bits, V is (reg != 0) */
3259 if (count
>= bits
) {
3260 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, reg
, QREG_CC_V
);
3262 TCGv t0
= tcg_temp_new();
3263 tcg_gen_sari_i32(QREG_CC_V
, reg
, bits
- 1);
3264 tcg_gen_sari_i32(t0
, reg
, bits
- count
- 1);
3265 tcg_gen_setcond_i32(TCG_COND_NE
, QREG_CC_V
, QREG_CC_V
, t0
);
3268 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3271 tcg_gen_shri_i32(QREG_CC_C
, reg
, count
- 1);
3273 tcg_gen_shri_i32(QREG_CC_N
, reg
, count
);
3275 tcg_gen_sari_i32(QREG_CC_N
, reg
, count
);
3279 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3280 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3281 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3282 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3284 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3285 set_cc_op(s
, CC_OP_FLAGS
);
3288 static inline void shift_reg(DisasContext
*s
, uint16_t insn
, int opsize
)
3290 int logical
= insn
& 8;
3291 int left
= insn
& 0x100;
3292 int bits
= opsize_bytes(opsize
) * 8;
3293 TCGv reg
= gen_extend(DREG(insn
, 0), opsize
, !logical
);
3297 t64
= tcg_temp_new_i64();
3298 s64
= tcg_temp_new_i64();
3299 s32
= tcg_temp_new();
3301 /* Note that m68k truncates the shift count modulo 64, not 32.
3302 In addition, a 64-bit shift makes it easy to find "the last
3303 bit shifted out", for the carry flag. */
3304 tcg_gen_andi_i32(s32
, DREG(insn
, 9), 63);
3305 tcg_gen_extu_i32_i64(s64
, s32
);
3306 tcg_gen_extu_i32_i64(t64
, reg
);
3308 /* Optimistically set V=0. Also used as a zero source below. */
3309 tcg_gen_movi_i32(QREG_CC_V
, 0);
3311 tcg_gen_shl_i64(t64
, t64
, s64
);
3313 if (opsize
== OS_LONG
) {
3314 tcg_gen_extr_i64_i32(QREG_CC_N
, QREG_CC_C
, t64
);
3315 /* Note that C=0 if shift count is 0, and we get that for free. */
3317 TCGv zero
= tcg_const_i32(0);
3318 tcg_gen_extrl_i64_i32(QREG_CC_N
, t64
);
3319 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_N
, bits
);
3320 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3321 s32
, zero
, zero
, QREG_CC_C
);
3322 tcg_temp_free(zero
);
3324 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3326 /* X = C, but only if the shift count was non-zero. */
3327 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3328 QREG_CC_C
, QREG_CC_X
);
3330 /* M68000 sets V if the most significant bit is changed at
3331 * any time during the shift operation. Do this via creating
3332 * an extension of the sign bit, comparing, and discarding
3333 * the bits below the sign bit. I.e.
3334 * int64_t s = (intN_t)reg;
3335 * int64_t t = (int64_t)(intN_t)reg << count;
3336 * V = ((s ^ t) & (-1 << (bits - 1))) != 0
3338 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3339 TCGv_i64 tt
= tcg_const_i64(32);
3340 /* if shift is greater than 32, use 32 */
3341 tcg_gen_movcond_i64(TCG_COND_GT
, s64
, s64
, tt
, tt
, s64
);
3342 tcg_temp_free_i64(tt
);
3343 /* Sign extend the input to 64 bits; re-do the shift. */
3344 tcg_gen_ext_i32_i64(t64
, reg
);
3345 tcg_gen_shl_i64(s64
, t64
, s64
);
3346 /* Clear all bits that are unchanged. */
3347 tcg_gen_xor_i64(t64
, t64
, s64
);
3348 /* Ignore the bits below the sign bit. */
3349 tcg_gen_andi_i64(t64
, t64
, -1ULL << (bits
- 1));
3350 /* If any bits remain set, we have overflow. */
3351 tcg_gen_setcondi_i64(TCG_COND_NE
, t64
, t64
, 0);
3352 tcg_gen_extrl_i64_i32(QREG_CC_V
, t64
);
3353 tcg_gen_neg_i32(QREG_CC_V
, QREG_CC_V
);
3356 tcg_gen_shli_i64(t64
, t64
, 32);
3358 tcg_gen_shr_i64(t64
, t64
, s64
);
3360 tcg_gen_sar_i64(t64
, t64
, s64
);
3362 tcg_gen_extr_i64_i32(QREG_CC_C
, QREG_CC_N
, t64
);
3364 /* Note that C=0 if shift count is 0, and we get that for free. */
3365 tcg_gen_shri_i32(QREG_CC_C
, QREG_CC_C
, 31);
3367 /* X = C, but only if the shift count was non-zero. */
3368 tcg_gen_movcond_i32(TCG_COND_NE
, QREG_CC_X
, s32
, QREG_CC_V
,
3369 QREG_CC_C
, QREG_CC_X
);
3371 gen_ext(QREG_CC_N
, QREG_CC_N
, opsize
, 1);
3372 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3375 tcg_temp_free_i64(s64
);
3376 tcg_temp_free_i64(t64
);
3378 /* Write back the result. */
3379 gen_partset_reg(opsize
, DREG(insn
, 0), QREG_CC_N
);
3380 set_cc_op(s
, CC_OP_FLAGS
);
3383 DISAS_INSN(shift8_im
)
3385 shift_im(s
, insn
, OS_BYTE
);
3388 DISAS_INSN(shift16_im
)
3390 shift_im(s
, insn
, OS_WORD
);
3393 DISAS_INSN(shift_im
)
3395 shift_im(s
, insn
, OS_LONG
);
3398 DISAS_INSN(shift8_reg
)
3400 shift_reg(s
, insn
, OS_BYTE
);
3403 DISAS_INSN(shift16_reg
)
3405 shift_reg(s
, insn
, OS_WORD
);
3408 DISAS_INSN(shift_reg
)
3410 shift_reg(s
, insn
, OS_LONG
);
3413 DISAS_INSN(shift_mem
)
3415 int logical
= insn
& 8;
3416 int left
= insn
& 0x100;
3420 SRC_EA(env
, src
, OS_WORD
, !logical
, &addr
);
3421 tcg_gen_movi_i32(QREG_CC_V
, 0);
3423 tcg_gen_shri_i32(QREG_CC_C
, src
, 15);
3424 tcg_gen_shli_i32(QREG_CC_N
, src
, 1);
3426 /* Note that ColdFire always clears V,
3427 while M68000 sets if the most significant bit is changed at
3428 any time during the shift operation */
3429 if (!logical
&& m68k_feature(s
->env
, M68K_FEATURE_M68000
)) {
3430 src
= gen_extend(src
, OS_WORD
, 1);
3431 tcg_gen_xor_i32(QREG_CC_V
, QREG_CC_N
, src
);
3434 tcg_gen_mov_i32(QREG_CC_C
, src
);
3436 tcg_gen_shri_i32(QREG_CC_N
, src
, 1);
3438 tcg_gen_sari_i32(QREG_CC_N
, src
, 1);
3442 gen_ext(QREG_CC_N
, QREG_CC_N
, OS_WORD
, 1);
3443 tcg_gen_andi_i32(QREG_CC_C
, QREG_CC_C
, 1);
3444 tcg_gen_mov_i32(QREG_CC_Z
, QREG_CC_N
);
3445 tcg_gen_mov_i32(QREG_CC_X
, QREG_CC_C
);
3447 DEST_EA(env
, insn
, OS_WORD
, QREG_CC_N
, &addr
);
3448 set_cc_op(s
, CC_OP_FLAGS
);
3451 static void rotate(TCGv reg
, TCGv shift
, int left
, int size
)
3455 /* Replicate the 8-bit input so that a 32-bit rotate works. */
3456 tcg_gen_ext8u_i32(reg
, reg
);
3457 tcg_gen_muli_i32(reg
, reg
, 0x01010101);
3460 /* Replicate the 16-bit input so that a 32-bit rotate works. */
3461 tcg_gen_deposit_i32(reg
, reg
, reg
, 16, 16);
3466 tcg_gen_rotl_i32(reg
, reg
, shift
);
3468 tcg_gen_rotr_i32(reg
, reg
, shift
);
3476 tcg_gen_ext8s_i32(reg
, reg
);
3479 tcg_gen_ext16s_i32(reg
, reg
);
3485 /* QREG_CC_X is not affected */
3487 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3488 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3491 tcg_gen_andi_i32(QREG_CC_C
, reg
, 1);
3493 tcg_gen_shri_i32(QREG_CC_C
, reg
, 31);
3496 tcg_gen_movi_i32(QREG_CC_V
, 0); /* always cleared */
3499 static void rotate_x_flags(TCGv reg
, TCGv X
, int size
)
3503 tcg_gen_ext8s_i32(reg
, reg
);
3506 tcg_gen_ext16s_i32(reg
, reg
);
3511 tcg_gen_mov_i32(QREG_CC_N
, reg
);
3512 tcg_gen_mov_i32(QREG_CC_Z
, reg
);
3513 tcg_gen_mov_i32(QREG_CC_X
, X
);
3514 tcg_gen_mov_i32(QREG_CC_C
, X
);
3515 tcg_gen_movi_i32(QREG_CC_V
, 0);
3518 /* Result of rotate_x() is valid if 0 <= shift <= size */
3519 static TCGv
rotate_x(TCGv reg
, TCGv shift
, int left
, int size
)
3521 TCGv X
, shl
, shr
, shx
, sz
, zero
;
3523 sz
= tcg_const_i32(size
);
3525 shr
= tcg_temp_new();
3526 shl
= tcg_temp_new();
3527 shx
= tcg_temp_new();
3529 tcg_gen_mov_i32(shl
, shift
); /* shl = shift */
3530 tcg_gen_movi_i32(shr
, size
+ 1);
3531 tcg_gen_sub_i32(shr
, shr
, shift
); /* shr = size + 1 - shift */
3532 tcg_gen_subi_i32(shx
, shift
, 1); /* shx = shift - 1 */
3533 /* shx = shx < 0 ? size : shx; */
3534 zero
= tcg_const_i32(0);
3535 tcg_gen_movcond_i32(TCG_COND_LT
, shx
, shx
, zero
, sz
, shx
);
3536 tcg_temp_free(zero
);
3538 tcg_gen_mov_i32(shr
, shift
); /* shr = shift */
3539 tcg_gen_movi_i32(shl
, size
+ 1);
3540 tcg_gen_sub_i32(shl
, shl
, shift
); /* shl = size + 1 - shift */
3541 tcg_gen_sub_i32(shx
, sz
, shift
); /* shx = size - shift */
3544 /* reg = (reg << shl) | (reg >> shr) | (x << shx); */
3546 tcg_gen_shl_i32(shl
, reg
, shl
);
3547 tcg_gen_shr_i32(shr
, reg
, shr
);
3548 tcg_gen_or_i32(reg
, shl
, shr
);
3551 tcg_gen_shl_i32(shx
, QREG_CC_X
, shx
);
3552 tcg_gen_or_i32(reg
, reg
, shx
);
3555 /* X = (reg >> size) & 1 */
3558 tcg_gen_shr_i32(X
, reg
, sz
);
3559 tcg_gen_andi_i32(X
, X
, 1);
3565 /* Result of rotate32_x() is valid if 0 <= shift < 33 */
3566 static TCGv
rotate32_x(TCGv reg
, TCGv shift
, int left
)
3568 TCGv_i64 t0
, shift64
;
3569 TCGv X
, lo
, hi
, zero
;
3571 shift64
= tcg_temp_new_i64();
3572 tcg_gen_extu_i32_i64(shift64
, shift
);
3574 t0
= tcg_temp_new_i64();
3577 lo
= tcg_temp_new();
3578 hi
= tcg_temp_new();
3581 /* create [reg:X:..] */
3583 tcg_gen_shli_i32(lo
, QREG_CC_X
, 31);
3584 tcg_gen_concat_i32_i64(t0
, lo
, reg
);
3588 tcg_gen_rotl_i64(t0
, t0
, shift64
);
3589 tcg_temp_free_i64(shift64
);
3591 /* result is [reg:..:reg:X] */
3593 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3594 tcg_gen_andi_i32(X
, lo
, 1);
3596 tcg_gen_shri_i32(lo
, lo
, 1);
3598 /* create [..:X:reg] */
3600 tcg_gen_concat_i32_i64(t0
, reg
, QREG_CC_X
);
3602 tcg_gen_rotr_i64(t0
, t0
, shift64
);
3603 tcg_temp_free_i64(shift64
);
3605 /* result is value: [X:reg:..:reg] */
3607 tcg_gen_extr_i64_i32(lo
, hi
, t0
);
3611 tcg_gen_shri_i32(X
, hi
, 31);
3613 /* extract result */
3615 tcg_gen_shli_i32(hi
, hi
, 1);
3617 tcg_temp_free_i64(t0
);
3618 tcg_gen_or_i32(lo
, lo
, hi
);
3621 /* if shift == 0, register and X are not affected */
3623 zero
= tcg_const_i32(0);
3624 tcg_gen_movcond_i32(TCG_COND_EQ
, X
, shift
, zero
, QREG_CC_X
, X
);
3625 tcg_gen_movcond_i32(TCG_COND_EQ
, reg
, shift
, zero
, reg
, lo
);
3626 tcg_temp_free(zero
);
3632 DISAS_INSN(rotate_im
)
3636 int left
= (insn
& 0x100);
3638 tmp
= (insn
>> 9) & 7;
3643 shift
= tcg_const_i32(tmp
);
3645 rotate(DREG(insn
, 0), shift
, left
, 32);
3647 TCGv X
= rotate32_x(DREG(insn
, 0), shift
, left
);
3648 rotate_x_flags(DREG(insn
, 0), X
, 32);
3651 tcg_temp_free(shift
);
3653 set_cc_op(s
, CC_OP_FLAGS
);
3656 DISAS_INSN(rotate8_im
)
3658 int left
= (insn
& 0x100);
3663 reg
= gen_extend(DREG(insn
, 0), OS_BYTE
, 0);
3665 tmp
= (insn
>> 9) & 7;
3670 shift
= tcg_const_i32(tmp
);
3672 rotate(reg
, shift
, left
, 8);
3674 TCGv X
= rotate_x(reg
, shift
, left
, 8);
3675 rotate_x_flags(reg
, X
, 8);
3678 tcg_temp_free(shift
);
3679 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3680 set_cc_op(s
, CC_OP_FLAGS
);
3683 DISAS_INSN(rotate16_im
)
3685 int left
= (insn
& 0x100);
3690 reg
= gen_extend(DREG(insn
, 0), OS_WORD
, 0);
3691 tmp
= (insn
>> 9) & 7;
3696 shift
= tcg_const_i32(tmp
);
3698 rotate(reg
, shift
, left
, 16);
3700 TCGv X
= rotate_x(reg
, shift
, left
, 16);
3701 rotate_x_flags(reg
, X
, 16);
3704 tcg_temp_free(shift
);
3705 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3706 set_cc_op(s
, CC_OP_FLAGS
);
3709 DISAS_INSN(rotate_reg
)
3714 int left
= (insn
& 0x100);
3716 reg
= DREG(insn
, 0);
3717 src
= DREG(insn
, 9);
3718 /* shift in [0..63] */
3719 t0
= tcg_temp_new();
3720 tcg_gen_andi_i32(t0
, src
, 63);
3721 t1
= tcg_temp_new_i32();
3723 tcg_gen_andi_i32(t1
, src
, 31);
3724 rotate(reg
, t1
, left
, 32);
3725 /* if shift == 0, clear C */
3726 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3727 t0
, QREG_CC_V
/* 0 */,
3728 QREG_CC_V
/* 0 */, QREG_CC_C
);
3732 tcg_gen_movi_i32(t1
, 33);
3733 tcg_gen_remu_i32(t1
, t0
, t1
);
3734 X
= rotate32_x(DREG(insn
, 0), t1
, left
);
3735 rotate_x_flags(DREG(insn
, 0), X
, 32);
3740 set_cc_op(s
, CC_OP_FLAGS
);
3743 DISAS_INSN(rotate8_reg
)
3748 int left
= (insn
& 0x100);
3750 reg
= gen_extend(DREG(insn
, 0), OS_BYTE
, 0);
3751 src
= DREG(insn
, 9);
3752 /* shift in [0..63] */
3753 t0
= tcg_temp_new_i32();
3754 tcg_gen_andi_i32(t0
, src
, 63);
3755 t1
= tcg_temp_new_i32();
3757 tcg_gen_andi_i32(t1
, src
, 7);
3758 rotate(reg
, t1
, left
, 8);
3759 /* if shift == 0, clear C */
3760 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3761 t0
, QREG_CC_V
/* 0 */,
3762 QREG_CC_V
/* 0 */, QREG_CC_C
);
3766 tcg_gen_movi_i32(t1
, 9);
3767 tcg_gen_remu_i32(t1
, t0
, t1
);
3768 X
= rotate_x(reg
, t1
, left
, 8);
3769 rotate_x_flags(reg
, X
, 8);
3774 gen_partset_reg(OS_BYTE
, DREG(insn
, 0), reg
);
3775 set_cc_op(s
, CC_OP_FLAGS
);
3778 DISAS_INSN(rotate16_reg
)
3783 int left
= (insn
& 0x100);
3785 reg
= gen_extend(DREG(insn
, 0), OS_WORD
, 0);
3786 src
= DREG(insn
, 9);
3787 /* shift in [0..63] */
3788 t0
= tcg_temp_new_i32();
3789 tcg_gen_andi_i32(t0
, src
, 63);
3790 t1
= tcg_temp_new_i32();
3792 tcg_gen_andi_i32(t1
, src
, 15);
3793 rotate(reg
, t1
, left
, 16);
3794 /* if shift == 0, clear C */
3795 tcg_gen_movcond_i32(TCG_COND_EQ
, QREG_CC_C
,
3796 t0
, QREG_CC_V
/* 0 */,
3797 QREG_CC_V
/* 0 */, QREG_CC_C
);
3801 tcg_gen_movi_i32(t1
, 17);
3802 tcg_gen_remu_i32(t1
, t0
, t1
);
3803 X
= rotate_x(reg
, t1
, left
, 16);
3804 rotate_x_flags(reg
, X
, 16);
3809 gen_partset_reg(OS_WORD
, DREG(insn
, 0), reg
);
3810 set_cc_op(s
, CC_OP_FLAGS
);
3813 DISAS_INSN(rotate_mem
)
3818 int left
= (insn
& 0x100);
3820 SRC_EA(env
, src
, OS_WORD
, 0, &addr
);
3822 shift
= tcg_const_i32(1);
3823 if (insn
& 0x0200) {
3824 rotate(src
, shift
, left
, 16);
3826 TCGv X
= rotate_x(src
, shift
, left
, 16);
3827 rotate_x_flags(src
, X
, 16);
3830 tcg_temp_free(shift
);
3831 DEST_EA(env
, insn
, OS_WORD
, src
, &addr
);
3832 set_cc_op(s
, CC_OP_FLAGS
);
3835 DISAS_INSN(bfext_reg
)
3837 int ext
= read_im16(env
, s
);
3838 int is_sign
= insn
& 0x200;
3839 TCGv src
= DREG(insn
, 0);
3840 TCGv dst
= DREG(ext
, 12);
3841 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
3842 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
3843 int pos
= 32 - ofs
- len
; /* little bit-endian */
3844 TCGv tmp
= tcg_temp_new();
3847 /* In general, we're going to rotate the field so that it's at the
3848 top of the word and then right-shift by the compliment of the
3849 width to extend the field. */
3851 /* Variable width. */
3853 /* Variable offset. */
3854 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
3855 tcg_gen_rotl_i32(tmp
, src
, tmp
);
3857 tcg_gen_rotli_i32(tmp
, src
, ofs
);
3860 shift
= tcg_temp_new();
3861 tcg_gen_neg_i32(shift
, DREG(ext
, 0));
3862 tcg_gen_andi_i32(shift
, shift
, 31);
3863 tcg_gen_sar_i32(QREG_CC_N
, tmp
, shift
);
3865 tcg_gen_mov_i32(dst
, QREG_CC_N
);
3867 tcg_gen_shr_i32(dst
, tmp
, shift
);
3869 tcg_temp_free(shift
);
3871 /* Immediate width. */
3873 /* Variable offset */
3874 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
3875 tcg_gen_rotl_i32(tmp
, src
, tmp
);
3879 /* Immediate offset. If the field doesn't wrap around the
3880 end of the word, rely on (s)extract completely. */
3882 tcg_gen_rotli_i32(tmp
, src
, ofs
);
3888 tcg_gen_sextract_i32(QREG_CC_N
, src
, pos
, len
);
3890 tcg_gen_mov_i32(dst
, QREG_CC_N
);
3892 tcg_gen_extract_i32(dst
, src
, pos
, len
);
3897 set_cc_op(s
, CC_OP_LOGIC
);
3900 DISAS_INSN(bfext_mem
)
3902 int ext
= read_im16(env
, s
);
3903 int is_sign
= insn
& 0x200;
3904 TCGv dest
= DREG(ext
, 12);
3905 TCGv addr
, len
, ofs
;
3907 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
3908 if (IS_NULL_QREG(addr
)) {
3916 len
= tcg_const_i32(extract32(ext
, 0, 5));
3921 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
3925 gen_helper_bfexts_mem(dest
, cpu_env
, addr
, ofs
, len
);
3926 tcg_gen_mov_i32(QREG_CC_N
, dest
);
3928 TCGv_i64 tmp
= tcg_temp_new_i64();
3929 gen_helper_bfextu_mem(tmp
, cpu_env
, addr
, ofs
, len
);
3930 tcg_gen_extr_i64_i32(dest
, QREG_CC_N
, tmp
);
3931 tcg_temp_free_i64(tmp
);
3933 set_cc_op(s
, CC_OP_LOGIC
);
3935 if (!(ext
& 0x20)) {
3938 if (!(ext
& 0x800)) {
3943 DISAS_INSN(bfop_reg
)
3945 int ext
= read_im16(env
, s
);
3946 TCGv src
= DREG(insn
, 0);
3947 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
3948 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
3949 TCGv mask
, tofs
, tlen
;
3953 if ((insn
& 0x0f00) == 0x0d00) { /* bfffo */
3954 tofs
= tcg_temp_new();
3955 tlen
= tcg_temp_new();
3958 if ((ext
& 0x820) == 0) {
3959 /* Immediate width and offset. */
3960 uint32_t maski
= 0x7fffffffu
>> (len
- 1);
3961 if (ofs
+ len
<= 32) {
3962 tcg_gen_shli_i32(QREG_CC_N
, src
, ofs
);
3964 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
3966 tcg_gen_andi_i32(QREG_CC_N
, QREG_CC_N
, ~maski
);
3967 mask
= tcg_const_i32(ror32(maski
, ofs
));
3968 if (!TCGV_IS_UNUSED(tofs
)) {
3969 tcg_gen_movi_i32(tofs
, ofs
);
3970 tcg_gen_movi_i32(tlen
, len
);
3973 TCGv tmp
= tcg_temp_new();
3975 /* Variable width */
3976 tcg_gen_subi_i32(tmp
, DREG(ext
, 0), 1);
3977 tcg_gen_andi_i32(tmp
, tmp
, 31);
3978 mask
= tcg_const_i32(0x7fffffffu
);
3979 tcg_gen_shr_i32(mask
, mask
, tmp
);
3980 if (!TCGV_IS_UNUSED(tlen
)) {
3981 tcg_gen_addi_i32(tlen
, tmp
, 1);
3984 /* Immediate width */
3985 mask
= tcg_const_i32(0x7fffffffu
>> (len
- 1));
3986 if (!TCGV_IS_UNUSED(tlen
)) {
3987 tcg_gen_movi_i32(tlen
, len
);
3991 /* Variable offset */
3992 tcg_gen_andi_i32(tmp
, DREG(ext
, 6), 31);
3993 tcg_gen_rotl_i32(QREG_CC_N
, src
, tmp
);
3994 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
3995 tcg_gen_rotr_i32(mask
, mask
, tmp
);
3996 if (!TCGV_IS_UNUSED(tofs
)) {
3997 tcg_gen_mov_i32(tofs
, tmp
);
4000 /* Immediate offset (and variable width) */
4001 tcg_gen_rotli_i32(QREG_CC_N
, src
, ofs
);
4002 tcg_gen_andc_i32(QREG_CC_N
, QREG_CC_N
, mask
);
4003 tcg_gen_rotri_i32(mask
, mask
, ofs
);
4004 if (!TCGV_IS_UNUSED(tofs
)) {
4005 tcg_gen_movi_i32(tofs
, ofs
);
4010 set_cc_op(s
, CC_OP_LOGIC
);
4012 switch (insn
& 0x0f00) {
4013 case 0x0a00: /* bfchg */
4014 tcg_gen_eqv_i32(src
, src
, mask
);
4016 case 0x0c00: /* bfclr */
4017 tcg_gen_and_i32(src
, src
, mask
);
4019 case 0x0d00: /* bfffo */
4020 gen_helper_bfffo_reg(DREG(ext
, 12), QREG_CC_N
, tofs
, tlen
);
4021 tcg_temp_free(tlen
);
4022 tcg_temp_free(tofs
);
4024 case 0x0e00: /* bfset */
4025 tcg_gen_orc_i32(src
, src
, mask
);
4027 case 0x0800: /* bftst */
4028 /* flags already set; no other work to do. */
4031 g_assert_not_reached();
4033 tcg_temp_free(mask
);
4036 DISAS_INSN(bfop_mem
)
4038 int ext
= read_im16(env
, s
);
4039 TCGv addr
, len
, ofs
;
4042 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4043 if (IS_NULL_QREG(addr
)) {
4051 len
= tcg_const_i32(extract32(ext
, 0, 5));
4056 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4059 switch (insn
& 0x0f00) {
4060 case 0x0a00: /* bfchg */
4061 gen_helper_bfchg_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4063 case 0x0c00: /* bfclr */
4064 gen_helper_bfclr_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4066 case 0x0d00: /* bfffo */
4067 t64
= tcg_temp_new_i64();
4068 gen_helper_bfffo_mem(t64
, cpu_env
, addr
, ofs
, len
);
4069 tcg_gen_extr_i64_i32(DREG(ext
, 12), QREG_CC_N
, t64
);
4070 tcg_temp_free_i64(t64
);
4072 case 0x0e00: /* bfset */
4073 gen_helper_bfset_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4075 case 0x0800: /* bftst */
4076 gen_helper_bfexts_mem(QREG_CC_N
, cpu_env
, addr
, ofs
, len
);
4079 g_assert_not_reached();
4081 set_cc_op(s
, CC_OP_LOGIC
);
4083 if (!(ext
& 0x20)) {
4086 if (!(ext
& 0x800)) {
4091 DISAS_INSN(bfins_reg
)
4093 int ext
= read_im16(env
, s
);
4094 TCGv dst
= DREG(insn
, 0);
4095 TCGv src
= DREG(ext
, 12);
4096 int len
= ((extract32(ext
, 0, 5) - 1) & 31) + 1;
4097 int ofs
= extract32(ext
, 6, 5); /* big bit-endian */
4098 int pos
= 32 - ofs
- len
; /* little bit-endian */
4101 tmp
= tcg_temp_new();
4104 /* Variable width */
4105 tcg_gen_neg_i32(tmp
, DREG(ext
, 0));
4106 tcg_gen_andi_i32(tmp
, tmp
, 31);
4107 tcg_gen_shl_i32(QREG_CC_N
, src
, tmp
);
4109 /* Immediate width */
4110 tcg_gen_shli_i32(QREG_CC_N
, src
, 32 - len
);
4112 set_cc_op(s
, CC_OP_LOGIC
);
4114 /* Immediate width and offset */
4115 if ((ext
& 0x820) == 0) {
4116 /* Check for suitability for deposit. */
4118 tcg_gen_deposit_i32(dst
, dst
, src
, pos
, len
);
4120 uint32_t maski
= -2U << (len
- 1);
4121 uint32_t roti
= (ofs
+ len
) & 31;
4122 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4123 tcg_gen_rotri_i32(tmp
, tmp
, roti
);
4124 tcg_gen_andi_i32(dst
, dst
, ror32(maski
, roti
));
4125 tcg_gen_or_i32(dst
, dst
, tmp
);
4128 TCGv mask
= tcg_temp_new();
4129 TCGv rot
= tcg_temp_new();
4132 /* Variable width */
4133 tcg_gen_subi_i32(rot
, DREG(ext
, 0), 1);
4134 tcg_gen_andi_i32(rot
, rot
, 31);
4135 tcg_gen_movi_i32(mask
, -2);
4136 tcg_gen_shl_i32(mask
, mask
, rot
);
4137 tcg_gen_mov_i32(rot
, DREG(ext
, 0));
4138 tcg_gen_andc_i32(tmp
, src
, mask
);
4140 /* Immediate width (variable offset) */
4141 uint32_t maski
= -2U << (len
- 1);
4142 tcg_gen_andi_i32(tmp
, src
, ~maski
);
4143 tcg_gen_movi_i32(mask
, maski
);
4144 tcg_gen_movi_i32(rot
, len
& 31);
4147 /* Variable offset */
4148 tcg_gen_add_i32(rot
, rot
, DREG(ext
, 6));
4150 /* Immediate offset (variable width) */
4151 tcg_gen_addi_i32(rot
, rot
, ofs
);
4153 tcg_gen_andi_i32(rot
, rot
, 31);
4154 tcg_gen_rotr_i32(mask
, mask
, rot
);
4155 tcg_gen_rotr_i32(tmp
, tmp
, rot
);
4156 tcg_gen_and_i32(dst
, dst
, mask
);
4157 tcg_gen_or_i32(dst
, dst
, tmp
);
4160 tcg_temp_free(mask
);
4165 DISAS_INSN(bfins_mem
)
4167 int ext
= read_im16(env
, s
);
4168 TCGv src
= DREG(ext
, 12);
4169 TCGv addr
, len
, ofs
;
4171 addr
= gen_lea(env
, s
, insn
, OS_UNSIZED
);
4172 if (IS_NULL_QREG(addr
)) {
4180 len
= tcg_const_i32(extract32(ext
, 0, 5));
4185 ofs
= tcg_const_i32(extract32(ext
, 6, 5));
4188 gen_helper_bfins_mem(QREG_CC_N
, cpu_env
, addr
, src
, ofs
, len
);
4189 set_cc_op(s
, CC_OP_LOGIC
);
4191 if (!(ext
& 0x20)) {
4194 if (!(ext
& 0x800)) {
4202 reg
= DREG(insn
, 0);
4203 gen_logic_cc(s
, reg
, OS_LONG
);
4204 gen_helper_ff1(reg
, reg
);
4207 static TCGv
gen_get_sr(DisasContext
*s
)
4212 ccr
= gen_get_ccr(s
);
4213 sr
= tcg_temp_new();
4214 tcg_gen_andi_i32(sr
, QREG_SR
, 0xffe0);
4215 tcg_gen_or_i32(sr
, sr
, ccr
);
4225 ext
= read_im16(env
, s
);
4226 if (ext
!= 0x46FC) {
4227 gen_exception(s
, addr
, EXCP_UNSUPPORTED
);
4230 ext
= read_im16(env
, s
);
4231 if (IS_USER(s
) || (ext
& SR_S
) == 0) {
4232 gen_exception(s
, addr
, EXCP_PRIVILEGE
);
4235 gen_push(s
, gen_get_sr(s
));
4236 gen_set_sr_im(s
, ext
, 0);
4239 DISAS_INSN(move_from_sr
)
4243 if (IS_USER(s
) && !m68k_feature(env
, M68K_FEATURE_M68000
)) {
4244 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4248 DEST_EA(env
, insn
, OS_WORD
, sr
, NULL
);
4251 DISAS_INSN(move_to_sr
)
4254 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4257 gen_set_sr(env
, s
, insn
, 0);
4261 DISAS_INSN(move_from_usp
)
4264 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4267 tcg_gen_ld_i32(AREG(insn
, 0), cpu_env
,
4268 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4271 DISAS_INSN(move_to_usp
)
4274 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4277 tcg_gen_st_i32(AREG(insn
, 0), cpu_env
,
4278 offsetof(CPUM68KState
, sp
[M68K_USP
]));
4283 gen_exception(s
, s
->pc
, EXCP_HALT_INSN
);
4291 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4295 ext
= read_im16(env
, s
);
4297 gen_set_sr_im(s
, ext
, 0);
4298 tcg_gen_movi_i32(cpu_halted
, 1);
4299 gen_exception(s
, s
->pc
, EXCP_HLT
);
4305 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4308 gen_exception(s
, s
->pc
- 2, EXCP_RTE
);
4317 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4321 ext
= read_im16(env
, s
);
4324 reg
= AREG(ext
, 12);
4326 reg
= DREG(ext
, 12);
4328 gen_helper_movec(cpu_env
, tcg_const_i32(ext
& 0xfff), reg
);
4335 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4338 /* ICache fetch. Implement as no-op. */
4344 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4347 /* Cache push/invalidate. Implement as no-op. */
4352 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4357 M68kCPU
*cpu
= m68k_env_get_cpu(env
);
4360 gen_exception(s
, s
->pc
- 2, EXCP_PRIVILEGE
);
4363 /* TODO: Implement wdebug. */
4364 cpu_abort(CPU(cpu
), "WDEBUG not implemented");
4369 gen_exception(s
, s
->pc
- 2, EXCP_TRAP0
+ (insn
& 0xf));
4372 static void gen_load_fcr(DisasContext
*s
, TCGv res
, int reg
)
4376 tcg_gen_movi_i32(res
, 0);
4379 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4382 tcg_gen_ld_i32(res
, cpu_env
, offsetof(CPUM68KState
, fpcr
));
4387 static void gen_store_fcr(DisasContext
*s
, TCGv val
, int reg
)
4393 tcg_gen_st_i32(val
, cpu_env
, offsetof(CPUM68KState
, fpsr
));
4396 gen_helper_set_fpcr(cpu_env
, val
);
4401 static void gen_qemu_store_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4403 int index
= IS_USER(s
);
4406 tmp
= tcg_temp_new();
4407 gen_load_fcr(s
, tmp
, reg
);
4408 tcg_gen_qemu_st32(tmp
, addr
, index
);
4412 static void gen_qemu_load_fcr(DisasContext
*s
, TCGv addr
, int reg
)
4414 int index
= IS_USER(s
);
4417 tmp
= tcg_temp_new();
4418 tcg_gen_qemu_ld32u(tmp
, addr
, index
);
4419 gen_store_fcr(s
, tmp
, reg
);
4424 static void gen_op_fmove_fcr(CPUM68KState
*env
, DisasContext
*s
,
4425 uint32_t insn
, uint32_t ext
)
4427 int mask
= (ext
>> 10) & 7;
4428 int is_write
= (ext
>> 13) & 1;
4429 int mode
= extract32(insn
, 3, 3);
4435 if (mask
!= M68K_FPIAR
&& mask
!= M68K_FPSR
&& mask
!= M68K_FPCR
) {
4436 gen_exception(s
, s
->insn_pc
, EXCP_ILLEGAL
);
4440 gen_load_fcr(s
, DREG(insn
, 0), mask
);
4442 gen_store_fcr(s
, DREG(insn
, 0), mask
);
4445 case 1: /* An, only with FPIAR */
4446 if (mask
!= M68K_FPIAR
) {
4447 gen_exception(s
, s
->insn_pc
, EXCP_ILLEGAL
);
4451 gen_load_fcr(s
, AREG(insn
, 0), mask
);
4453 gen_store_fcr(s
, AREG(insn
, 0), mask
);
4460 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
4461 if (IS_NULL_QREG(tmp
)) {
4466 addr
= tcg_temp_new();
4467 tcg_gen_mov_i32(addr
, tmp
);
4471 * 0b100 Floating-Point Control Register
4472 * 0b010 Floating-Point Status Register
4473 * 0b001 Floating-Point Instruction Address Register
4477 if (is_write
&& mode
== 4) {
4478 for (i
= 2; i
>= 0; i
--, mask
>>= 1) {
4480 gen_qemu_store_fcr(s
, addr
, 1 << i
);
4482 tcg_gen_subi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
4486 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4488 for (i
= 0; i
< 3; i
++, mask
>>= 1) {
4491 gen_qemu_store_fcr(s
, addr
, 1 << i
);
4493 gen_qemu_load_fcr(s
, addr
, 1 << i
);
4495 if (mask
!= 1 || mode
== 3) {
4496 tcg_gen_addi_i32(addr
, addr
, opsize_bytes(OS_LONG
));
4501 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
4504 tcg_temp_free_i32(addr
);
4507 static void gen_op_fmovem(CPUM68KState
*env
, DisasContext
*s
,
4508 uint32_t insn
, uint32_t ext
)
4512 int mode
= (ext
>> 11) & 0x3;
4513 int is_load
= ((ext
& 0x2000) == 0);
4515 if (m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
4516 opsize
= OS_EXTENDED
;
4518 opsize
= OS_DOUBLE
; /* FIXME */
4521 addr
= gen_lea(env
, s
, insn
, opsize
);
4522 if (IS_NULL_QREG(addr
)) {
4527 tmp
= tcg_temp_new();
4529 /* Dynamic register list */
4530 tcg_gen_ext8u_i32(tmp
, DREG(ext
, 4));
4532 /* Static register list */
4533 tcg_gen_movi_i32(tmp
, ext
& 0xff);
4536 if (!is_load
&& (mode
& 2) == 0) {
4537 /* predecrement addressing mode
4538 * only available to store register to memory
4540 if (opsize
== OS_EXTENDED
) {
4541 gen_helper_fmovemx_st_predec(tmp
, cpu_env
, addr
, tmp
);
4543 gen_helper_fmovemd_st_predec(tmp
, cpu_env
, addr
, tmp
);
4546 /* postincrement addressing mode */
4547 if (opsize
== OS_EXTENDED
) {
4549 gen_helper_fmovemx_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
4551 gen_helper_fmovemx_st_postinc(tmp
, cpu_env
, addr
, tmp
);
4555 gen_helper_fmovemd_ld_postinc(tmp
, cpu_env
, addr
, tmp
);
4557 gen_helper_fmovemd_st_postinc(tmp
, cpu_env
, addr
, tmp
);
4561 if ((insn
& 070) == 030 || (insn
& 070) == 040) {
4562 tcg_gen_mov_i32(AREG(insn
, 0), tmp
);
4567 /* ??? FP exceptions are not implemented. Most exceptions are deferred until
4568 immediately before the next FP instruction is executed. */
4574 TCGv_ptr cpu_src
, cpu_dest
;
4576 ext
= read_im16(env
, s
);
4577 opmode
= ext
& 0x7f;
4578 switch ((ext
>> 13) & 7) {
4584 if (insn
== 0xf200 && (ext
& 0xfc00) == 0x5c00) {
4586 TCGv rom_offset
= tcg_const_i32(opmode
);
4587 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
4588 gen_helper_fconst(cpu_env
, cpu_dest
, rom_offset
);
4589 tcg_temp_free_ptr(cpu_dest
);
4590 tcg_temp_free(rom_offset
);
4594 case 3: /* fmove out */
4595 cpu_src
= gen_fp_ptr(REG(ext
, 7));
4596 opsize
= ext_opsize(ext
, 10);
4597 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
, EA_STORE
) == -1) {
4600 gen_helper_ftst(cpu_env
, cpu_src
);
4601 tcg_temp_free_ptr(cpu_src
);
4603 case 4: /* fmove to control register. */
4604 case 5: /* fmove from control register. */
4605 gen_op_fmove_fcr(env
, s
, insn
, ext
);
4607 case 6: /* fmovem */
4609 if ((ext
& 0x1000) == 0 && !m68k_feature(s
->env
, M68K_FEATURE_FPU
)) {
4612 gen_op_fmovem(env
, s
, insn
, ext
);
4615 if (ext
& (1 << 14)) {
4616 /* Source effective address. */
4617 opsize
= ext_opsize(ext
, 10);
4618 cpu_src
= gen_fp_result_ptr();
4619 if (gen_ea_fp(env
, s
, insn
, opsize
, cpu_src
, EA_LOADS
) == -1) {
4624 /* Source register. */
4625 opsize
= OS_EXTENDED
;
4626 cpu_src
= gen_fp_ptr(REG(ext
, 10));
4628 cpu_dest
= gen_fp_ptr(REG(ext
, 7));
4631 gen_fp_move(cpu_dest
, cpu_src
);
4633 case 0x40: /* fsmove */
4634 gen_helper_fsround(cpu_env
, cpu_dest
, cpu_src
);
4636 case 0x44: /* fdmove */
4637 gen_helper_fdround(cpu_env
, cpu_dest
, cpu_src
);
4640 gen_helper_firound(cpu_env
, cpu_dest
, cpu_src
);
4642 case 3: /* fintrz */
4643 gen_helper_fitrunc(cpu_env
, cpu_dest
, cpu_src
);
4646 gen_helper_fsqrt(cpu_env
, cpu_dest
, cpu_src
);
4648 case 0x41: /* fssqrt */
4649 gen_helper_fssqrt(cpu_env
, cpu_dest
, cpu_src
);
4651 case 0x45: /* fdsqrt */
4652 gen_helper_fdsqrt(cpu_env
, cpu_dest
, cpu_src
);
4654 case 0x18: /* fabs */
4655 gen_helper_fabs(cpu_env
, cpu_dest
, cpu_src
);
4657 case 0x58: /* fsabs */
4658 gen_helper_fsabs(cpu_env
, cpu_dest
, cpu_src
);
4660 case 0x5c: /* fdabs */
4661 gen_helper_fdabs(cpu_env
, cpu_dest
, cpu_src
);
4663 case 0x1a: /* fneg */
4664 gen_helper_fneg(cpu_env
, cpu_dest
, cpu_src
);
4666 case 0x5a: /* fsneg */
4667 gen_helper_fsneg(cpu_env
, cpu_dest
, cpu_src
);
4669 case 0x5e: /* fdneg */
4670 gen_helper_fdneg(cpu_env
, cpu_dest
, cpu_src
);
4672 case 0x20: /* fdiv */
4673 gen_helper_fdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4675 case 0x60: /* fsdiv */
4676 gen_helper_fsdiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4678 case 0x64: /* fddiv */
4679 gen_helper_fddiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4681 case 0x22: /* fadd */
4682 gen_helper_fadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4684 case 0x62: /* fsadd */
4685 gen_helper_fsadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4687 case 0x66: /* fdadd */
4688 gen_helper_fdadd(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4690 case 0x23: /* fmul */
4691 gen_helper_fmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4693 case 0x63: /* fsmul */
4694 gen_helper_fsmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4696 case 0x67: /* fdmul */
4697 gen_helper_fdmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4699 case 0x24: /* fsgldiv */
4700 gen_helper_fsgldiv(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4702 case 0x27: /* fsglmul */
4703 gen_helper_fsglmul(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4705 case 0x28: /* fsub */
4706 gen_helper_fsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4708 case 0x68: /* fssub */
4709 gen_helper_fssub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4711 case 0x6c: /* fdsub */
4712 gen_helper_fdsub(cpu_env
, cpu_dest
, cpu_src
, cpu_dest
);
4714 case 0x38: /* fcmp */
4715 gen_helper_fcmp(cpu_env
, cpu_src
, cpu_dest
);
4717 case 0x3a: /* ftst */
4718 gen_helper_ftst(cpu_env
, cpu_src
);
4723 tcg_temp_free_ptr(cpu_src
);
4724 gen_helper_ftst(cpu_env
, cpu_dest
);
4725 tcg_temp_free_ptr(cpu_dest
);
4728 /* FIXME: Is this right for offset addressing modes? */
4730 disas_undef_fpu(env
, s
, insn
);
4733 static void gen_fcc_cond(DisasCompare
*c
, DisasContext
*s
, int cond
)
4738 c
->v2
= tcg_const_i32(0);
4740 /* TODO: Raise BSUN exception. */
4741 fpsr
= tcg_temp_new();
4742 gen_load_fcr(s
, fpsr
, M68K_FPSR
);
4745 case 16: /* Signaling False */
4747 c
->tcond
= TCG_COND_NEVER
;
4749 case 1: /* EQual Z */
4750 case 17: /* Signaling EQual Z */
4751 c
->v1
= tcg_temp_new();
4753 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
4754 c
->tcond
= TCG_COND_NE
;
4756 case 2: /* Ordered Greater Than !(A || Z || N) */
4757 case 18: /* Greater Than !(A || Z || N) */
4758 c
->v1
= tcg_temp_new();
4760 tcg_gen_andi_i32(c
->v1
, fpsr
,
4761 FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
4762 c
->tcond
= TCG_COND_EQ
;
4764 case 3: /* Ordered Greater than or Equal Z || !(A || N) */
4765 case 19: /* Greater than or Equal Z || !(A || N) */
4766 c
->v1
= tcg_temp_new();
4768 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
4769 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
4770 tcg_gen_andi_i32(fpsr
, fpsr
, FPSR_CC_Z
| FPSR_CC_N
);
4771 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
4772 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
4773 c
->tcond
= TCG_COND_NE
;
4775 case 4: /* Ordered Less Than !(!N || A || Z); */
4776 case 20: /* Less Than !(!N || A || Z); */
4777 c
->v1
= tcg_temp_new();
4779 tcg_gen_xori_i32(c
->v1
, fpsr
, FPSR_CC_N
);
4780 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_N
| FPSR_CC_A
| FPSR_CC_Z
);
4781 c
->tcond
= TCG_COND_EQ
;
4783 case 5: /* Ordered Less than or Equal Z || (N && !A) */
4784 case 21: /* Less than or Equal Z || (N && !A) */
4785 c
->v1
= tcg_temp_new();
4787 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
4788 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_A
));
4789 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
4790 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_Z
| FPSR_CC_N
);
4791 c
->tcond
= TCG_COND_NE
;
4793 case 6: /* Ordered Greater or Less than !(A || Z) */
4794 case 22: /* Greater or Less than !(A || Z) */
4795 c
->v1
= tcg_temp_new();
4797 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
4798 c
->tcond
= TCG_COND_EQ
;
4800 case 7: /* Ordered !A */
4801 case 23: /* Greater, Less or Equal !A */
4802 c
->v1
= tcg_temp_new();
4804 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
4805 c
->tcond
= TCG_COND_EQ
;
4807 case 8: /* Unordered A */
4808 case 24: /* Not Greater, Less or Equal A */
4809 c
->v1
= tcg_temp_new();
4811 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
);
4812 c
->tcond
= TCG_COND_NE
;
4814 case 9: /* Unordered or Equal A || Z */
4815 case 25: /* Not Greater or Less then A || Z */
4816 c
->v1
= tcg_temp_new();
4818 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
);
4819 c
->tcond
= TCG_COND_NE
;
4821 case 10: /* Unordered or Greater Than A || !(N || Z)) */
4822 case 26: /* Not Less or Equal A || !(N || Z)) */
4823 c
->v1
= tcg_temp_new();
4825 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
4826 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
4827 tcg_gen_andi_i32(fpsr
, fpsr
, FPSR_CC_A
| FPSR_CC_N
);
4828 tcg_gen_or_i32(c
->v1
, c
->v1
, fpsr
);
4829 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
4830 c
->tcond
= TCG_COND_NE
;
4832 case 11: /* Unordered or Greater or Equal A || Z || !N */
4833 case 27: /* Not Less Than A || Z || !N */
4834 c
->v1
= tcg_temp_new();
4836 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
4837 tcg_gen_xori_i32(c
->v1
, c
->v1
, FPSR_CC_N
);
4838 c
->tcond
= TCG_COND_NE
;
4840 case 12: /* Unordered or Less Than A || (N && !Z) */
4841 case 28: /* Not Greater than or Equal A || (N && !Z) */
4842 c
->v1
= tcg_temp_new();
4844 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
4845 tcg_gen_shli_i32(c
->v1
, c
->v1
, ctz32(FPSR_CC_N
) - ctz32(FPSR_CC_Z
));
4846 tcg_gen_andc_i32(c
->v1
, fpsr
, c
->v1
);
4847 tcg_gen_andi_i32(c
->v1
, c
->v1
, FPSR_CC_A
| FPSR_CC_N
);
4848 c
->tcond
= TCG_COND_NE
;
4850 case 13: /* Unordered or Less or Equal A || Z || N */
4851 case 29: /* Not Greater Than A || Z || N */
4852 c
->v1
= tcg_temp_new();
4854 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_A
| FPSR_CC_Z
| FPSR_CC_N
);
4855 c
->tcond
= TCG_COND_NE
;
4857 case 14: /* Not Equal !Z */
4858 case 30: /* Signaling Not Equal !Z */
4859 c
->v1
= tcg_temp_new();
4861 tcg_gen_andi_i32(c
->v1
, fpsr
, FPSR_CC_Z
);
4862 c
->tcond
= TCG_COND_EQ
;
4865 case 31: /* Signaling True */
4867 c
->tcond
= TCG_COND_ALWAYS
;
4870 tcg_temp_free(fpsr
);
4873 static void gen_fjmpcc(DisasContext
*s
, int cond
, TCGLabel
*l1
)
4877 gen_fcc_cond(&c
, s
, cond
);
4878 tcg_gen_brcond_i32(c
.tcond
, c
.v1
, c
.v2
, l1
);
4889 offset
= (int16_t)read_im16(env
, s
);
4890 if (insn
& (1 << 6)) {
4891 offset
= (offset
<< 16) | read_im16(env
, s
);
4894 l1
= gen_new_label();
4896 gen_fjmpcc(s
, insn
& 0x3f, l1
);
4897 gen_jmp_tb(s
, 0, s
->pc
);
4899 gen_jmp_tb(s
, 1, base
+ offset
);
4909 ext
= read_im16(env
, s
);
4911 gen_fcc_cond(&c
, s
, cond
);
4913 tmp
= tcg_temp_new();
4914 tcg_gen_setcond_i32(c
.tcond
, tmp
, c
.v1
, c
.v2
);
4917 tcg_gen_neg_i32(tmp
, tmp
);
4918 DEST_EA(env
, insn
, OS_BYTE
, tmp
, NULL
);
4922 DISAS_INSN(frestore
)
4924 M68kCPU
*cpu
= m68k_env_get_cpu(env
);
4926 /* TODO: Implement frestore. */
4927 cpu_abort(CPU(cpu
), "FRESTORE not implemented");
4932 M68kCPU
*cpu
= m68k_env_get_cpu(env
);
4934 /* TODO: Implement fsave. */
4935 cpu_abort(CPU(cpu
), "FSAVE not implemented");
4938 static inline TCGv
gen_mac_extract_word(DisasContext
*s
, TCGv val
, int upper
)
4940 TCGv tmp
= tcg_temp_new();
4941 if (s
->env
->macsr
& MACSR_FI
) {
4943 tcg_gen_andi_i32(tmp
, val
, 0xffff0000);
4945 tcg_gen_shli_i32(tmp
, val
, 16);
4946 } else if (s
->env
->macsr
& MACSR_SU
) {
4948 tcg_gen_sari_i32(tmp
, val
, 16);
4950 tcg_gen_ext16s_i32(tmp
, val
);
4953 tcg_gen_shri_i32(tmp
, val
, 16);
4955 tcg_gen_ext16u_i32(tmp
, val
);
4960 static void gen_mac_clear_flags(void)
4962 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
,
4963 ~(MACSR_V
| MACSR_Z
| MACSR_N
| MACSR_EV
));
4979 s
->mactmp
= tcg_temp_new_i64();
4983 ext
= read_im16(env
, s
);
4985 acc
= ((insn
>> 7) & 1) | ((ext
>> 3) & 2);
4986 dual
= ((insn
& 0x30) != 0 && (ext
& 3) != 0);
4987 if (dual
&& !m68k_feature(s
->env
, M68K_FEATURE_CF_EMAC_B
)) {
4988 disas_undef(env
, s
, insn
);
4992 /* MAC with load. */
4993 tmp
= gen_lea(env
, s
, insn
, OS_LONG
);
4994 addr
= tcg_temp_new();
4995 tcg_gen_and_i32(addr
, tmp
, QREG_MAC_MASK
);
4996 /* Load the value now to ensure correct exception behavior.
4997 Perform writeback after reading the MAC inputs. */
4998 loadval
= gen_load(s
, OS_LONG
, addr
, 0);
5001 rx
= (ext
& 0x8000) ? AREG(ext
, 12) : DREG(insn
, 12);
5002 ry
= (ext
& 8) ? AREG(ext
, 0) : DREG(ext
, 0);
5004 loadval
= addr
= NULL_QREG
;
5005 rx
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5006 ry
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5009 gen_mac_clear_flags();
5012 /* Disabled because conditional branches clobber temporary vars. */
5013 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && !dual
) {
5014 /* Skip the multiply if we know we will ignore it. */
5015 l1
= gen_new_label();
5016 tmp
= tcg_temp_new();
5017 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 1 << (acc
+ 8));
5018 gen_op_jmp_nz32(tmp
, l1
);
5022 if ((ext
& 0x0800) == 0) {
5024 rx
= gen_mac_extract_word(s
, rx
, (ext
& 0x80) != 0);
5025 ry
= gen_mac_extract_word(s
, ry
, (ext
& 0x40) != 0);
5027 if (s
->env
->macsr
& MACSR_FI
) {
5028 gen_helper_macmulf(s
->mactmp
, cpu_env
, rx
, ry
);
5030 if (s
->env
->macsr
& MACSR_SU
)
5031 gen_helper_macmuls(s
->mactmp
, cpu_env
, rx
, ry
);
5033 gen_helper_macmulu(s
->mactmp
, cpu_env
, rx
, ry
);
5034 switch ((ext
>> 9) & 3) {
5036 tcg_gen_shli_i64(s
->mactmp
, s
->mactmp
, 1);
5039 tcg_gen_shri_i64(s
->mactmp
, s
->mactmp
, 1);
5045 /* Save the overflow flag from the multiply. */
5046 saved_flags
= tcg_temp_new();
5047 tcg_gen_mov_i32(saved_flags
, QREG_MACSR
);
5049 saved_flags
= NULL_QREG
;
5053 /* Disabled because conditional branches clobber temporary vars. */
5054 if ((s
->env
->macsr
& MACSR_OMC
) != 0 && dual
) {
5055 /* Skip the accumulate if the value is already saturated. */
5056 l1
= gen_new_label();
5057 tmp
= tcg_temp_new();
5058 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
5059 gen_op_jmp_nz32(tmp
, l1
);
5064 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5066 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5068 if (s
->env
->macsr
& MACSR_FI
)
5069 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
5070 else if (s
->env
->macsr
& MACSR_SU
)
5071 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
5073 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
5076 /* Disabled because conditional branches clobber temporary vars. */
5082 /* Dual accumulate variant. */
5083 acc
= (ext
>> 2) & 3;
5084 /* Restore the overflow flag from the multiplier. */
5085 tcg_gen_mov_i32(QREG_MACSR
, saved_flags
);
5087 /* Disabled because conditional branches clobber temporary vars. */
5088 if ((s
->env
->macsr
& MACSR_OMC
) != 0) {
5089 /* Skip the accumulate if the value is already saturated. */
5090 l1
= gen_new_label();
5091 tmp
= tcg_temp_new();
5092 gen_op_and32(tmp
, QREG_MACSR
, tcg_const_i32(MACSR_PAV0
<< acc
));
5093 gen_op_jmp_nz32(tmp
, l1
);
5097 tcg_gen_sub_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5099 tcg_gen_add_i64(MACREG(acc
), MACREG(acc
), s
->mactmp
);
5100 if (s
->env
->macsr
& MACSR_FI
)
5101 gen_helper_macsatf(cpu_env
, tcg_const_i32(acc
));
5102 else if (s
->env
->macsr
& MACSR_SU
)
5103 gen_helper_macsats(cpu_env
, tcg_const_i32(acc
));
5105 gen_helper_macsatu(cpu_env
, tcg_const_i32(acc
));
5107 /* Disabled because conditional branches clobber temporary vars. */
5112 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(acc
));
5116 rw
= (insn
& 0x40) ? AREG(insn
, 9) : DREG(insn
, 9);
5117 tcg_gen_mov_i32(rw
, loadval
);
5118 /* FIXME: Should address writeback happen with the masked or
5120 switch ((insn
>> 3) & 7) {
5121 case 3: /* Post-increment. */
5122 tcg_gen_addi_i32(AREG(insn
, 0), addr
, 4);
5124 case 4: /* Pre-decrement. */
5125 tcg_gen_mov_i32(AREG(insn
, 0), addr
);
5130 DISAS_INSN(from_mac
)
5136 rx
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5137 accnum
= (insn
>> 9) & 3;
5138 acc
= MACREG(accnum
);
5139 if (s
->env
->macsr
& MACSR_FI
) {
5140 gen_helper_get_macf(rx
, cpu_env
, acc
);
5141 } else if ((s
->env
->macsr
& MACSR_OMC
) == 0) {
5142 tcg_gen_extrl_i64_i32(rx
, acc
);
5143 } else if (s
->env
->macsr
& MACSR_SU
) {
5144 gen_helper_get_macs(rx
, acc
);
5146 gen_helper_get_macu(rx
, acc
);
5149 tcg_gen_movi_i64(acc
, 0);
5150 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5154 DISAS_INSN(move_mac
)
5156 /* FIXME: This can be done without a helper. */
5160 dest
= tcg_const_i32((insn
>> 9) & 3);
5161 gen_helper_mac_move(cpu_env
, dest
, tcg_const_i32(src
));
5162 gen_mac_clear_flags();
5163 gen_helper_mac_set_flags(cpu_env
, dest
);
5166 DISAS_INSN(from_macsr
)
5170 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5171 tcg_gen_mov_i32(reg
, QREG_MACSR
);
5174 DISAS_INSN(from_mask
)
5177 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5178 tcg_gen_mov_i32(reg
, QREG_MAC_MASK
);
5181 DISAS_INSN(from_mext
)
5185 reg
= (insn
& 8) ? AREG(insn
, 0) : DREG(insn
, 0);
5186 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
5187 if (s
->env
->macsr
& MACSR_FI
)
5188 gen_helper_get_mac_extf(reg
, cpu_env
, acc
);
5190 gen_helper_get_mac_exti(reg
, cpu_env
, acc
);
5193 DISAS_INSN(macsr_to_ccr
)
5195 TCGv tmp
= tcg_temp_new();
5196 tcg_gen_andi_i32(tmp
, QREG_MACSR
, 0xf);
5197 gen_helper_set_sr(cpu_env
, tmp
);
5199 set_cc_op(s
, CC_OP_FLAGS
);
5207 accnum
= (insn
>> 9) & 3;
5208 acc
= MACREG(accnum
);
5209 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5210 if (s
->env
->macsr
& MACSR_FI
) {
5211 tcg_gen_ext_i32_i64(acc
, val
);
5212 tcg_gen_shli_i64(acc
, acc
, 8);
5213 } else if (s
->env
->macsr
& MACSR_SU
) {
5214 tcg_gen_ext_i32_i64(acc
, val
);
5216 tcg_gen_extu_i32_i64(acc
, val
);
5218 tcg_gen_andi_i32(QREG_MACSR
, QREG_MACSR
, ~(MACSR_PAV0
<< accnum
));
5219 gen_mac_clear_flags();
5220 gen_helper_mac_set_flags(cpu_env
, tcg_const_i32(accnum
));
5223 DISAS_INSN(to_macsr
)
5226 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5227 gen_helper_set_macsr(cpu_env
, val
);
5234 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5235 tcg_gen_ori_i32(QREG_MAC_MASK
, val
, 0xffff0000);
5242 SRC_EA(env
, val
, OS_LONG
, 0, NULL
);
5243 acc
= tcg_const_i32((insn
& 0x400) ? 2 : 0);
5244 if (s
->env
->macsr
& MACSR_FI
)
5245 gen_helper_set_mac_extf(cpu_env
, val
, acc
);
5246 else if (s
->env
->macsr
& MACSR_SU
)
5247 gen_helper_set_mac_exts(cpu_env
, val
, acc
);
5249 gen_helper_set_mac_extu(cpu_env
, val
, acc
);
5252 static disas_proc opcode_table
[65536];
5255 register_opcode (disas_proc proc
, uint16_t opcode
, uint16_t mask
)
5261 /* Sanity check. All set bits must be included in the mask. */
5262 if (opcode
& ~mask
) {
5264 "qemu internal error: bogus opcode definition %04x/%04x\n",
5268 /* This could probably be cleverer. For now just optimize the case where
5269 the top bits are known. */
5270 /* Find the first zero bit in the mask. */
5272 while ((i
& mask
) != 0)
5274 /* Iterate over all combinations of this and lower bits. */
5279 from
= opcode
& ~(i
- 1);
5281 for (i
= from
; i
< to
; i
++) {
5282 if ((i
& mask
) == opcode
)
5283 opcode_table
[i
] = proc
;
5287 /* Register m68k opcode handlers. Order is important.
5288 Later insn override earlier ones. */
5289 void register_m68k_insns (CPUM68KState
*env
)
5291 /* Build the opcode table only once to avoid
5292 multithreading issues. */
5293 if (opcode_table
[0] != NULL
) {
5297 /* use BASE() for instruction available
5298 * for CF_ISA_A and M68000.
5300 #define BASE(name, opcode, mask) \
5301 register_opcode(disas_##name, 0x##opcode, 0x##mask)
5302 #define INSN(name, opcode, mask, feature) do { \
5303 if (m68k_feature(env, M68K_FEATURE_##feature)) \
5304 BASE(name, opcode, mask); \
5306 BASE(undef
, 0000, 0000);
5307 INSN(arith_im
, 0080, fff8
, CF_ISA_A
);
5308 INSN(arith_im
, 0000, ff00
, M68000
);
5309 INSN(undef
, 00c0
, ffc0
, M68000
);
5310 INSN(bitrev
, 00c0
, fff8
, CF_ISA_APLUSC
);
5311 BASE(bitop_reg
, 0100, f1c0
);
5312 BASE(bitop_reg
, 0140, f1c0
);
5313 BASE(bitop_reg
, 0180, f1c0
);
5314 BASE(bitop_reg
, 01c0
, f1c0
);
5315 INSN(arith_im
, 0280, fff8
, CF_ISA_A
);
5316 INSN(arith_im
, 0200, ff00
, M68000
);
5317 INSN(undef
, 02c0
, ffc0
, M68000
);
5318 INSN(byterev
, 02c0
, fff8
, CF_ISA_APLUSC
);
5319 INSN(arith_im
, 0480, fff8
, CF_ISA_A
);
5320 INSN(arith_im
, 0400, ff00
, M68000
);
5321 INSN(undef
, 04c0
, ffc0
, M68000
);
5322 INSN(arith_im
, 0600, ff00
, M68000
);
5323 INSN(undef
, 06c0
, ffc0
, M68000
);
5324 INSN(ff1
, 04c0
, fff8
, CF_ISA_APLUSC
);
5325 INSN(arith_im
, 0680, fff8
, CF_ISA_A
);
5326 INSN(arith_im
, 0c00
, ff38
, CF_ISA_A
);
5327 INSN(arith_im
, 0c00
, ff00
, M68000
);
5328 BASE(bitop_im
, 0800, ffc0
);
5329 BASE(bitop_im
, 0840, ffc0
);
5330 BASE(bitop_im
, 0880, ffc0
);
5331 BASE(bitop_im
, 08c0
, ffc0
);
5332 INSN(arith_im
, 0a80
, fff8
, CF_ISA_A
);
5333 INSN(arith_im
, 0a00
, ff00
, M68000
);
5334 INSN(cas
, 0ac0
, ffc0
, CAS
);
5335 INSN(cas
, 0cc0
, ffc0
, CAS
);
5336 INSN(cas
, 0ec0
, ffc0
, CAS
);
5337 INSN(cas2w
, 0cfc
, ffff
, CAS
);
5338 INSN(cas2l
, 0efc
, ffff
, CAS
);
5339 BASE(move
, 1000, f000
);
5340 BASE(move
, 2000, f000
);
5341 BASE(move
, 3000, f000
);
5342 INSN(strldsr
, 40e7
, ffff
, CF_ISA_APLUSC
);
5343 INSN(negx
, 4080, fff8
, CF_ISA_A
);
5344 INSN(negx
, 4000, ff00
, M68000
);
5345 INSN(undef
, 40c0
, ffc0
, M68000
);
5346 INSN(move_from_sr
, 40c0
, fff8
, CF_ISA_A
);
5347 INSN(move_from_sr
, 40c0
, ffc0
, M68000
);
5348 BASE(lea
, 41c0
, f1c0
);
5349 BASE(clr
, 4200, ff00
);
5350 BASE(undef
, 42c0
, ffc0
);
5351 INSN(move_from_ccr
, 42c0
, fff8
, CF_ISA_A
);
5352 INSN(move_from_ccr
, 42c0
, ffc0
, M68000
);
5353 INSN(neg
, 4480, fff8
, CF_ISA_A
);
5354 INSN(neg
, 4400, ff00
, M68000
);
5355 INSN(undef
, 44c0
, ffc0
, M68000
);
5356 BASE(move_to_ccr
, 44c0
, ffc0
);
5357 INSN(not, 4680, fff8
, CF_ISA_A
);
5358 INSN(not, 4600, ff00
, M68000
);
5359 INSN(undef
, 46c0
, ffc0
, M68000
);
5360 INSN(move_to_sr
, 46c0
, ffc0
, CF_ISA_A
);
5361 INSN(nbcd
, 4800, ffc0
, M68000
);
5362 INSN(linkl
, 4808, fff8
, M68000
);
5363 BASE(pea
, 4840, ffc0
);
5364 BASE(swap
, 4840, fff8
);
5365 INSN(bkpt
, 4848, fff8
, BKPT
);
5366 INSN(movem
, 48d0
, fbf8
, CF_ISA_A
);
5367 INSN(movem
, 48e8
, fbf8
, CF_ISA_A
);
5368 INSN(movem
, 4880, fb80
, M68000
);
5369 BASE(ext
, 4880, fff8
);
5370 BASE(ext
, 48c0
, fff8
);
5371 BASE(ext
, 49c0
, fff8
);
5372 BASE(tst
, 4a00
, ff00
);
5373 INSN(tas
, 4ac0
, ffc0
, CF_ISA_B
);
5374 INSN(tas
, 4ac0
, ffc0
, M68000
);
5375 INSN(halt
, 4ac8
, ffff
, CF_ISA_A
);
5376 INSN(pulse
, 4acc
, ffff
, CF_ISA_A
);
5377 BASE(illegal
, 4afc
, ffff
);
5378 INSN(mull
, 4c00
, ffc0
, CF_ISA_A
);
5379 INSN(mull
, 4c00
, ffc0
, LONG_MULDIV
);
5380 INSN(divl
, 4c40
, ffc0
, CF_ISA_A
);
5381 INSN(divl
, 4c40
, ffc0
, LONG_MULDIV
);
5382 INSN(sats
, 4c80
, fff8
, CF_ISA_B
);
5383 BASE(trap
, 4e40
, fff0
);
5384 BASE(link
, 4e50
, fff8
);
5385 BASE(unlk
, 4e58
, fff8
);
5386 INSN(move_to_usp
, 4e60
, fff8
, USP
);
5387 INSN(move_from_usp
, 4e68
, fff8
, USP
);
5388 BASE(nop
, 4e71
, ffff
);
5389 BASE(stop
, 4e72
, ffff
);
5390 BASE(rte
, 4e73
, ffff
);
5391 INSN(rtd
, 4e74
, ffff
, RTD
);
5392 BASE(rts
, 4e75
, ffff
);
5393 INSN(movec
, 4e7b
, ffff
, CF_ISA_A
);
5394 BASE(jump
, 4e80
, ffc0
);
5395 BASE(jump
, 4ec0
, ffc0
);
5396 INSN(addsubq
, 5000, f080
, M68000
);
5397 BASE(addsubq
, 5080, f0c0
);
5398 INSN(scc
, 50c0
, f0f8
, CF_ISA_A
); /* Scc.B Dx */
5399 INSN(scc
, 50c0
, f0c0
, M68000
); /* Scc.B <EA> */
5400 INSN(dbcc
, 50c8
, f0f8
, M68000
);
5401 INSN(tpf
, 51f8
, fff8
, CF_ISA_A
);
5403 /* Branch instructions. */
5404 BASE(branch
, 6000, f000
);
5405 /* Disable long branch instructions, then add back the ones we want. */
5406 BASE(undef
, 60ff
, f0ff
); /* All long branches. */
5407 INSN(branch
, 60ff
, f0ff
, CF_ISA_B
);
5408 INSN(undef
, 60ff
, ffff
, CF_ISA_B
); /* bra.l */
5409 INSN(branch
, 60ff
, ffff
, BRAL
);
5410 INSN(branch
, 60ff
, f0ff
, BCCL
);
5412 BASE(moveq
, 7000, f100
);
5413 INSN(mvzs
, 7100, f100
, CF_ISA_B
);
5414 BASE(or, 8000, f000
);
5415 BASE(divw
, 80c0
, f0c0
);
5416 INSN(sbcd_reg
, 8100, f1f8
, M68000
);
5417 INSN(sbcd_mem
, 8108, f1f8
, M68000
);
5418 BASE(addsub
, 9000, f000
);
5419 INSN(undef
, 90c0
, f0c0
, CF_ISA_A
);
5420 INSN(subx_reg
, 9180, f1f8
, CF_ISA_A
);
5421 INSN(subx_reg
, 9100, f138
, M68000
);
5422 INSN(subx_mem
, 9108, f138
, M68000
);
5423 INSN(suba
, 91c0
, f1c0
, CF_ISA_A
);
5424 INSN(suba
, 90c0
, f0c0
, M68000
);
5426 BASE(undef_mac
, a000
, f000
);
5427 INSN(mac
, a000
, f100
, CF_EMAC
);
5428 INSN(from_mac
, a180
, f9b0
, CF_EMAC
);
5429 INSN(move_mac
, a110
, f9fc
, CF_EMAC
);
5430 INSN(from_macsr
,a980
, f9f0
, CF_EMAC
);
5431 INSN(from_mask
, ad80
, fff0
, CF_EMAC
);
5432 INSN(from_mext
, ab80
, fbf0
, CF_EMAC
);
5433 INSN(macsr_to_ccr
, a9c0
, ffff
, CF_EMAC
);
5434 INSN(to_mac
, a100
, f9c0
, CF_EMAC
);
5435 INSN(to_macsr
, a900
, ffc0
, CF_EMAC
);
5436 INSN(to_mext
, ab00
, fbc0
, CF_EMAC
);
5437 INSN(to_mask
, ad00
, ffc0
, CF_EMAC
);
5439 INSN(mov3q
, a140
, f1c0
, CF_ISA_B
);
5440 INSN(cmp
, b000
, f1c0
, CF_ISA_B
); /* cmp.b */
5441 INSN(cmp
, b040
, f1c0
, CF_ISA_B
); /* cmp.w */
5442 INSN(cmpa
, b0c0
, f1c0
, CF_ISA_B
); /* cmpa.w */
5443 INSN(cmp
, b080
, f1c0
, CF_ISA_A
);
5444 INSN(cmpa
, b1c0
, f1c0
, CF_ISA_A
);
5445 INSN(cmp
, b000
, f100
, M68000
);
5446 INSN(eor
, b100
, f100
, M68000
);
5447 INSN(cmpm
, b108
, f138
, M68000
);
5448 INSN(cmpa
, b0c0
, f0c0
, M68000
);
5449 INSN(eor
, b180
, f1c0
, CF_ISA_A
);
5450 BASE(and, c000
, f000
);
5451 INSN(exg_dd
, c140
, f1f8
, M68000
);
5452 INSN(exg_aa
, c148
, f1f8
, M68000
);
5453 INSN(exg_da
, c188
, f1f8
, M68000
);
5454 BASE(mulw
, c0c0
, f0c0
);
5455 INSN(abcd_reg
, c100
, f1f8
, M68000
);
5456 INSN(abcd_mem
, c108
, f1f8
, M68000
);
5457 BASE(addsub
, d000
, f000
);
5458 INSN(undef
, d0c0
, f0c0
, CF_ISA_A
);
5459 INSN(addx_reg
, d180
, f1f8
, CF_ISA_A
);
5460 INSN(addx_reg
, d100
, f138
, M68000
);
5461 INSN(addx_mem
, d108
, f138
, M68000
);
5462 INSN(adda
, d1c0
, f1c0
, CF_ISA_A
);
5463 INSN(adda
, d0c0
, f0c0
, M68000
);
5464 INSN(shift_im
, e080
, f0f0
, CF_ISA_A
);
5465 INSN(shift_reg
, e0a0
, f0f0
, CF_ISA_A
);
5466 INSN(shift8_im
, e000
, f0f0
, M68000
);
5467 INSN(shift16_im
, e040
, f0f0
, M68000
);
5468 INSN(shift_im
, e080
, f0f0
, M68000
);
5469 INSN(shift8_reg
, e020
, f0f0
, M68000
);
5470 INSN(shift16_reg
, e060
, f0f0
, M68000
);
5471 INSN(shift_reg
, e0a0
, f0f0
, M68000
);
5472 INSN(shift_mem
, e0c0
, fcc0
, M68000
);
5473 INSN(rotate_im
, e090
, f0f0
, M68000
);
5474 INSN(rotate8_im
, e010
, f0f0
, M68000
);
5475 INSN(rotate16_im
, e050
, f0f0
, M68000
);
5476 INSN(rotate_reg
, e0b0
, f0f0
, M68000
);
5477 INSN(rotate8_reg
, e030
, f0f0
, M68000
);
5478 INSN(rotate16_reg
, e070
, f0f0
, M68000
);
5479 INSN(rotate_mem
, e4c0
, fcc0
, M68000
);
5480 INSN(bfext_mem
, e9c0
, fdc0
, BITFIELD
); /* bfextu & bfexts */
5481 INSN(bfext_reg
, e9c0
, fdf8
, BITFIELD
);
5482 INSN(bfins_mem
, efc0
, ffc0
, BITFIELD
);
5483 INSN(bfins_reg
, efc0
, fff8
, BITFIELD
);
5484 INSN(bfop_mem
, eac0
, ffc0
, BITFIELD
); /* bfchg */
5485 INSN(bfop_reg
, eac0
, fff8
, BITFIELD
); /* bfchg */
5486 INSN(bfop_mem
, ecc0
, ffc0
, BITFIELD
); /* bfclr */
5487 INSN(bfop_reg
, ecc0
, fff8
, BITFIELD
); /* bfclr */
5488 INSN(bfop_mem
, edc0
, ffc0
, BITFIELD
); /* bfffo */
5489 INSN(bfop_reg
, edc0
, fff8
, BITFIELD
); /* bfffo */
5490 INSN(bfop_mem
, eec0
, ffc0
, BITFIELD
); /* bfset */
5491 INSN(bfop_reg
, eec0
, fff8
, BITFIELD
); /* bfset */
5492 INSN(bfop_mem
, e8c0
, ffc0
, BITFIELD
); /* bftst */
5493 INSN(bfop_reg
, e8c0
, fff8
, BITFIELD
); /* bftst */
5494 BASE(undef_fpu
, f000
, f000
);
5495 INSN(fpu
, f200
, ffc0
, CF_FPU
);
5496 INSN(fbcc
, f280
, ffc0
, CF_FPU
);
5497 INSN(frestore
, f340
, ffc0
, CF_FPU
);
5498 INSN(fsave
, f300
, ffc0
, CF_FPU
);
5499 INSN(fpu
, f200
, ffc0
, FPU
);
5500 INSN(fscc
, f240
, ffc0
, FPU
);
5501 INSN(fbcc
, f280
, ff80
, FPU
);
5502 INSN(frestore
, f340
, ffc0
, FPU
);
5503 INSN(fsave
, f300
, ffc0
, FPU
);
5504 INSN(intouch
, f340
, ffc0
, CF_ISA_A
);
5505 INSN(cpushl
, f428
, ff38
, CF_ISA_A
);
5506 INSN(wddata
, fb00
, ff00
, CF_ISA_A
);
5507 INSN(wdebug
, fbc0
, ffc0
, CF_ISA_A
);
5511 /* ??? Some of this implementation is not exception safe. We should always
5512 write back the result to memory before setting the condition codes. */
5513 static void disas_m68k_insn(CPUM68KState
* env
, DisasContext
*s
)
5515 uint16_t insn
= read_im16(env
, s
);
5516 opcode_table
[insn
](env
, s
, insn
);
5520 /* generate intermediate code for basic block 'tb'. */
5521 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
)
5523 CPUM68KState
*env
= cs
->env_ptr
;
5524 DisasContext dc1
, *dc
= &dc1
;
5525 target_ulong pc_start
;
5530 /* generate intermediate code */
5536 dc
->is_jmp
= DISAS_NEXT
;
5538 dc
->cc_op
= CC_OP_DYNAMIC
;
5539 dc
->cc_op_synced
= 1;
5540 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
5541 dc
->user
= (env
->sr
& SR_S
) == 0;
5543 dc
->writeback_mask
= 0;
5545 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
5546 if (max_insns
== 0) {
5547 max_insns
= CF_COUNT_MASK
;
5549 if (max_insns
> TCG_MAX_INSNS
) {
5550 max_insns
= TCG_MAX_INSNS
;
5555 pc_offset
= dc
->pc
- pc_start
;
5556 gen_throws_exception
= NULL
;
5557 tcg_gen_insn_start(dc
->pc
, dc
->cc_op
);
5560 if (unlikely(cpu_breakpoint_test(cs
, dc
->pc
, BP_ANY
))) {
5561 gen_exception(dc
, dc
->pc
, EXCP_DEBUG
);
5562 dc
->is_jmp
= DISAS_JUMP
;
5563 /* The address covered by the breakpoint must be included in
5564 [tb->pc, tb->pc + tb->size) in order to for it to be
5565 properly cleared -- thus we increment the PC here so that
5566 the logic setting tb->size below does the right thing. */
5571 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
5575 dc
->insn_pc
= dc
->pc
;
5576 disas_m68k_insn(env
, dc
);
5577 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
5578 !cs
->singlestep_enabled
&&
5580 (pc_offset
) < (TARGET_PAGE_SIZE
- 32) &&
5581 num_insns
< max_insns
);
5583 if (tb
->cflags
& CF_LAST_IO
)
5585 if (unlikely(cs
->singlestep_enabled
)) {
5586 /* Make sure the pc is updated, and raise a debug exception. */
5589 tcg_gen_movi_i32(QREG_PC
, dc
->pc
);
5591 gen_helper_raise_exception(cpu_env
, tcg_const_i32(EXCP_DEBUG
));
5593 switch(dc
->is_jmp
) {
5596 gen_jmp_tb(dc
, 0, dc
->pc
);
5602 /* indicate that the hash table must be used to find the next TB */
5606 /* nothing more to generate */
5610 gen_tb_end(tb
, num_insns
);
5613 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)
5614 && qemu_log_in_addr_range(pc_start
)) {
5616 qemu_log("----------------\n");
5617 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
5618 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
, 0);
5623 tb
->size
= dc
->pc
- pc_start
;
5624 tb
->icount
= num_insns
;
5627 static double floatx80_to_double(CPUM68KState
*env
, uint16_t high
, uint64_t low
)
5629 floatx80 a
= { .high
= high
, .low
= low
};
5635 u
.f64
= floatx80_to_float64(a
, &env
->fp_status
);
5639 void m68k_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
5642 M68kCPU
*cpu
= M68K_CPU(cs
);
5643 CPUM68KState
*env
= &cpu
->env
;
5646 for (i
= 0; i
< 8; i
++) {
5647 cpu_fprintf(f
, "D%d = %08x A%d = %08x "
5648 "F%d = %04x %016"PRIx64
" (%12g)\n",
5649 i
, env
->dregs
[i
], i
, env
->aregs
[i
],
5650 i
, env
->fregs
[i
].l
.upper
, env
->fregs
[i
].l
.lower
,
5651 floatx80_to_double(env
, env
->fregs
[i
].l
.upper
,
5652 env
->fregs
[i
].l
.lower
));
5654 cpu_fprintf (f
, "PC = %08x ", env
->pc
);
5655 sr
= env
->sr
| cpu_m68k_get_ccr(env
);
5656 cpu_fprintf(f
, "SR = %04x %c%c%c%c%c ", sr
, (sr
& CCF_X
) ? 'X' : '-',
5657 (sr
& CCF_N
) ? 'N' : '-', (sr
& CCF_Z
) ? 'Z' : '-',
5658 (sr
& CCF_V
) ? 'V' : '-', (sr
& CCF_C
) ? 'C' : '-');
5659 cpu_fprintf(f
, "FPSR = %08x %c%c%c%c ", env
->fpsr
,
5660 (env
->fpsr
& FPSR_CC_A
) ? 'A' : '-',
5661 (env
->fpsr
& FPSR_CC_I
) ? 'I' : '-',
5662 (env
->fpsr
& FPSR_CC_Z
) ? 'Z' : '-',
5663 (env
->fpsr
& FPSR_CC_N
) ? 'N' : '-');
5664 cpu_fprintf(f
, "\n "
5665 "FPCR = %04x ", env
->fpcr
);
5666 switch (env
->fpcr
& FPCR_PREC_MASK
) {
5668 cpu_fprintf(f
, "X ");
5671 cpu_fprintf(f
, "S ");
5674 cpu_fprintf(f
, "D ");
5677 switch (env
->fpcr
& FPCR_RND_MASK
) {
5679 cpu_fprintf(f
, "RN ");
5682 cpu_fprintf(f
, "RZ ");
5685 cpu_fprintf(f
, "RM ");
5688 cpu_fprintf(f
, "RP ");
5693 void restore_state_to_opc(CPUM68KState
*env
, TranslationBlock
*tb
,
5696 int cc_op
= data
[1];
5698 if (cc_op
!= CC_OP_DYNAMIC
) {