2006-10-22 08:18:54 +08:00
|
|
|
/*
|
|
|
|
* m68k translation
|
2007-09-17 05:08:06 +08:00
|
|
|
*
|
2007-05-24 03:58:11 +08:00
|
|
|
* Copyright (c) 2005-2007 CodeSourcery
|
2006-10-22 08:18:54 +08:00
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-07-17 04:47:01 +08:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2006-10-22 08:18:54 +08:00
|
|
|
*/
|
|
|
|
|
2016-01-27 02:17:23 +08:00
|
|
|
#include "qemu/osdep.h"
|
2006-10-22 08:18:54 +08:00
|
|
|
#include "cpu.h"
|
2012-10-24 17:12:21 +08:00
|
|
|
#include "disas/disas.h"
|
2016-03-15 20:18:37 +08:00
|
|
|
#include "exec/exec-all.h"
|
2008-02-01 18:50:11 +08:00
|
|
|
#include "tcg-op.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/log.h"
|
2014-03-29 02:42:10 +08:00
|
|
|
#include "exec/cpu_ldst.h"
|
2008-05-25 06:29:16 +08:00
|
|
|
|
2014-04-08 13:31:41 +08:00
|
|
|
#include "exec/helper-proto.h"
|
|
|
|
#include "exec/helper-gen.h"
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2014-05-30 20:12:25 +08:00
|
|
|
#include "trace-tcg.h"
|
2016-01-07 21:55:28 +08:00
|
|
|
#include "exec/log.h"
|
2014-05-30 20:12:25 +08:00
|
|
|
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
//#define DEBUG_DISPATCH 1
|
|
|
|
|
2008-07-11 01:17:54 +08:00
|
|
|
/* Fake floating point. */
|
|
|
|
#define tcg_gen_mov_f64 tcg_gen_mov_i64
|
|
|
|
#define tcg_gen_qemu_ldf64 tcg_gen_qemu_ld64
|
|
|
|
#define tcg_gen_qemu_stf64 tcg_gen_qemu_st64
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
#define DEFO32(name, offset) static TCGv QREG_##name;
|
2008-11-17 22:43:54 +08:00
|
|
|
#define DEFO64(name, offset) static TCGv_i64 QREG_##name;
|
|
|
|
#define DEFF64(name, offset) static TCGv_i64 QREG_##name;
|
2008-05-25 06:29:16 +08:00
|
|
|
#include "qregs.def"
|
|
|
|
#undef DEFO32
|
|
|
|
#undef DEFO64
|
|
|
|
#undef DEFF64
|
|
|
|
|
2013-01-18 01:51:17 +08:00
|
|
|
static TCGv_i32 cpu_halted;
|
2013-08-26 14:31:06 +08:00
|
|
|
static TCGv_i32 cpu_exception_index;
|
2013-01-18 01:51:17 +08:00
|
|
|
|
2016-02-26 00:43:15 +08:00
|
|
|
static TCGv_env cpu_env;
|
2008-05-25 06:29:16 +08:00
|
|
|
|
|
|
|
static char cpu_reg_names[3*8*3 + 5*4];
|
|
|
|
static TCGv cpu_dregs[8];
|
|
|
|
static TCGv cpu_aregs[8];
|
2008-11-17 22:43:54 +08:00
|
|
|
static TCGv_i64 cpu_fregs[8];
|
|
|
|
static TCGv_i64 cpu_macc[4];
|
2008-05-25 06:29:16 +08:00
|
|
|
|
2016-11-04 04:50:01 +08:00
|
|
|
#define REG(insn, pos) (((insn) >> (pos)) & 7)
|
2015-08-09 07:23:35 +08:00
|
|
|
#define DREG(insn, pos) cpu_dregs[REG(insn, pos)]
|
2016-11-04 04:50:01 +08:00
|
|
|
#define AREG(insn, pos) get_areg(s, REG(insn, pos))
|
2015-08-09 07:23:35 +08:00
|
|
|
#define FREG(insn, pos) cpu_fregs[REG(insn, pos)]
|
2016-11-04 04:50:01 +08:00
|
|
|
#define MACREG(acc) cpu_macc[acc]
|
|
|
|
#define QREG_SP get_areg(s, 7)
|
2008-05-25 06:29:16 +08:00
|
|
|
|
|
|
|
static TCGv NULL_QREG;
|
2008-11-17 22:43:54 +08:00
|
|
|
#define IS_NULL_QREG(t) (TCGV_EQUAL(t, NULL_QREG))
|
2008-05-25 06:29:16 +08:00
|
|
|
/* Used to distinguish stores from bad addressing modes. */
|
|
|
|
static TCGv store_dummy;
|
|
|
|
|
2012-12-18 01:19:49 +08:00
|
|
|
#include "exec/gen-icount.h"
|
2008-06-29 09:03:05 +08:00
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
void m68k_tcg_init(void)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
|
2013-09-19 03:53:09 +08:00
|
|
|
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
|
2016-06-10 01:31:41 +08:00
|
|
|
tcg_ctx.tcg_env = cpu_env;
|
2013-09-19 03:53:09 +08:00
|
|
|
|
|
|
|
#define DEFO32(name, offset) \
|
|
|
|
QREG_##name = tcg_global_mem_new_i32(cpu_env, \
|
|
|
|
offsetof(CPUM68KState, offset), #name);
|
|
|
|
#define DEFO64(name, offset) \
|
|
|
|
QREG_##name = tcg_global_mem_new_i64(cpu_env, \
|
|
|
|
offsetof(CPUM68KState, offset), #name);
|
|
|
|
#define DEFF64(name, offset) DEFO64(name, offset)
|
2008-05-25 06:29:16 +08:00
|
|
|
#include "qregs.def"
|
|
|
|
#undef DEFO32
|
|
|
|
#undef DEFO64
|
|
|
|
#undef DEFF64
|
|
|
|
|
2013-09-19 03:53:09 +08:00
|
|
|
cpu_halted = tcg_global_mem_new_i32(cpu_env,
|
2013-01-18 01:51:17 +08:00
|
|
|
-offsetof(M68kCPU, env) +
|
|
|
|
offsetof(CPUState, halted), "HALTED");
|
2013-09-19 03:53:09 +08:00
|
|
|
cpu_exception_index = tcg_global_mem_new_i32(cpu_env,
|
2013-08-26 14:31:06 +08:00
|
|
|
-offsetof(M68kCPU, env) +
|
|
|
|
offsetof(CPUState, exception_index),
|
|
|
|
"EXCEPTION");
|
2013-01-18 01:51:17 +08:00
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
p = cpu_reg_names;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
sprintf(p, "D%d", i);
|
2013-09-19 03:53:09 +08:00
|
|
|
cpu_dregs[i] = tcg_global_mem_new(cpu_env,
|
2008-05-25 06:29:16 +08:00
|
|
|
offsetof(CPUM68KState, dregs[i]), p);
|
|
|
|
p += 3;
|
|
|
|
sprintf(p, "A%d", i);
|
2013-09-19 03:53:09 +08:00
|
|
|
cpu_aregs[i] = tcg_global_mem_new(cpu_env,
|
2008-05-25 06:29:16 +08:00
|
|
|
offsetof(CPUM68KState, aregs[i]), p);
|
|
|
|
p += 3;
|
|
|
|
sprintf(p, "F%d", i);
|
2013-09-19 03:53:09 +08:00
|
|
|
cpu_fregs[i] = tcg_global_mem_new_i64(cpu_env,
|
2008-05-25 06:29:16 +08:00
|
|
|
offsetof(CPUM68KState, fregs[i]), p);
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
sprintf(p, "ACC%d", i);
|
2013-09-19 03:53:09 +08:00
|
|
|
cpu_macc[i] = tcg_global_mem_new_i64(cpu_env,
|
2008-05-25 06:29:16 +08:00
|
|
|
offsetof(CPUM68KState, macc[i]), p);
|
|
|
|
p += 5;
|
|
|
|
}
|
|
|
|
|
2013-09-19 03:53:09 +08:00
|
|
|
NULL_QREG = tcg_global_mem_new(cpu_env, -4, "NULL");
|
|
|
|
store_dummy = tcg_global_mem_new(cpu_env, -8, "NULL");
|
2008-05-25 06:29:16 +08:00
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
/* internal defines */
|
|
|
|
typedef struct DisasContext {
|
2007-05-27 05:16:48 +08:00
|
|
|
CPUM68KState *env;
|
2007-05-27 06:11:13 +08:00
|
|
|
target_ulong insn_pc; /* Start of the current instruction. */
|
2006-10-22 08:18:54 +08:00
|
|
|
target_ulong pc;
|
|
|
|
int is_jmp;
|
2015-08-09 07:44:24 +08:00
|
|
|
CCOp cc_op; /* Current CC operation */
|
2015-08-14 22:59:20 +08:00
|
|
|
int cc_op_synced;
|
2007-05-24 03:58:11 +08:00
|
|
|
int user;
|
2006-10-22 08:18:54 +08:00
|
|
|
uint32_t fpcr;
|
|
|
|
struct TranslationBlock *tb;
|
|
|
|
int singlestep_enabled;
|
2008-11-17 22:43:54 +08:00
|
|
|
TCGv_i64 mactmp;
|
|
|
|
int done_mac;
|
2016-11-04 04:50:01 +08:00
|
|
|
int writeback_mask;
|
|
|
|
TCGv writeback[8];
|
2006-10-22 08:18:54 +08:00
|
|
|
} DisasContext;
|
|
|
|
|
2016-11-04 04:50:01 +08:00
|
|
|
static TCGv get_areg(DisasContext *s, unsigned regno)
|
|
|
|
{
|
|
|
|
if (s->writeback_mask & (1 << regno)) {
|
|
|
|
return s->writeback[regno];
|
|
|
|
} else {
|
|
|
|
return cpu_aregs[regno];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delay_set_areg(DisasContext *s, unsigned regno,
|
|
|
|
TCGv val, bool give_temp)
|
|
|
|
{
|
|
|
|
if (s->writeback_mask & (1 << regno)) {
|
|
|
|
if (give_temp) {
|
|
|
|
tcg_temp_free(s->writeback[regno]);
|
|
|
|
s->writeback[regno] = val;
|
|
|
|
} else {
|
|
|
|
tcg_gen_mov_i32(s->writeback[regno], val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s->writeback_mask |= 1 << regno;
|
|
|
|
if (give_temp) {
|
|
|
|
s->writeback[regno] = val;
|
|
|
|
} else {
|
|
|
|
TCGv tmp = tcg_temp_new();
|
|
|
|
s->writeback[regno] = tmp;
|
|
|
|
tcg_gen_mov_i32(tmp, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_writebacks(DisasContext *s)
|
|
|
|
{
|
|
|
|
unsigned mask = s->writeback_mask;
|
|
|
|
if (mask) {
|
|
|
|
s->writeback_mask = 0;
|
|
|
|
do {
|
|
|
|
unsigned regno = ctz32(mask);
|
|
|
|
tcg_gen_mov_i32(cpu_aregs[regno], s->writeback[regno]);
|
|
|
|
tcg_temp_free(s->writeback[regno]);
|
|
|
|
mask &= mask - 1;
|
|
|
|
} while (mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
#define DISAS_JUMP_NEXT 4
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
#define IS_USER(s) 1
|
|
|
|
#else
|
|
|
|
#define IS_USER(s) s->user
|
|
|
|
#endif
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
/* XXX: move that elsewhere */
|
|
|
|
/* ??? Fix exceptions. */
|
|
|
|
static void *gen_throws_exception;
|
|
|
|
#define gen_last_qop NULL
|
|
|
|
|
2012-09-08 18:48:20 +08:00
|
|
|
typedef void (*disas_proc)(CPUM68KState *env, DisasContext *s, uint16_t insn);
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
#ifdef DEBUG_DISPATCH
|
2012-09-08 18:48:20 +08:00
|
|
|
#define DISAS_INSN(name) \
|
|
|
|
static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
|
|
|
|
uint16_t insn); \
|
|
|
|
static void disas_##name(CPUM68KState *env, DisasContext *s, \
|
|
|
|
uint16_t insn) \
|
|
|
|
{ \
|
|
|
|
qemu_log("Dispatch " #name "\n"); \
|
2015-12-07 02:01:47 +08:00
|
|
|
real_disas_##name(env, s, insn); \
|
2012-09-08 18:48:20 +08:00
|
|
|
} \
|
|
|
|
static void real_disas_##name(CPUM68KState *env, DisasContext *s, \
|
|
|
|
uint16_t insn)
|
2007-05-24 03:58:11 +08:00
|
|
|
#else
|
2012-09-08 18:48:20 +08:00
|
|
|
#define DISAS_INSN(name) \
|
|
|
|
static void disas_##name(CPUM68KState *env, DisasContext *s, \
|
|
|
|
uint16_t insn)
|
2007-05-24 03:58:11 +08:00
|
|
|
#endif
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2015-08-09 07:44:24 +08:00
|
|
|
static const uint8_t cc_op_live[CC_OP_NB] = {
|
2015-08-14 22:59:20 +08:00
|
|
|
[CC_OP_FLAGS] = CCF_C | CCF_V | CCF_Z | CCF_N | CCF_X,
|
2016-01-17 00:23:50 +08:00
|
|
|
[CC_OP_ADDB ... CC_OP_ADDL] = CCF_X | CCF_N | CCF_V,
|
|
|
|
[CC_OP_SUBB ... CC_OP_SUBL] = CCF_X | CCF_N | CCF_V,
|
|
|
|
[CC_OP_CMPB ... CC_OP_CMPL] = CCF_X | CCF_N | CCF_V,
|
2015-08-14 22:59:20 +08:00
|
|
|
[CC_OP_LOGIC] = CCF_X | CCF_N
|
2015-08-09 07:44:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void set_cc_op(DisasContext *s, CCOp op)
|
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
CCOp old_op = s->cc_op;
|
2015-08-09 07:44:24 +08:00
|
|
|
int dead;
|
|
|
|
|
2015-08-14 22:59:20 +08:00
|
|
|
if (old_op == op) {
|
2015-08-09 07:44:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-08-14 22:59:20 +08:00
|
|
|
s->cc_op = op;
|
|
|
|
s->cc_op_synced = 0;
|
2015-08-09 07:44:24 +08:00
|
|
|
|
2015-08-14 22:59:20 +08:00
|
|
|
/* Discard CC computation that will no longer be used.
|
|
|
|
Note that X and N are never dead. */
|
|
|
|
dead = cc_op_live[old_op] & ~cc_op_live[op];
|
|
|
|
if (dead & CCF_C) {
|
|
|
|
tcg_gen_discard_i32(QREG_CC_C);
|
2015-08-09 07:44:24 +08:00
|
|
|
}
|
2015-08-14 22:59:20 +08:00
|
|
|
if (dead & CCF_Z) {
|
|
|
|
tcg_gen_discard_i32(QREG_CC_Z);
|
2015-08-09 07:44:24 +08:00
|
|
|
}
|
2015-08-14 22:59:20 +08:00
|
|
|
if (dead & CCF_V) {
|
|
|
|
tcg_gen_discard_i32(QREG_CC_V);
|
2015-08-09 07:44:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the CPU env CC_OP state. */
|
2015-08-14 22:59:20 +08:00
|
|
|
static void update_cc_op(DisasContext *s)
|
2015-08-09 07:44:24 +08:00
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
if (!s->cc_op_synced) {
|
|
|
|
s->cc_op_synced = 1;
|
2015-08-09 07:44:24 +08:00
|
|
|
tcg_gen_movi_i32(QREG_CC_OP, s->cc_op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Generate a load from the specified address. Narrow values are
|
|
|
|
sign extended to full register width. */
|
2008-05-25 06:29:16 +08:00
|
|
|
static inline TCGv gen_load(DisasContext * s, int opsize, TCGv addr, int sign)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
|
|
|
int index = IS_USER(s);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new_i32();
|
2006-10-22 08:18:54 +08:00
|
|
|
switch(opsize) {
|
|
|
|
case OS_BYTE:
|
|
|
|
if (sign)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_qemu_ld8s(tmp, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_qemu_ld8u(tmp, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
|
|
|
if (sign)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_qemu_ld16s(tmp, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_qemu_ld16u(tmp, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
case OS_SINGLE:
|
2008-11-17 22:43:54 +08:00
|
|
|
tcg_gen_qemu_ld32u(tmp, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-12 21:24:49 +08:00
|
|
|
g_assert_not_reached();
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
gen_throws_exception = gen_last_qop;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
static inline TCGv_i64 gen_load64(DisasContext * s, TCGv addr)
|
|
|
|
{
|
|
|
|
TCGv_i64 tmp;
|
|
|
|
int index = IS_USER(s);
|
|
|
|
tmp = tcg_temp_new_i64();
|
|
|
|
tcg_gen_qemu_ldf64(tmp, addr, index);
|
|
|
|
gen_throws_exception = gen_last_qop;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Generate a store. */
|
2008-05-25 06:29:16 +08:00
|
|
|
static inline void gen_store(DisasContext *s, int opsize, TCGv addr, TCGv val)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
int index = IS_USER(s);
|
2006-10-22 08:18:54 +08:00
|
|
|
switch(opsize) {
|
|
|
|
case OS_BYTE:
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_qemu_st8(val, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_qemu_st16(val, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
case OS_SINGLE:
|
2008-11-17 22:43:54 +08:00
|
|
|
tcg_gen_qemu_st32(val, addr, index);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-12 21:24:49 +08:00
|
|
|
g_assert_not_reached();
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
gen_throws_exception = gen_last_qop;
|
|
|
|
}
|
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
static inline void gen_store64(DisasContext *s, TCGv addr, TCGv_i64 val)
|
|
|
|
{
|
|
|
|
int index = IS_USER(s);
|
|
|
|
tcg_gen_qemu_stf64(val, addr, index);
|
|
|
|
gen_throws_exception = gen_last_qop;
|
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
typedef enum {
|
|
|
|
EA_STORE,
|
|
|
|
EA_LOADU,
|
|
|
|
EA_LOADS
|
|
|
|
} ea_what;
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Generate an unsigned load if VAL is 0 a signed load if val is -1,
|
|
|
|
otherwise generate a store. */
|
2008-05-25 06:29:16 +08:00
|
|
|
static TCGv gen_ldst(DisasContext *s, int opsize, TCGv addr, TCGv val,
|
|
|
|
ea_what what)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
if (what == EA_STORE) {
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_store(s, opsize, addr, val);
|
2008-05-25 06:29:16 +08:00
|
|
|
return store_dummy;
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
return gen_load(s, opsize, addr, what == EA_LOADS);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
/* Read a 16-bit immediate constant */
|
|
|
|
static inline uint16_t read_im16(CPUM68KState *env, DisasContext *s)
|
|
|
|
{
|
|
|
|
uint16_t im;
|
|
|
|
im = cpu_lduw_code(env, s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
return im;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read an 8-bit immediate constant */
|
|
|
|
static inline uint8_t read_im8(CPUM68KState *env, DisasContext *s)
|
|
|
|
{
|
|
|
|
return read_im16(env, s);
|
|
|
|
}
|
|
|
|
|
2007-05-27 05:16:48 +08:00
|
|
|
/* Read a 32-bit immediate constant. */
|
2012-09-08 18:48:20 +08:00
|
|
|
static inline uint32_t read_im32(CPUM68KState *env, DisasContext *s)
|
2007-05-27 05:16:48 +08:00
|
|
|
{
|
|
|
|
uint32_t im;
|
2015-06-24 08:28:59 +08:00
|
|
|
im = read_im16(env, s) << 16;
|
|
|
|
im |= 0xffff & read_im16(env, s);
|
2007-05-27 05:16:48 +08:00
|
|
|
return im;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate and address index. */
|
2016-11-04 04:50:01 +08:00
|
|
|
static TCGv gen_addr_index(DisasContext *s, uint16_t ext, TCGv tmp)
|
2007-05-27 05:16:48 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv add;
|
2007-05-27 05:16:48 +08:00
|
|
|
int scale;
|
|
|
|
|
|
|
|
add = (ext & 0x8000) ? AREG(ext, 12) : DREG(ext, 12);
|
|
|
|
if ((ext & 0x800) == 0) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16s_i32(tmp, add);
|
2007-05-27 05:16:48 +08:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
scale = (ext >> 9) & 3;
|
|
|
|
if (scale != 0) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_shli_i32(tmp, add, scale);
|
2007-05-27 05:16:48 +08:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
return add;
|
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
/* Handle a base + index + displacement effective addresss.
|
|
|
|
A NULL_QREG base means pc-relative. */
|
2015-06-24 08:51:49 +08:00
|
|
|
static TCGv gen_lea_indexed(CPUM68KState *env, DisasContext *s, TCGv base)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
|
|
|
uint32_t offset;
|
|
|
|
uint16_t ext;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv add;
|
|
|
|
TCGv tmp;
|
2007-05-27 05:16:48 +08:00
|
|
|
uint32_t bd, od;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
offset = s->pc;
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2007-05-27 05:16:48 +08:00
|
|
|
|
|
|
|
if ((ext & 0x800) == 0 && !m68k_feature(s->env, M68K_FEATURE_WORD_INDEX))
|
2008-05-25 06:29:16 +08:00
|
|
|
return NULL_QREG;
|
2007-05-27 05:16:48 +08:00
|
|
|
|
2015-06-24 08:35:06 +08:00
|
|
|
if (m68k_feature(s->env, M68K_FEATURE_M68000) &&
|
|
|
|
!m68k_feature(s->env, M68K_FEATURE_SCALED_INDEX)) {
|
|
|
|
ext &= ~(3 << 9);
|
|
|
|
}
|
|
|
|
|
2007-05-27 05:16:48 +08:00
|
|
|
if (ext & 0x100) {
|
|
|
|
/* full extension word format */
|
|
|
|
if (!m68k_feature(s->env, M68K_FEATURE_EXT_FULL))
|
2008-05-25 06:29:16 +08:00
|
|
|
return NULL_QREG;
|
2007-05-27 05:16:48 +08:00
|
|
|
|
|
|
|
if ((ext & 0x30) > 0x10) {
|
|
|
|
/* base displacement */
|
|
|
|
if ((ext & 0x30) == 0x20) {
|
2015-06-24 08:28:59 +08:00
|
|
|
bd = (int16_t)read_im16(env, s);
|
2007-05-27 05:16:48 +08:00
|
|
|
} else {
|
2012-09-08 18:48:20 +08:00
|
|
|
bd = read_im32(env, s);
|
2007-05-27 05:16:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bd = 0;
|
|
|
|
}
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2007-05-27 05:16:48 +08:00
|
|
|
if ((ext & 0x44) == 0) {
|
|
|
|
/* pre-index */
|
2016-11-04 04:50:01 +08:00
|
|
|
add = gen_addr_index(s, ext, tmp);
|
2007-05-27 05:16:48 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
add = NULL_QREG;
|
2007-05-27 05:16:48 +08:00
|
|
|
}
|
|
|
|
if ((ext & 0x80) == 0) {
|
|
|
|
/* base not suppressed */
|
2008-05-25 06:29:16 +08:00
|
|
|
if (IS_NULL_QREG(base)) {
|
2011-03-25 17:36:36 +08:00
|
|
|
base = tcg_const_i32(offset + bd);
|
2007-05-27 05:16:48 +08:00
|
|
|
bd = 0;
|
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
if (!IS_NULL_QREG(add)) {
|
|
|
|
tcg_gen_add_i32(tmp, add, base);
|
2007-05-27 05:16:48 +08:00
|
|
|
add = tmp;
|
|
|
|
} else {
|
|
|
|
add = base;
|
|
|
|
}
|
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
if (!IS_NULL_QREG(add)) {
|
2007-05-27 05:16:48 +08:00
|
|
|
if (bd != 0) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(tmp, add, bd);
|
2007-05-27 05:16:48 +08:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-25 17:36:36 +08:00
|
|
|
add = tcg_const_i32(bd);
|
2007-05-27 05:16:48 +08:00
|
|
|
}
|
|
|
|
if ((ext & 3) != 0) {
|
|
|
|
/* memory indirect */
|
|
|
|
base = gen_load(s, OS_LONG, add, 0);
|
|
|
|
if ((ext & 0x44) == 4) {
|
2016-11-04 04:50:01 +08:00
|
|
|
add = gen_addr_index(s, ext, tmp);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_add_i32(tmp, add, base);
|
2007-05-27 05:16:48 +08:00
|
|
|
add = tmp;
|
|
|
|
} else {
|
|
|
|
add = base;
|
|
|
|
}
|
|
|
|
if ((ext & 3) > 1) {
|
|
|
|
/* outer displacement */
|
|
|
|
if ((ext & 3) == 2) {
|
2015-06-24 08:28:59 +08:00
|
|
|
od = (int16_t)read_im16(env, s);
|
2007-05-27 05:16:48 +08:00
|
|
|
} else {
|
2012-09-08 18:48:20 +08:00
|
|
|
od = read_im32(env, s);
|
2007-05-27 05:16:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
od = 0;
|
|
|
|
}
|
|
|
|
if (od != 0) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(tmp, add, od);
|
2007-05-27 05:16:48 +08:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2007-05-27 05:16:48 +08:00
|
|
|
/* brief extension word format */
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2016-11-04 04:50:01 +08:00
|
|
|
add = gen_addr_index(s, ext, tmp);
|
2008-05-25 06:29:16 +08:00
|
|
|
if (!IS_NULL_QREG(base)) {
|
|
|
|
tcg_gen_add_i32(tmp, add, base);
|
2007-05-27 05:16:48 +08:00
|
|
|
if ((int8_t)ext)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(tmp, tmp, (int8_t)ext);
|
2007-05-27 05:16:48 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(tmp, add, offset + (int8_t)ext);
|
2007-05-27 05:16:48 +08:00
|
|
|
}
|
|
|
|
add = tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2007-05-27 05:16:48 +08:00
|
|
|
return add;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2016-01-17 00:23:50 +08:00
|
|
|
/* Sign or zero extend a value. */
|
|
|
|
|
|
|
|
static inline void gen_ext(TCGv res, TCGv val, int opsize, int sign)
|
|
|
|
{
|
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE:
|
|
|
|
if (sign) {
|
|
|
|
tcg_gen_ext8s_i32(res, val);
|
|
|
|
} else {
|
|
|
|
tcg_gen_ext8u_i32(res, val);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OS_WORD:
|
|
|
|
if (sign) {
|
|
|
|
tcg_gen_ext16s_i32(res, val);
|
|
|
|
} else {
|
|
|
|
tcg_gen_ext16u_i32(res, val);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
tcg_gen_mov_i32(res, val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Evaluate all the CC flags. */
|
2015-08-09 07:44:24 +08:00
|
|
|
|
2015-08-14 22:59:20 +08:00
|
|
|
static void gen_flush_flags(DisasContext *s)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2015-08-14 22:59:24 +08:00
|
|
|
TCGv t0, t1;
|
2015-08-14 22:59:20 +08:00
|
|
|
|
|
|
|
switch (s->cc_op) {
|
|
|
|
case CC_OP_FLAGS:
|
2006-10-22 08:18:54 +08:00
|
|
|
return;
|
2015-08-14 22:59:24 +08:00
|
|
|
|
2016-01-17 00:23:50 +08:00
|
|
|
case CC_OP_ADDB:
|
|
|
|
case CC_OP_ADDW:
|
|
|
|
case CC_OP_ADDL:
|
2015-08-14 22:59:24 +08:00
|
|
|
tcg_gen_mov_i32(QREG_CC_C, QREG_CC_X);
|
|
|
|
tcg_gen_mov_i32(QREG_CC_Z, QREG_CC_N);
|
|
|
|
/* Compute signed overflow for addition. */
|
|
|
|
t0 = tcg_temp_new();
|
|
|
|
t1 = tcg_temp_new();
|
|
|
|
tcg_gen_sub_i32(t0, QREG_CC_N, QREG_CC_V);
|
2016-01-17 00:23:50 +08:00
|
|
|
gen_ext(t0, t0, s->cc_op - CC_OP_ADDB, 1);
|
2015-08-14 22:59:24 +08:00
|
|
|
tcg_gen_xor_i32(t1, QREG_CC_N, QREG_CC_V);
|
|
|
|
tcg_gen_xor_i32(QREG_CC_V, QREG_CC_V, t0);
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_gen_andc_i32(QREG_CC_V, t1, QREG_CC_V);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
break;
|
|
|
|
|
2016-01-17 00:23:50 +08:00
|
|
|
case CC_OP_SUBB:
|
|
|
|
case CC_OP_SUBW:
|
|
|
|
case CC_OP_SUBL:
|
2015-08-14 22:59:24 +08:00
|
|
|
tcg_gen_mov_i32(QREG_CC_C, QREG_CC_X);
|
|
|
|
tcg_gen_mov_i32(QREG_CC_Z, QREG_CC_N);
|
|
|
|
/* Compute signed overflow for subtraction. */
|
|
|
|
t0 = tcg_temp_new();
|
|
|
|
t1 = tcg_temp_new();
|
|
|
|
tcg_gen_add_i32(t0, QREG_CC_N, QREG_CC_V);
|
2016-01-17 00:23:50 +08:00
|
|
|
gen_ext(t0, t0, s->cc_op - CC_OP_SUBB, 1);
|
2015-08-14 22:59:24 +08:00
|
|
|
tcg_gen_xor_i32(t1, QREG_CC_N, QREG_CC_V);
|
|
|
|
tcg_gen_xor_i32(QREG_CC_V, QREG_CC_V, t0);
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_gen_and_i32(QREG_CC_V, QREG_CC_V, t1);
|
|
|
|
tcg_temp_free(t1);
|
|
|
|
break;
|
|
|
|
|
2016-01-17 00:23:50 +08:00
|
|
|
case CC_OP_CMPB:
|
|
|
|
case CC_OP_CMPW:
|
|
|
|
case CC_OP_CMPL:
|
2015-08-14 22:59:24 +08:00
|
|
|
tcg_gen_setcond_i32(TCG_COND_LTU, QREG_CC_C, QREG_CC_N, QREG_CC_V);
|
|
|
|
tcg_gen_sub_i32(QREG_CC_Z, QREG_CC_N, QREG_CC_V);
|
2016-01-17 00:23:50 +08:00
|
|
|
gen_ext(QREG_CC_Z, QREG_CC_Z, s->cc_op - CC_OP_CMPB, 1);
|
2015-08-14 22:59:24 +08:00
|
|
|
/* Compute signed overflow for subtraction. */
|
|
|
|
t0 = tcg_temp_new();
|
|
|
|
tcg_gen_xor_i32(t0, QREG_CC_Z, QREG_CC_N);
|
|
|
|
tcg_gen_xor_i32(QREG_CC_V, QREG_CC_V, QREG_CC_N);
|
|
|
|
tcg_gen_and_i32(QREG_CC_V, QREG_CC_V, t0);
|
|
|
|
tcg_temp_free(t0);
|
|
|
|
tcg_gen_mov_i32(QREG_CC_N, QREG_CC_Z);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CC_OP_LOGIC:
|
|
|
|
tcg_gen_mov_i32(QREG_CC_Z, QREG_CC_N);
|
|
|
|
tcg_gen_movi_i32(QREG_CC_C, 0);
|
|
|
|
tcg_gen_movi_i32(QREG_CC_V, 0);
|
|
|
|
break;
|
|
|
|
|
2015-08-14 22:59:20 +08:00
|
|
|
case CC_OP_DYNAMIC:
|
|
|
|
gen_helper_flush_flags(cpu_env, QREG_CC_OP);
|
|
|
|
break;
|
2015-08-14 22:59:24 +08:00
|
|
|
|
2015-08-14 22:59:20 +08:00
|
|
|
default:
|
2015-08-14 22:59:24 +08:00
|
|
|
t0 = tcg_const_i32(s->cc_op);
|
|
|
|
gen_helper_flush_flags(cpu_env, t0);
|
|
|
|
tcg_temp_free(t0);
|
2015-08-14 22:59:20 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that flush_flags also assigned to env->cc_op. */
|
|
|
|
s->cc_op = CC_OP_FLAGS;
|
|
|
|
s->cc_op_synced = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-17 00:23:50 +08:00
|
|
|
static inline TCGv gen_extend(TCGv val, int opsize, int sign)
|
2015-08-14 22:59:20 +08:00
|
|
|
{
|
|
|
|
TCGv tmp;
|
|
|
|
|
|
|
|
if (opsize == OS_LONG) {
|
|
|
|
tmp = val;
|
|
|
|
} else {
|
|
|
|
tmp = tcg_temp_new();
|
|
|
|
gen_ext(tmp, val, opsize, sign);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
2015-08-09 08:41:40 +08:00
|
|
|
|
|
|
|
static void gen_logic_cc(DisasContext *s, TCGv val, int opsize)
|
2008-05-25 06:29:16 +08:00
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
gen_ext(QREG_CC_N, val, opsize, 1);
|
|
|
|
set_cc_op(s, CC_OP_LOGIC);
|
2008-05-25 06:29:16 +08:00
|
|
|
}
|
|
|
|
|
2016-01-17 21:34:09 +08:00
|
|
|
static void gen_update_cc_cmp(DisasContext *s, TCGv dest, TCGv src, int opsize)
|
|
|
|
{
|
|
|
|
tcg_gen_mov_i32(QREG_CC_N, dest);
|
|
|
|
tcg_gen_mov_i32(QREG_CC_V, src);
|
|
|
|
set_cc_op(s, CC_OP_CMPB + opsize);
|
|
|
|
}
|
|
|
|
|
2016-01-17 00:23:50 +08:00
|
|
|
static void gen_update_cc_add(TCGv dest, TCGv src, int opsize)
|
2008-05-25 06:29:16 +08:00
|
|
|
{
|
2016-01-17 00:23:50 +08:00
|
|
|
gen_ext(QREG_CC_N, dest, opsize, 1);
|
2015-08-14 22:59:20 +08:00
|
|
|
tcg_gen_mov_i32(QREG_CC_V, src);
|
2008-05-25 06:29:16 +08:00
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
static inline int opsize_bytes(int opsize)
|
|
|
|
{
|
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE: return 1;
|
|
|
|
case OS_WORD: return 2;
|
|
|
|
case OS_LONG: return 4;
|
|
|
|
case OS_SINGLE: return 4;
|
|
|
|
case OS_DOUBLE: return 8;
|
2015-08-09 07:12:46 +08:00
|
|
|
case OS_EXTENDED: return 12;
|
|
|
|
case OS_PACKED: return 12;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int insn_opsize(int insn)
|
|
|
|
{
|
|
|
|
switch ((insn >> 6) & 3) {
|
|
|
|
case 0: return OS_BYTE;
|
|
|
|
case 1: return OS_WORD;
|
|
|
|
case 2: return OS_LONG;
|
2006-10-22 08:18:54 +08:00
|
|
|
default:
|
2014-03-12 21:24:49 +08:00
|
|
|
g_assert_not_reached();
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign value to a register. If the width is less than the register width
|
|
|
|
only the low part of the register is set. */
|
2008-05-25 06:29:16 +08:00
|
|
|
static void gen_partset_reg(int opsize, TCGv reg, TCGv val)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE:
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(reg, reg, 0xffffff00);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext8u_i32(tmp, val);
|
|
|
|
tcg_gen_or_i32(reg, reg, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(reg, reg, 0xffff0000);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16u_i32(tmp, val);
|
|
|
|
tcg_gen_or_i32(reg, reg, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
case OS_SINGLE:
|
2008-11-17 22:43:54 +08:00
|
|
|
tcg_gen_mov_i32(reg, val);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-12 21:24:49 +08:00
|
|
|
g_assert_not_reached();
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate code for an "effective address". Does not adjust the base
|
2008-12-01 00:25:37 +08:00
|
|
|
register for autoincrement addressing modes. */
|
2016-11-04 04:50:02 +08:00
|
|
|
static TCGv gen_lea_mode(CPUM68KState *env, DisasContext *s,
|
|
|
|
int mode, int reg0, int opsize)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
uint16_t ext;
|
|
|
|
uint32_t offset;
|
|
|
|
|
2016-11-04 04:50:02 +08:00
|
|
|
switch (mode) {
|
2006-10-22 08:18:54 +08:00
|
|
|
case 0: /* Data register direct. */
|
|
|
|
case 1: /* Address register direct. */
|
2008-05-25 06:29:16 +08:00
|
|
|
return NULL_QREG;
|
2006-10-22 08:18:54 +08:00
|
|
|
case 2: /* Indirect register */
|
|
|
|
case 3: /* Indirect postincrement. */
|
2016-11-04 04:50:02 +08:00
|
|
|
return get_areg(s, reg0);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 4: /* Indirect predecrememnt. */
|
2016-11-04 04:50:02 +08:00
|
|
|
reg = get_areg(s, reg0);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_subi_i32(tmp, reg, opsize_bytes(opsize));
|
2006-10-22 08:18:54 +08:00
|
|
|
return tmp;
|
|
|
|
case 5: /* Indirect displacement. */
|
2016-11-04 04:50:02 +08:00
|
|
|
reg = get_areg(s, reg0);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(tmp, reg, (int16_t)ext);
|
2006-10-22 08:18:54 +08:00
|
|
|
return tmp;
|
|
|
|
case 6: /* Indirect index + displacement. */
|
2016-11-04 04:50:02 +08:00
|
|
|
reg = get_areg(s, reg0);
|
2015-06-24 08:51:49 +08:00
|
|
|
return gen_lea_indexed(env, s, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 7: /* Other */
|
2016-11-04 04:50:02 +08:00
|
|
|
switch (reg0) {
|
2006-10-22 08:18:54 +08:00
|
|
|
case 0: /* Absolute short. */
|
2015-06-24 08:28:59 +08:00
|
|
|
offset = (int16_t)read_im16(env, s);
|
2011-03-25 17:36:36 +08:00
|
|
|
return tcg_const_i32(offset);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 1: /* Absolute long. */
|
2012-09-08 18:48:20 +08:00
|
|
|
offset = read_im32(env, s);
|
2011-03-25 17:36:36 +08:00
|
|
|
return tcg_const_i32(offset);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 2: /* pc displacement */
|
|
|
|
offset = s->pc;
|
2015-06-24 08:28:59 +08:00
|
|
|
offset += (int16_t)read_im16(env, s);
|
2011-03-25 17:36:36 +08:00
|
|
|
return tcg_const_i32(offset);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 3: /* pc index+displacement. */
|
2015-06-24 08:51:49 +08:00
|
|
|
return gen_lea_indexed(env, s, NULL_QREG);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 4: /* Immediate. */
|
|
|
|
default:
|
2008-05-25 06:29:16 +08:00
|
|
|
return NULL_QREG;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Should never happen. */
|
2008-05-25 06:29:16 +08:00
|
|
|
return NULL_QREG;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-04 04:50:02 +08:00
|
|
|
static TCGv gen_lea(CPUM68KState *env, DisasContext *s, uint16_t insn,
|
|
|
|
int opsize)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2016-11-04 04:50:02 +08:00
|
|
|
int mode = extract32(insn, 3, 3);
|
|
|
|
int reg0 = REG(insn, 0);
|
|
|
|
return gen_lea_mode(env, s, mode, reg0, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-04 04:50:02 +08:00
|
|
|
/* Generate code to load/store a value from/into an EA. If WHAT > 0 this is
|
2006-10-22 08:18:54 +08:00
|
|
|
a write otherwise it is a read (0 == sign extend, -1 == zero extend).
|
|
|
|
ADDRP is non-null for readwrite operands. */
|
2016-11-04 04:50:02 +08:00
|
|
|
static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0,
|
|
|
|
int opsize, TCGv val, TCGv *addrp, ea_what what)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2016-11-04 04:50:02 +08:00
|
|
|
TCGv reg, tmp, result;
|
|
|
|
int32_t offset;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-11-04 04:50:02 +08:00
|
|
|
switch (mode) {
|
2006-10-22 08:18:54 +08:00
|
|
|
case 0: /* Data register direct. */
|
2016-11-04 04:50:02 +08:00
|
|
|
reg = cpu_dregs[reg0];
|
2008-05-25 06:29:16 +08:00
|
|
|
if (what == EA_STORE) {
|
2006-10-22 08:18:54 +08:00
|
|
|
gen_partset_reg(opsize, reg, val);
|
2008-05-25 06:29:16 +08:00
|
|
|
return store_dummy;
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
return gen_extend(reg, opsize, what == EA_LOADS);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
case 1: /* Address register direct. */
|
2016-11-04 04:50:02 +08:00
|
|
|
reg = get_areg(s, reg0);
|
2008-05-25 06:29:16 +08:00
|
|
|
if (what == EA_STORE) {
|
|
|
|
tcg_gen_mov_i32(reg, val);
|
|
|
|
return store_dummy;
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
return gen_extend(reg, opsize, what == EA_LOADS);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
case 2: /* Indirect register */
|
2016-11-04 04:50:02 +08:00
|
|
|
reg = get_areg(s, reg0);
|
2008-05-25 06:29:16 +08:00
|
|
|
return gen_ldst(s, opsize, reg, val, what);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 3: /* Indirect postincrement. */
|
2016-11-04 04:50:02 +08:00
|
|
|
reg = get_areg(s, reg0);
|
2008-05-25 06:29:16 +08:00
|
|
|
result = gen_ldst(s, opsize, reg, val, what);
|
2016-11-04 04:50:01 +08:00
|
|
|
if (what == EA_STORE || !addrp) {
|
|
|
|
TCGv tmp = tcg_temp_new();
|
|
|
|
tcg_gen_addi_i32(tmp, reg, opsize_bytes(opsize));
|
2016-11-04 04:50:02 +08:00
|
|
|
delay_set_areg(s, reg0, tmp, true);
|
2016-11-04 04:50:01 +08:00
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
return result;
|
|
|
|
case 4: /* Indirect predecrememnt. */
|
2016-11-04 04:50:02 +08:00
|
|
|
if (addrp && what == EA_STORE) {
|
|
|
|
tmp = *addrp;
|
|
|
|
} else {
|
|
|
|
tmp = gen_lea_mode(env, s, mode, reg0, opsize);
|
|
|
|
if (IS_NULL_QREG(tmp)) {
|
|
|
|
return tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-11-04 04:50:02 +08:00
|
|
|
if (addrp) {
|
|
|
|
*addrp = tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-04 04:50:02 +08:00
|
|
|
result = gen_ldst(s, opsize, tmp, val, what);
|
|
|
|
if (what == EA_STORE || !addrp) {
|
|
|
|
delay_set_areg(s, reg0, tmp, false);
|
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
return result;
|
|
|
|
case 5: /* Indirect displacement. */
|
|
|
|
case 6: /* Indirect index + displacement. */
|
2016-11-04 04:50:02 +08:00
|
|
|
do_indirect:
|
|
|
|
if (addrp && what == EA_STORE) {
|
|
|
|
tmp = *addrp;
|
|
|
|
} else {
|
|
|
|
tmp = gen_lea_mode(env, s, mode, reg0, opsize);
|
|
|
|
if (IS_NULL_QREG(tmp)) {
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
if (addrp) {
|
|
|
|
*addrp = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return gen_ldst(s, opsize, tmp, val, what);
|
2006-10-22 08:18:54 +08:00
|
|
|
case 7: /* Other */
|
2016-11-04 04:50:02 +08:00
|
|
|
switch (reg0) {
|
2006-10-22 08:18:54 +08:00
|
|
|
case 0: /* Absolute short. */
|
|
|
|
case 1: /* Absolute long. */
|
|
|
|
case 2: /* pc displacement */
|
|
|
|
case 3: /* pc index+displacement. */
|
2016-11-04 04:50:02 +08:00
|
|
|
goto do_indirect;
|
2006-10-22 08:18:54 +08:00
|
|
|
case 4: /* Immediate. */
|
|
|
|
/* Sign extend values for consistency. */
|
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE:
|
2012-09-02 15:27:38 +08:00
|
|
|
if (what == EA_LOADS) {
|
2015-06-24 08:28:59 +08:00
|
|
|
offset = (int8_t)read_im8(env, s);
|
2012-09-02 15:27:38 +08:00
|
|
|
} else {
|
2015-06-24 08:28:59 +08:00
|
|
|
offset = read_im8(env, s);
|
2012-09-02 15:27:38 +08:00
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
2012-09-02 15:27:38 +08:00
|
|
|
if (what == EA_LOADS) {
|
2015-06-24 08:28:59 +08:00
|
|
|
offset = (int16_t)read_im16(env, s);
|
2012-09-02 15:27:38 +08:00
|
|
|
} else {
|
2015-06-24 08:28:59 +08:00
|
|
|
offset = read_im16(env, s);
|
2012-09-02 15:27:38 +08:00
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
2012-09-08 18:48:20 +08:00
|
|
|
offset = read_im32(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-12 21:24:49 +08:00
|
|
|
g_assert_not_reached();
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
return tcg_const_i32(offset);
|
2006-10-22 08:18:54 +08:00
|
|
|
default:
|
2008-05-25 06:29:16 +08:00
|
|
|
return NULL_QREG;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Should never happen. */
|
2008-05-25 06:29:16 +08:00
|
|
|
return NULL_QREG;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-04 04:50:02 +08:00
|
|
|
static TCGv gen_ea(CPUM68KState *env, DisasContext *s, uint16_t insn,
|
|
|
|
int opsize, TCGv val, TCGv *addrp, ea_what what)
|
|
|
|
{
|
|
|
|
int mode = extract32(insn, 3, 3);
|
|
|
|
int reg0 = REG(insn, 0);
|
|
|
|
return gen_ea_mode(env, s, mode, reg0, opsize, val, addrp, what);
|
|
|
|
}
|
|
|
|
|
2015-08-14 22:59:21 +08:00
|
|
|
typedef struct {
|
|
|
|
TCGCond tcond;
|
|
|
|
bool g1;
|
|
|
|
bool g2;
|
|
|
|
TCGv v1;
|
|
|
|
TCGv v2;
|
|
|
|
} DisasCompare;
|
|
|
|
|
|
|
|
static void gen_cc_cond(DisasCompare *c, DisasContext *s, int cond)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
TCGv tmp, tmp2;
|
|
|
|
TCGCond tcond;
|
2015-08-14 22:59:23 +08:00
|
|
|
CCOp op = s->cc_op;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2015-08-14 22:59:23 +08:00
|
|
|
/* The CC_OP_CMP form can handle most normal comparisons directly. */
|
2016-01-17 00:23:50 +08:00
|
|
|
if (op == CC_OP_CMPB || op == CC_OP_CMPW || op == CC_OP_CMPL) {
|
2015-08-14 22:59:23 +08:00
|
|
|
c->g1 = c->g2 = 1;
|
|
|
|
c->v1 = QREG_CC_N;
|
|
|
|
c->v2 = QREG_CC_V;
|
|
|
|
switch (cond) {
|
|
|
|
case 2: /* HI */
|
|
|
|
case 3: /* LS */
|
|
|
|
tcond = TCG_COND_LEU;
|
|
|
|
goto done;
|
|
|
|
case 4: /* CC */
|
|
|
|
case 5: /* CS */
|
|
|
|
tcond = TCG_COND_LTU;
|
|
|
|
goto done;
|
|
|
|
case 6: /* NE */
|
|
|
|
case 7: /* EQ */
|
|
|
|
tcond = TCG_COND_EQ;
|
|
|
|
goto done;
|
|
|
|
case 10: /* PL */
|
|
|
|
case 11: /* MI */
|
|
|
|
c->g1 = c->g2 = 0;
|
|
|
|
c->v2 = tcg_const_i32(0);
|
|
|
|
c->v1 = tmp = tcg_temp_new();
|
|
|
|
tcg_gen_sub_i32(tmp, QREG_CC_N, QREG_CC_V);
|
2016-01-17 00:23:50 +08:00
|
|
|
gen_ext(tmp, tmp, op - CC_OP_CMPB, 1);
|
2015-08-14 22:59:23 +08:00
|
|
|
/* fallthru */
|
|
|
|
case 12: /* GE */
|
|
|
|
case 13: /* LT */
|
|
|
|
tcond = TCG_COND_LT;
|
|
|
|
goto done;
|
|
|
|
case 14: /* GT */
|
|
|
|
case 15: /* LE */
|
|
|
|
tcond = TCG_COND_LE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2015-08-14 22:59:21 +08:00
|
|
|
|
|
|
|
c->g1 = 1;
|
|
|
|
c->g2 = 0;
|
|
|
|
c->v2 = tcg_const_i32(0);
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
switch (cond) {
|
|
|
|
case 0: /* T */
|
|
|
|
case 1: /* F */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = c->v2;
|
|
|
|
tcond = TCG_COND_NEVER;
|
2015-08-14 22:59:23 +08:00
|
|
|
goto done;
|
|
|
|
case 14: /* GT (!(Z || (N ^ V))) */
|
|
|
|
case 15: /* LE (Z || (N ^ V)) */
|
|
|
|
/* Logic operations clear V, which simplifies LE to (Z || N),
|
|
|
|
and since Z and N are co-located, this becomes a normal
|
|
|
|
comparison vs N. */
|
|
|
|
if (op == CC_OP_LOGIC) {
|
|
|
|
c->v1 = QREG_CC_N;
|
|
|
|
tcond = TCG_COND_LE;
|
|
|
|
goto done;
|
|
|
|
}
|
2015-08-14 22:59:21 +08:00
|
|
|
break;
|
2015-08-14 22:59:23 +08:00
|
|
|
case 12: /* GE (!(N ^ V)) */
|
|
|
|
case 13: /* LT (N ^ V) */
|
|
|
|
/* Logic operations clear V, which simplifies this to N. */
|
|
|
|
if (op != CC_OP_LOGIC) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthru */
|
|
|
|
case 10: /* PL (!N) */
|
|
|
|
case 11: /* MI (N) */
|
|
|
|
/* Several cases represent N normally. */
|
2016-01-17 00:23:50 +08:00
|
|
|
if (op == CC_OP_ADDB || op == CC_OP_ADDW || op == CC_OP_ADDL ||
|
|
|
|
op == CC_OP_SUBB || op == CC_OP_SUBW || op == CC_OP_SUBL ||
|
|
|
|
op == CC_OP_LOGIC) {
|
2015-08-14 22:59:23 +08:00
|
|
|
c->v1 = QREG_CC_N;
|
|
|
|
tcond = TCG_COND_LT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6: /* NE (!Z) */
|
|
|
|
case 7: /* EQ (Z) */
|
|
|
|
/* Some cases fold Z into N. */
|
2016-01-17 00:23:50 +08:00
|
|
|
if (op == CC_OP_ADDB || op == CC_OP_ADDW || op == CC_OP_ADDL ||
|
|
|
|
op == CC_OP_SUBB || op == CC_OP_SUBW || op == CC_OP_SUBL ||
|
|
|
|
op == CC_OP_LOGIC) {
|
2015-08-14 22:59:23 +08:00
|
|
|
tcond = TCG_COND_EQ;
|
|
|
|
c->v1 = QREG_CC_N;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: /* CC (!C) */
|
|
|
|
case 5: /* CS (C) */
|
|
|
|
/* Some cases fold C into X. */
|
2016-01-17 00:23:50 +08:00
|
|
|
if (op == CC_OP_ADDB || op == CC_OP_ADDW || op == CC_OP_ADDL ||
|
|
|
|
op == CC_OP_ADDB || op == CC_OP_ADDW || op == CC_OP_ADDL) {
|
2015-08-14 22:59:23 +08:00
|
|
|
tcond = TCG_COND_NE;
|
|
|
|
c->v1 = QREG_CC_X;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/* fallthru */
|
|
|
|
case 8: /* VC (!V) */
|
|
|
|
case 9: /* VS (V) */
|
|
|
|
/* Logic operations clear V and C. */
|
|
|
|
if (op == CC_OP_LOGIC) {
|
|
|
|
tcond = TCG_COND_NEVER;
|
|
|
|
c->v1 = c->v2;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, flush flag state to CC_OP_FLAGS. */
|
|
|
|
gen_flush_flags(s);
|
|
|
|
|
|
|
|
switch (cond) {
|
|
|
|
case 0: /* T */
|
|
|
|
case 1: /* F */
|
|
|
|
default:
|
|
|
|
/* Invalid, or handled above. */
|
|
|
|
abort();
|
2015-08-14 22:59:20 +08:00
|
|
|
case 2: /* HI (!C && !Z) -> !(C || Z)*/
|
2006-10-22 08:18:54 +08:00
|
|
|
case 3: /* LS (C || Z) */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = tmp = tcg_temp_new();
|
|
|
|
c->g1 = 0;
|
|
|
|
tcg_gen_setcond_i32(TCG_COND_EQ, tmp, QREG_CC_Z, c->v2);
|
2015-08-14 22:59:20 +08:00
|
|
|
tcg_gen_or_i32(tmp, tmp, QREG_CC_C);
|
2015-08-14 22:59:21 +08:00
|
|
|
tcond = TCG_COND_NE;
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 4: /* CC (!C) */
|
|
|
|
case 5: /* CS (C) */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = QREG_CC_C;
|
|
|
|
tcond = TCG_COND_NE;
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 6: /* NE (!Z) */
|
|
|
|
case 7: /* EQ (Z) */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = QREG_CC_Z;
|
|
|
|
tcond = TCG_COND_EQ;
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 8: /* VC (!V) */
|
|
|
|
case 9: /* VS (V) */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = QREG_CC_V;
|
|
|
|
tcond = TCG_COND_LT;
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 10: /* PL (!N) */
|
|
|
|
case 11: /* MI (N) */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = QREG_CC_N;
|
|
|
|
tcond = TCG_COND_LT;
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 12: /* GE (!(N ^ V)) */
|
|
|
|
case 13: /* LT (N ^ V) */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = tmp = tcg_temp_new();
|
|
|
|
c->g1 = 0;
|
2015-08-14 22:59:20 +08:00
|
|
|
tcg_gen_xor_i32(tmp, QREG_CC_N, QREG_CC_V);
|
2015-08-14 22:59:21 +08:00
|
|
|
tcond = TCG_COND_LT;
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 14: /* GT (!(Z || (N ^ V))) */
|
|
|
|
case 15: /* LE (Z || (N ^ V)) */
|
2015-08-14 22:59:21 +08:00
|
|
|
c->v1 = tmp = tcg_temp_new();
|
|
|
|
c->g1 = 0;
|
|
|
|
tcg_gen_setcond_i32(TCG_COND_EQ, tmp, QREG_CC_Z, c->v2);
|
2015-08-14 22:59:20 +08:00
|
|
|
tcg_gen_neg_i32(tmp, tmp);
|
|
|
|
tmp2 = tcg_temp_new();
|
|
|
|
tcg_gen_xor_i32(tmp2, QREG_CC_N, QREG_CC_V);
|
|
|
|
tcg_gen_or_i32(tmp, tmp, tmp2);
|
2015-08-14 22:59:21 +08:00
|
|
|
tcg_temp_free(tmp2);
|
|
|
|
tcond = TCG_COND_LT;
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-08-14 22:59:23 +08:00
|
|
|
|
|
|
|
done:
|
2015-08-14 22:59:21 +08:00
|
|
|
if ((cond & 1) == 0) {
|
|
|
|
tcond = tcg_invert_cond(tcond);
|
|
|
|
}
|
|
|
|
c->tcond = tcond;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_cond(DisasCompare *c)
|
|
|
|
{
|
|
|
|
if (!c->g1) {
|
|
|
|
tcg_temp_free(c->v1);
|
|
|
|
}
|
|
|
|
if (!c->g2) {
|
|
|
|
tcg_temp_free(c->v2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gen_jmpcc(DisasContext *s, int cond, TCGLabel *l1)
|
|
|
|
{
|
|
|
|
DisasCompare c;
|
|
|
|
|
|
|
|
gen_cc_cond(&c, s, cond);
|
|
|
|
update_cc_op(s);
|
|
|
|
tcg_gen_brcond_i32(c.tcond, c.v1, c.v2, l1);
|
|
|
|
free_cond(&c);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
/* Force a TB lookup after an instruction that changes the CPU state. */
|
|
|
|
static void gen_lookup_tb(DisasContext *s)
|
|
|
|
{
|
2015-08-09 07:44:24 +08:00
|
|
|
update_cc_op(s);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_movi_i32(QREG_PC, s->pc);
|
2007-05-24 03:58:11 +08:00
|
|
|
s->is_jmp = DISAS_UPDATE;
|
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
/* Generate a jump to an immediate address. */
|
|
|
|
static void gen_jmp_im(DisasContext *s, uint32_t dest)
|
|
|
|
{
|
2015-08-09 07:44:24 +08:00
|
|
|
update_cc_op(s);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_movi_i32(QREG_PC, dest);
|
|
|
|
s->is_jmp = DISAS_JUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate a jump to the address in qreg DEST. */
|
|
|
|
static void gen_jmp(DisasContext *s, TCGv dest)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2015-08-09 07:44:24 +08:00
|
|
|
update_cc_op(s);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(QREG_PC, dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
s->is_jmp = DISAS_JUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gen_exception(DisasContext *s, uint32_t where, int nr)
|
|
|
|
{
|
2015-08-09 07:44:24 +08:00
|
|
|
update_cc_op(s);
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_jmp_im(s, where);
|
2012-09-02 15:27:38 +08:00
|
|
|
gen_helper_raise_exception(cpu_env, tcg_const_i32(nr));
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2007-05-27 06:11:13 +08:00
|
|
|
static inline void gen_addr_fault(DisasContext *s)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->insn_pc, EXCP_ADDRESS);
|
|
|
|
}
|
|
|
|
|
2012-09-08 18:48:20 +08:00
|
|
|
#define SRC_EA(env, result, opsize, op_sign, addrp) do { \
|
|
|
|
result = gen_ea(env, s, insn, opsize, NULL_QREG, addrp, \
|
|
|
|
op_sign ? EA_LOADS : EA_LOADU); \
|
|
|
|
if (IS_NULL_QREG(result)) { \
|
|
|
|
gen_addr_fault(s); \
|
|
|
|
return; \
|
|
|
|
} \
|
2007-05-27 06:11:13 +08:00
|
|
|
} while (0)
|
|
|
|
|
2012-09-08 18:48:20 +08:00
|
|
|
#define DEST_EA(env, insn, opsize, val, addrp) do { \
|
|
|
|
TCGv ea_result = gen_ea(env, s, insn, opsize, val, addrp, EA_STORE); \
|
|
|
|
if (IS_NULL_QREG(ea_result)) { \
|
|
|
|
gen_addr_fault(s); \
|
|
|
|
return; \
|
|
|
|
} \
|
2007-05-27 06:11:13 +08:00
|
|
|
} while (0)
|
|
|
|
|
2016-04-09 06:00:23 +08:00
|
|
|
static inline bool use_goto_tb(DisasContext *s, uint32_t dest)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
return (s->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) ||
|
|
|
|
(s->insn_pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK);
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Generate a jump to an immediate address. */
|
|
|
|
static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest)
|
|
|
|
{
|
2008-07-04 01:57:36 +08:00
|
|
|
if (unlikely(s->singlestep_enabled)) {
|
2006-10-22 08:18:54 +08:00
|
|
|
gen_exception(s, dest, EXCP_DEBUG);
|
2016-04-09 06:00:23 +08:00
|
|
|
} else if (use_goto_tb(s, dest)) {
|
2008-02-01 18:50:11 +08:00
|
|
|
tcg_gen_goto_tb(n);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_movi_i32(QREG_PC, dest);
|
2016-04-09 06:00:23 +08:00
|
|
|
tcg_gen_exit_tb((uintptr_t)s->tb + n);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_jmp_im(s, dest);
|
2008-02-01 18:50:11 +08:00
|
|
|
tcg_gen_exit_tb(0);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
s->is_jmp = DISAS_TB_JUMP;
|
|
|
|
}
|
|
|
|
|
2016-01-11 06:53:20 +08:00
|
|
|
DISAS_INSN(scc)
|
|
|
|
{
|
|
|
|
DisasCompare c;
|
|
|
|
int cond;
|
|
|
|
TCGv tmp;
|
|
|
|
|
|
|
|
cond = (insn >> 8) & 0xf;
|
|
|
|
gen_cc_cond(&c, s, cond);
|
|
|
|
|
|
|
|
tmp = tcg_temp_new();
|
|
|
|
tcg_gen_setcond_i32(c.tcond, tmp, c.v1, c.v2);
|
|
|
|
free_cond(&c);
|
|
|
|
|
|
|
|
tcg_gen_neg_i32(tmp, tmp);
|
|
|
|
DEST_EA(env, insn, OS_BYTE, tmp, NULL);
|
|
|
|
tcg_temp_free(tmp);
|
|
|
|
}
|
|
|
|
|
2016-01-11 06:53:20 +08:00
|
|
|
DISAS_INSN(dbcc)
|
|
|
|
{
|
|
|
|
TCGLabel *l1;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
|
|
|
int16_t offset;
|
|
|
|
uint32_t base;
|
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
|
|
|
base = s->pc;
|
|
|
|
offset = (int16_t)read_im16(env, s);
|
|
|
|
l1 = gen_new_label();
|
|
|
|
gen_jmpcc(s, (insn >> 8) & 0xf, l1);
|
|
|
|
|
|
|
|
tmp = tcg_temp_new();
|
|
|
|
tcg_gen_ext16s_i32(tmp, reg);
|
|
|
|
tcg_gen_addi_i32(tmp, tmp, -1);
|
|
|
|
gen_partset_reg(OS_WORD, reg, tmp);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, -1, l1);
|
|
|
|
gen_jmp_tb(s, 1, base + offset);
|
|
|
|
gen_set_label(l1);
|
|
|
|
gen_jmp_tb(s, 0, s->pc);
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
DISAS_INSN(undef_mac)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_LINEA);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(undef_fpu)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_LINEF);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(undef)
|
|
|
|
{
|
2013-09-03 23:38:47 +08:00
|
|
|
M68kCPU *cpu = m68k_env_get_cpu(env);
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
gen_exception(s, s->pc - 2, EXCP_UNSUPPORTED);
|
2013-09-03 23:38:47 +08:00
|
|
|
cpu_abort(CPU(cpu), "Illegal instruction: %04x @ %08x", insn, s->pc - 2);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mulw)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv src;
|
2006-10-22 08:18:54 +08:00
|
|
|
int sign;
|
|
|
|
|
|
|
|
sign = (insn & 0x100) != 0;
|
|
|
|
reg = DREG(insn, 9);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
if (sign)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16s_i32(tmp, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16u_i32(tmp, reg);
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src, OS_WORD, sign, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mul_i32(tmp, tmp, src);
|
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2016-11-24 16:31:32 +08:00
|
|
|
gen_logic_cc(s, tmp, OS_LONG);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(divw)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv src;
|
2006-10-22 08:18:54 +08:00
|
|
|
int sign;
|
|
|
|
|
|
|
|
sign = (insn & 0x100) != 0;
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
if (sign) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16s_i32(QREG_DIV1, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16u_i32(QREG_DIV1, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src, OS_WORD, sign, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(QREG_DIV2, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (sign) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_divs(cpu_env, tcg_const_i32(1));
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_divu(cpu_env, tcg_const_i32(1));
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
|
|
|
src = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16u_i32(tmp, QREG_DIV1);
|
|
|
|
tcg_gen_shli_i32(src, QREG_DIV2, 16);
|
|
|
|
tcg_gen_or_i32(reg, tmp, src);
|
2015-08-14 22:59:20 +08:00
|
|
|
|
2015-08-09 07:44:24 +08:00
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(divl)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv num;
|
|
|
|
TCGv den;
|
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
uint16_t ext;
|
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (ext & 0x87f8) {
|
|
|
|
gen_exception(s, s->pc - 4, EXCP_UNSUPPORTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
num = DREG(ext, 12);
|
|
|
|
reg = DREG(ext, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(QREG_DIV1, num);
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, den, OS_LONG, 0, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(QREG_DIV2, den);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (ext & 0x0800) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_divs(cpu_env, tcg_const_i32(0));
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_divu(cpu_env, tcg_const_i32(0));
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
if ((ext & 7) == ((ext >> 12) & 7)) {
|
2006-10-22 08:18:54 +08:00
|
|
|
/* div */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32 (reg, QREG_DIV1);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
|
|
|
/* rem */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32 (reg, QREG_DIV2);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2015-08-09 07:44:24 +08:00
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(addsub)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv src;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
2006-10-22 08:18:54 +08:00
|
|
|
int add;
|
2016-01-17 07:57:01 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
add = (insn & 0x4000) != 0;
|
2016-01-17 07:57:01 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
reg = gen_extend(DREG(insn, 9), opsize, 1);
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
if (insn & 0x100) {
|
2016-01-17 07:57:01 +08:00
|
|
|
SRC_EA(env, tmp, opsize, 1, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
src = reg;
|
|
|
|
} else {
|
|
|
|
tmp = reg;
|
2016-01-17 07:57:01 +08:00
|
|
|
SRC_EA(env, src, opsize, 1, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
if (add) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_add_i32(dest, tmp, src);
|
2015-08-14 22:59:19 +08:00
|
|
|
tcg_gen_setcond_i32(TCG_COND_LTU, QREG_CC_X, dest, src);
|
2016-01-17 07:57:01 +08:00
|
|
|
set_cc_op(s, CC_OP_ADDB + opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2015-08-14 22:59:19 +08:00
|
|
|
tcg_gen_setcond_i32(TCG_COND_LTU, QREG_CC_X, tmp, src);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_sub_i32(dest, tmp, src);
|
2016-01-17 07:57:01 +08:00
|
|
|
set_cc_op(s, CC_OP_SUBB + opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-01-17 07:57:01 +08:00
|
|
|
gen_update_cc_add(dest, src, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (insn & 0x100) {
|
2016-01-17 07:57:01 +08:00
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2016-01-17 07:57:01 +08:00
|
|
|
gen_partset_reg(opsize, DREG(insn, 9), dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-01-17 07:57:01 +08:00
|
|
|
tcg_temp_free(dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reverse the order of the bits in REG. */
|
|
|
|
DISAS_INSN(bitrev)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_bitrev(reg, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(bitop_reg)
|
|
|
|
{
|
|
|
|
int opsize;
|
|
|
|
int op;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src1;
|
|
|
|
TCGv src2;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
|
|
|
TCGv dest;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
if ((insn & 0x38) != 0)
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
else
|
|
|
|
opsize = OS_LONG;
|
|
|
|
op = (insn >> 6) & 3;
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src1, opsize, 0, op ? &addr: NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 19:51:45 +08:00
|
|
|
gen_flush_flags(s);
|
|
|
|
src2 = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
if (opsize == OS_BYTE)
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_gen_andi_i32(src2, DREG(insn, 9), 7);
|
2006-10-22 08:18:54 +08:00
|
|
|
else
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_gen_andi_i32(src2, DREG(insn, 9), 31);
|
2015-08-14 22:59:20 +08:00
|
|
|
|
2016-01-17 19:51:45 +08:00
|
|
|
tmp = tcg_const_i32(1);
|
|
|
|
tcg_gen_shl_i32(tmp, tmp, src2);
|
|
|
|
tcg_temp_free(src2);
|
2015-08-14 22:59:20 +08:00
|
|
|
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_gen_and_i32(QREG_CC_Z, src1, tmp);
|
2015-08-14 22:59:20 +08:00
|
|
|
|
2016-01-17 19:51:45 +08:00
|
|
|
dest = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
switch (op) {
|
|
|
|
case 1: /* bchg */
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_gen_xor_i32(dest, src1, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 2: /* bclr */
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_gen_andc_i32(dest, src1, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 3: /* bset */
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_gen_or_i32(dest, src1, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
default: /* btst */
|
|
|
|
break;
|
|
|
|
}
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_temp_free(tmp);
|
2015-08-14 22:59:20 +08:00
|
|
|
if (op) {
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
2015-08-14 22:59:20 +08:00
|
|
|
}
|
|
|
|
tcg_temp_free(dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(sats)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = DREG(insn, 0);
|
|
|
|
gen_flush_flags(s);
|
2015-08-14 22:59:20 +08:00
|
|
|
gen_helper_sats(reg, reg, QREG_CC_V);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, reg, OS_LONG);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
static void gen_push(DisasContext *s, TCGv val)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_subi_i32(tmp, QREG_SP, 4);
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_store(s, OS_LONG, tmp, val);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(QREG_SP, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(movem)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv addr;
|
2006-10-22 08:18:54 +08:00
|
|
|
int i;
|
|
|
|
uint16_t mask;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
int is_load;
|
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
mask = read_im16(env, s);
|
2012-09-08 18:48:20 +08:00
|
|
|
tmp = gen_lea(env, s, insn, OS_LONG);
|
2008-05-25 06:29:16 +08:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 06:11:13 +08:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-11-17 22:43:54 +08:00
|
|
|
addr = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(addr, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
is_load = ((insn & 0x0400) != 0);
|
|
|
|
for (i = 0; i < 16; i++, mask >>= 1) {
|
|
|
|
if (mask & 1) {
|
|
|
|
if (i < 8)
|
|
|
|
reg = DREG(i, 0);
|
|
|
|
else
|
|
|
|
reg = AREG(i, 0);
|
|
|
|
if (is_load) {
|
2007-05-24 03:58:11 +08:00
|
|
|
tmp = gen_load(s, OS_LONG, addr, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_store(s, OS_LONG, addr, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
if (mask != 1)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(addr, addr, 4);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(bitop_im)
|
|
|
|
{
|
|
|
|
int opsize;
|
|
|
|
int op;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src1;
|
2006-10-22 08:18:54 +08:00
|
|
|
uint32_t mask;
|
|
|
|
int bitnum;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
if ((insn & 0x38) != 0)
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
else
|
|
|
|
opsize = OS_LONG;
|
|
|
|
op = (insn >> 6) & 3;
|
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
bitnum = read_im16(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (bitnum & 0xff00) {
|
2012-09-08 18:48:20 +08:00
|
|
|
disas_undef(env, s, insn);
|
2006-10-22 08:18:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src1, opsize, 0, op ? &addr: NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 19:51:45 +08:00
|
|
|
gen_flush_flags(s);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (opsize == OS_BYTE)
|
|
|
|
bitnum &= 7;
|
|
|
|
else
|
|
|
|
bitnum &= 31;
|
|
|
|
mask = 1 << bitnum;
|
|
|
|
|
2016-01-17 19:51:45 +08:00
|
|
|
tcg_gen_andi_i32(QREG_CC_Z, src1, mask);
|
2015-08-14 22:59:20 +08:00
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
if (op) {
|
2015-08-14 22:59:20 +08:00
|
|
|
tmp = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
switch (op) {
|
|
|
|
case 1: /* bchg */
|
|
|
|
tcg_gen_xori_i32(tmp, src1, mask);
|
|
|
|
break;
|
|
|
|
case 2: /* bclr */
|
|
|
|
tcg_gen_andi_i32(tmp, src1, ~mask);
|
|
|
|
break;
|
|
|
|
case 3: /* bset */
|
|
|
|
tcg_gen_ori_i32(tmp, src1, mask);
|
|
|
|
break;
|
|
|
|
default: /* btst */
|
|
|
|
break;
|
|
|
|
}
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, insn, opsize, tmp, &addr);
|
2015-08-14 22:59:20 +08:00
|
|
|
tcg_temp_free(tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
2015-08-14 22:59:20 +08:00
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
DISAS_INSN(arith_im)
|
|
|
|
{
|
|
|
|
int op;
|
2016-01-17 07:59:27 +08:00
|
|
|
TCGv im;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src1;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
2016-01-17 07:59:27 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
op = (insn >> 9) & 7;
|
2016-01-17 07:59:27 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE:
|
|
|
|
im = tcg_const_i32((int8_t)read_im8(env, s));
|
|
|
|
break;
|
|
|
|
case OS_WORD:
|
|
|
|
im = tcg_const_i32((int16_t)read_im16(env, s));
|
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
im = tcg_const_i32(read_im32(env, s));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
SRC_EA(env, src1, opsize, 1, (op == 6) ? NULL : &addr);
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
switch (op) {
|
|
|
|
case 0: /* ori */
|
2016-01-17 07:59:27 +08:00
|
|
|
tcg_gen_or_i32(dest, src1, im);
|
|
|
|
gen_logic_cc(s, dest, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 1: /* andi */
|
2016-01-17 07:59:27 +08:00
|
|
|
tcg_gen_and_i32(dest, src1, im);
|
|
|
|
gen_logic_cc(s, dest, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 2: /* subi */
|
2016-01-17 07:59:27 +08:00
|
|
|
tcg_gen_setcond_i32(TCG_COND_LTU, QREG_CC_X, src1, im);
|
|
|
|
tcg_gen_sub_i32(dest, src1, im);
|
|
|
|
gen_update_cc_add(dest, im, opsize);
|
|
|
|
set_cc_op(s, CC_OP_SUBB + opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 3: /* addi */
|
2016-01-17 07:59:27 +08:00
|
|
|
tcg_gen_add_i32(dest, src1, im);
|
|
|
|
gen_update_cc_add(dest, im, opsize);
|
|
|
|
tcg_gen_setcond_i32(TCG_COND_LTU, QREG_CC_X, dest, im);
|
|
|
|
set_cc_op(s, CC_OP_ADDB + opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 5: /* eori */
|
2016-01-17 07:59:27 +08:00
|
|
|
tcg_gen_xor_i32(dest, src1, im);
|
|
|
|
gen_logic_cc(s, dest, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 6: /* cmpi */
|
2016-01-17 07:59:27 +08:00
|
|
|
gen_update_cc_cmp(s, src1, im, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2016-01-17 07:59:27 +08:00
|
|
|
tcg_temp_free(im);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (op != 6) {
|
2016-01-17 07:59:27 +08:00
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-01-17 07:59:27 +08:00
|
|
|
tcg_temp_free(dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(byterev)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
2009-03-13 17:34:48 +08:00
|
|
|
tcg_gen_bswap32_i32(reg, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv dest;
|
2006-10-22 08:18:54 +08:00
|
|
|
int op;
|
|
|
|
int opsize;
|
|
|
|
|
|
|
|
switch (insn >> 12) {
|
|
|
|
case 1: /* move.b */
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
break;
|
|
|
|
case 2: /* move.l */
|
|
|
|
opsize = OS_LONG;
|
|
|
|
break;
|
|
|
|
case 3: /* move.w */
|
|
|
|
opsize = OS_WORD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src, opsize, 1, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
op = (insn >> 6) & 7;
|
|
|
|
if (op == 1) {
|
|
|
|
/* movea */
|
|
|
|
/* The value will already have been sign extended. */
|
|
|
|
dest = AREG(insn, 9);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(dest, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
|
|
|
/* normal move */
|
|
|
|
uint16_t dest_ea;
|
|
|
|
dest_ea = ((insn >> 9) & 7) | (op << 3);
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, dest_ea, opsize, src, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
/* This will be correct because loads sign extend. */
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, src, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(negx)
|
|
|
|
{
|
2015-08-14 22:59:26 +08:00
|
|
|
TCGv z;
|
|
|
|
TCGv src;
|
|
|
|
TCGv addr;
|
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2015-08-14 22:59:26 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
SRC_EA(env, src, opsize, 1, &addr);
|
|
|
|
|
|
|
|
gen_flush_flags(s); /* compute old Z */
|
|
|
|
|
|
|
|
/* Perform substract with borrow.
|
|
|
|
* (X, N) = -(src + X);
|
|
|
|
*/
|
|
|
|
|
|
|
|
z = tcg_const_i32(0);
|
|
|
|
tcg_gen_add2_i32(QREG_CC_N, QREG_CC_X, src, z, QREG_CC_X, z);
|
|
|
|
tcg_gen_sub2_i32(QREG_CC_N, QREG_CC_X, z, z, QREG_CC_N, QREG_CC_X);
|
|
|
|
tcg_temp_free(z);
|
|
|
|
gen_ext(QREG_CC_N, QREG_CC_N, opsize, 1);
|
|
|
|
|
|
|
|
tcg_gen_andi_i32(QREG_CC_X, QREG_CC_X, 1);
|
|
|
|
|
|
|
|
/* Compute signed-overflow for negation. The normal formula for
|
|
|
|
* subtraction is (res ^ src) & (src ^ dest), but with dest==0
|
|
|
|
* this simplies to res & src.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tcg_gen_and_i32(QREG_CC_V, QREG_CC_N, src);
|
|
|
|
|
|
|
|
/* Copy the rest of the results into place. */
|
|
|
|
tcg_gen_or_i32(QREG_CC_Z, QREG_CC_Z, QREG_CC_N); /* !Z is sticky */
|
|
|
|
tcg_gen_mov_i32(QREG_CC_C, QREG_CC_X);
|
|
|
|
|
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
|
|
|
|
|
|
|
/* result is in QREG_CC_N */
|
|
|
|
|
|
|
|
DEST_EA(env, insn, opsize, QREG_CC_N, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(lea)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
reg = AREG(insn, 9);
|
2012-09-08 18:48:20 +08:00
|
|
|
tmp = gen_lea(env, s, insn, OS_LONG);
|
2008-05-25 06:29:16 +08:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 06:11:13 +08:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(clr)
|
|
|
|
{
|
|
|
|
int opsize;
|
|
|
|
|
2015-08-09 07:12:46 +08:00
|
|
|
opsize = insn_opsize(insn);
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, insn, opsize, tcg_const_i32(0), NULL);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, tcg_const_i32(0), opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
static TCGv gen_get_ccr(DisasContext *s)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv dest;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
gen_flush_flags(s);
|
2015-08-14 22:59:20 +08:00
|
|
|
update_cc_op(s);
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2015-08-14 22:59:20 +08:00
|
|
|
gen_helper_get_ccr(dest, cpu_env);
|
2007-05-24 03:58:11 +08:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_from_ccr)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv ccr;
|
2007-05-24 03:58:11 +08:00
|
|
|
|
|
|
|
ccr = gen_get_ccr(s);
|
2016-01-18 01:55:13 +08:00
|
|
|
DEST_EA(env, insn, OS_WORD, ccr, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(neg)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src1;
|
2016-01-17 06:13:23 +08:00
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 06:13:23 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
SRC_EA(env, src1, opsize, 1, &addr);
|
|
|
|
dest = tcg_temp_new();
|
|
|
|
tcg_gen_neg_i32(dest, src1);
|
|
|
|
set_cc_op(s, CC_OP_SUBB + opsize);
|
|
|
|
gen_update_cc_add(dest, src1, opsize);
|
|
|
|
tcg_gen_setcondi_i32(TCG_COND_NE, QREG_CC_X, dest, 0);
|
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
|
|
|
tcg_temp_free(dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
static void gen_set_sr_im(DisasContext *s, uint16_t val, int ccr_only)
|
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
if (ccr_only) {
|
|
|
|
tcg_gen_movi_i32(QREG_CC_C, val & CCF_C ? 1 : 0);
|
|
|
|
tcg_gen_movi_i32(QREG_CC_V, val & CCF_V ? -1 : 0);
|
|
|
|
tcg_gen_movi_i32(QREG_CC_Z, val & CCF_Z ? 0 : 1);
|
|
|
|
tcg_gen_movi_i32(QREG_CC_N, val & CCF_N ? -1 : 0);
|
|
|
|
tcg_gen_movi_i32(QREG_CC_X, val & CCF_X ? 1 : 0);
|
|
|
|
} else {
|
|
|
|
gen_helper_set_sr(cpu_env, tcg_const_i32(val));
|
2007-05-24 03:58:11 +08:00
|
|
|
}
|
2015-08-09 07:44:24 +08:00
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
2007-05-24 03:58:11 +08:00
|
|
|
}
|
|
|
|
|
2015-08-14 22:59:20 +08:00
|
|
|
static void gen_set_sr(CPUM68KState *env, DisasContext *s, uint16_t insn,
|
|
|
|
int ccr_only)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
if ((insn & 0x38) == 0) {
|
|
|
|
if (ccr_only) {
|
|
|
|
gen_helper_set_ccr(cpu_env, DREG(insn, 0));
|
|
|
|
} else {
|
|
|
|
gen_helper_set_sr(cpu_env, DREG(insn, 0));
|
|
|
|
}
|
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
|
|
|
} else if ((insn & 0x3f) == 0x3c) {
|
|
|
|
uint16_t val;
|
|
|
|
val = read_im16(env, s);
|
|
|
|
gen_set_sr_im(s, val, ccr_only);
|
|
|
|
} else {
|
|
|
|
disas_undef(env, s, insn);
|
2016-01-18 01:55:13 +08:00
|
|
|
}
|
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-18 01:55:13 +08:00
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
DISAS_INSN(move_to_ccr)
|
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
gen_set_sr(env, s, insn, 1);
|
2007-05-24 03:58:11 +08:00
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
DISAS_INSN(not)
|
|
|
|
{
|
2016-01-17 06:13:52 +08:00
|
|
|
TCGv src1;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 06:13:52 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
SRC_EA(env, src1, opsize, 1, &addr);
|
|
|
|
dest = tcg_temp_new();
|
|
|
|
tcg_gen_not_i32(dest, src1);
|
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
|
|
|
gen_logic_cc(s, dest, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(swap)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src1;
|
|
|
|
TCGv src2;
|
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
src1 = tcg_temp_new();
|
|
|
|
src2 = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_shli_i32(src1, reg, 16);
|
|
|
|
tcg_gen_shri_i32(src2, reg, 16);
|
|
|
|
tcg_gen_or_i32(reg, src1, src2);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, reg, OS_LONG);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2016-01-17 08:13:07 +08:00
|
|
|
DISAS_INSN(bkpt)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_DEBUG);
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
DISAS_INSN(pea)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2012-09-08 18:48:20 +08:00
|
|
|
tmp = gen_lea(env, s, insn, OS_LONG);
|
2008-05-25 06:29:16 +08:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 06:11:13 +08:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_push(s, tmp);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(ext)
|
|
|
|
{
|
|
|
|
int op;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
|
|
|
op = (insn >> 6) & 7;
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
if (op == 3)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16s_i32(tmp, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext8s_i32(tmp, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (op == 2)
|
|
|
|
gen_partset_reg(OS_WORD, reg, tmp);
|
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, tmp, OS_LONG);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(tst)
|
|
|
|
{
|
|
|
|
int opsize;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2015-08-09 07:12:46 +08:00
|
|
|
opsize = insn_opsize(insn);
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, tmp, opsize, 1, NULL);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, tmp, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(pulse)
|
|
|
|
{
|
|
|
|
/* Implemented as a NOP. */
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(illegal)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ??? This should be atomic. */
|
|
|
|
DISAS_INSN(tas)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv dest;
|
|
|
|
TCGv src1;
|
|
|
|
TCGv addr;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src1, OS_BYTE, 1, &addr);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, src1, OS_BYTE);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ori_i32(dest, src1, 0x80);
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, insn, OS_BYTE, dest, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mull)
|
|
|
|
{
|
|
|
|
uint16_t ext;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv src1;
|
|
|
|
TCGv dest;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
/* The upper 32 bits of the product are discarded, so
|
|
|
|
muls.l and mulu.l are functionally equivalent. */
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (ext & 0x87ff) {
|
|
|
|
gen_exception(s, s->pc - 4, EXCP_UNSUPPORTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reg = DREG(ext, 12);
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src1, OS_LONG, 0, NULL);
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mul_i32(dest, src1, reg);
|
|
|
|
tcg_gen_mov_i32(reg, dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Unlike m68k, coldfire always clears the overflow bit. */
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, dest, OS_LONG);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2016-01-13 03:44:21 +08:00
|
|
|
static void gen_link(DisasContext *s, uint16_t insn, int32_t offset)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
reg = AREG(insn, 0);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_subi_i32(tmp, QREG_SP, 4);
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_store(s, OS_LONG, tmp, reg);
|
2016-01-13 03:44:21 +08:00
|
|
|
if ((insn & 7) != 7) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2016-01-13 03:44:21 +08:00
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(QREG_SP, tmp, offset);
|
2016-01-13 03:44:21 +08:00
|
|
|
tcg_temp_free(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(link)
|
|
|
|
{
|
|
|
|
int16_t offset;
|
|
|
|
|
|
|
|
offset = read_im16(env, s);
|
|
|
|
gen_link(s, insn, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(linkl)
|
|
|
|
{
|
|
|
|
int32_t offset;
|
|
|
|
|
|
|
|
offset = read_im32(env, s);
|
|
|
|
gen_link(s, insn, offset);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(unlk)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
src = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = AREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(src, reg);
|
2007-05-24 03:58:11 +08:00
|
|
|
tmp = gen_load(s, OS_LONG, src, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
|
|
|
tcg_gen_addi_i32(QREG_SP, src, 4);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(nop)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(rts)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
tmp = gen_load(s, OS_LONG, QREG_SP, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(QREG_SP, QREG_SP, 4);
|
2006-10-22 08:18:54 +08:00
|
|
|
gen_jmp(s, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(jump)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
/* Load the target address first to ensure correct exception
|
|
|
|
behavior. */
|
2012-09-08 18:48:20 +08:00
|
|
|
tmp = gen_lea(env, s, insn, OS_LONG);
|
2008-05-25 06:29:16 +08:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 06:11:13 +08:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
if ((insn & 0x40) == 0) {
|
|
|
|
/* jsr */
|
2011-03-25 17:36:36 +08:00
|
|
|
gen_push(s, tcg_const_i32(s->pc));
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
gen_jmp(s, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(addsubq)
|
|
|
|
{
|
2016-01-17 07:57:01 +08:00
|
|
|
TCGv src;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv dest;
|
2016-01-17 07:57:01 +08:00
|
|
|
TCGv val;
|
|
|
|
int imm;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv addr;
|
2016-01-17 07:57:01 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 07:57:01 +08:00
|
|
|
if ((insn & 070) == 010) {
|
|
|
|
/* Operation on address register is always long. */
|
|
|
|
opsize = OS_LONG;
|
|
|
|
} else {
|
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
}
|
|
|
|
SRC_EA(env, src, opsize, 1, &addr);
|
|
|
|
imm = (insn >> 9) & 7;
|
|
|
|
if (imm == 0) {
|
|
|
|
imm = 8;
|
|
|
|
}
|
|
|
|
val = tcg_const_i32(imm);
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2016-01-17 07:57:01 +08:00
|
|
|
tcg_gen_mov_i32(dest, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
if ((insn & 0x38) == 0x08) {
|
|
|
|
/* Don't update condition codes if the destination is an
|
|
|
|
address register. */
|
|
|
|
if (insn & 0x0100) {
|
2016-01-17 07:57:01 +08:00
|
|
|
tcg_gen_sub_i32(dest, dest, val);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2016-01-17 07:57:01 +08:00
|
|
|
tcg_gen_add_i32(dest, dest, val);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (insn & 0x0100) {
|
2016-01-17 07:57:01 +08:00
|
|
|
tcg_gen_setcond_i32(TCG_COND_LTU, QREG_CC_X, dest, val);
|
|
|
|
tcg_gen_sub_i32(dest, dest, val);
|
|
|
|
set_cc_op(s, CC_OP_SUBB + opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2016-01-17 07:57:01 +08:00
|
|
|
tcg_gen_add_i32(dest, dest, val);
|
|
|
|
tcg_gen_setcond_i32(TCG_COND_LTU, QREG_CC_X, dest, val);
|
|
|
|
set_cc_op(s, CC_OP_ADDB + opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-01-17 07:57:01 +08:00
|
|
|
gen_update_cc_add(dest, val, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-01-17 07:57:01 +08:00
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(tpf)
|
|
|
|
{
|
|
|
|
switch (insn & 7) {
|
|
|
|
case 2: /* One extension word. */
|
|
|
|
s->pc += 2;
|
|
|
|
break;
|
|
|
|
case 3: /* Two extension words. */
|
|
|
|
s->pc += 4;
|
|
|
|
break;
|
|
|
|
case 4: /* No extension words. */
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-08 18:48:20 +08:00
|
|
|
disas_undef(env, s, insn);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(branch)
|
|
|
|
{
|
|
|
|
int32_t offset;
|
|
|
|
uint32_t base;
|
|
|
|
int op;
|
2015-02-14 04:51:55 +08:00
|
|
|
TCGLabel *l1;
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
base = s->pc;
|
|
|
|
op = (insn >> 8) & 0xf;
|
|
|
|
offset = (int8_t)insn;
|
|
|
|
if (offset == 0) {
|
2015-06-24 08:28:59 +08:00
|
|
|
offset = (int16_t)read_im16(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else if (offset == -1) {
|
2012-09-08 18:48:20 +08:00
|
|
|
offset = read_im32(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
if (op == 1) {
|
|
|
|
/* bsr */
|
2011-03-25 17:36:36 +08:00
|
|
|
gen_push(s, tcg_const_i32(s->pc));
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
if (op > 1) {
|
|
|
|
/* Bcc */
|
|
|
|
l1 = gen_new_label();
|
|
|
|
gen_jmpcc(s, ((insn >> 8) & 0xf) ^ 1, l1);
|
|
|
|
gen_jmp_tb(s, 1, base + offset);
|
|
|
|
gen_set_label(l1);
|
|
|
|
gen_jmp_tb(s, 0, s->pc);
|
|
|
|
} else {
|
|
|
|
/* Unconditional branch. */
|
|
|
|
gen_jmp_tb(s, 0, base + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(moveq)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
uint32_t val;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
val = (int8_t)insn;
|
|
|
|
tcg_gen_movi_i32(DREG(insn, 9), val);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, tcg_const_i32(val), OS_LONG);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mvzs)
|
|
|
|
{
|
|
|
|
int opsize;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
if (insn & 0x40)
|
|
|
|
opsize = OS_WORD;
|
|
|
|
else
|
|
|
|
opsize = OS_BYTE;
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src, opsize, (insn & 0x80) == 0, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = DREG(insn, 9);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, src);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, src, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(or)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv src;
|
|
|
|
TCGv addr;
|
2016-01-17 06:40:50 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 06:40:50 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
reg = gen_extend(DREG(insn, 9), opsize, 0);
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2006-10-22 08:18:54 +08:00
|
|
|
if (insn & 0x100) {
|
2016-01-17 06:40:50 +08:00
|
|
|
SRC_EA(env, src, opsize, 0, &addr);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_or_i32(dest, src, reg);
|
2016-01-17 06:40:50 +08:00
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2016-01-17 06:40:50 +08:00
|
|
|
SRC_EA(env, src, opsize, 0, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_or_i32(dest, src, reg);
|
2016-01-17 06:40:50 +08:00
|
|
|
gen_partset_reg(opsize, DREG(insn, 9), dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-01-17 06:40:50 +08:00
|
|
|
gen_logic_cc(s, dest, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(suba)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 06:33:43 +08:00
|
|
|
SRC_EA(env, src, (insn & 0x100) ? OS_LONG : OS_WORD, 1, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = AREG(insn, 9);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_sub_i32(reg, reg, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2015-08-14 22:59:26 +08:00
|
|
|
static inline void gen_subx(DisasContext *s, TCGv src, TCGv dest, int opsize)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2015-08-14 22:59:26 +08:00
|
|
|
TCGv tmp;
|
|
|
|
|
|
|
|
gen_flush_flags(s); /* compute old Z */
|
|
|
|
|
|
|
|
/* Perform substract with borrow.
|
|
|
|
* (X, N) = dest - (src + X);
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmp = tcg_const_i32(0);
|
|
|
|
tcg_gen_add2_i32(QREG_CC_N, QREG_CC_X, src, tmp, QREG_CC_X, tmp);
|
|
|
|
tcg_gen_sub2_i32(QREG_CC_N, QREG_CC_X, dest, tmp, QREG_CC_N, QREG_CC_X);
|
|
|
|
gen_ext(QREG_CC_N, QREG_CC_N, opsize, 1);
|
|
|
|
tcg_gen_andi_i32(QREG_CC_X, QREG_CC_X, 1);
|
|
|
|
|
|
|
|
/* Compute signed-overflow for substract. */
|
|
|
|
|
|
|
|
tcg_gen_xor_i32(QREG_CC_V, QREG_CC_N, dest);
|
|
|
|
tcg_gen_xor_i32(tmp, dest, src);
|
|
|
|
tcg_gen_and_i32(QREG_CC_V, QREG_CC_V, tmp);
|
|
|
|
tcg_temp_free(tmp);
|
|
|
|
|
|
|
|
/* Copy the rest of the results into place. */
|
|
|
|
tcg_gen_or_i32(QREG_CC_Z, QREG_CC_Z, QREG_CC_N); /* !Z is sticky */
|
|
|
|
tcg_gen_mov_i32(QREG_CC_C, QREG_CC_X);
|
|
|
|
|
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
|
|
|
|
|
|
|
/* result is in QREG_CC_N */
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(subx_reg)
|
|
|
|
{
|
|
|
|
TCGv dest;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
2015-08-14 22:59:26 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2015-08-14 22:59:26 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
|
|
|
|
src = gen_extend(DREG(insn, 0), opsize, 1);
|
|
|
|
dest = gen_extend(DREG(insn, 9), opsize, 1);
|
|
|
|
|
|
|
|
gen_subx(s, src, dest, opsize);
|
|
|
|
|
|
|
|
gen_partset_reg(opsize, DREG(insn, 9), QREG_CC_N);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(subx_mem)
|
|
|
|
{
|
|
|
|
TCGv src;
|
|
|
|
TCGv addr_src;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr_dest;
|
|
|
|
int opsize;
|
|
|
|
|
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
|
|
|
|
addr_src = AREG(insn, 0);
|
|
|
|
tcg_gen_subi_i32(addr_src, addr_src, opsize);
|
|
|
|
src = gen_load(s, opsize, addr_src, 1);
|
|
|
|
|
|
|
|
addr_dest = AREG(insn, 9);
|
|
|
|
tcg_gen_subi_i32(addr_dest, addr_dest, opsize);
|
|
|
|
dest = gen_load(s, opsize, addr_dest, 1);
|
|
|
|
|
|
|
|
gen_subx(s, src, dest, opsize);
|
|
|
|
|
|
|
|
gen_store(s, opsize, addr_dest, QREG_CC_N);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mov3q)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
2006-10-22 08:18:54 +08:00
|
|
|
int val;
|
|
|
|
|
|
|
|
val = (insn >> 9) & 7;
|
|
|
|
if (val == 0)
|
|
|
|
val = -1;
|
2011-03-25 17:36:36 +08:00
|
|
|
src = tcg_const_i32(val);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, src, OS_LONG);
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, insn, OS_LONG, src, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(cmp)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
int opsize;
|
|
|
|
|
2015-08-09 08:41:40 +08:00
|
|
|
opsize = insn_opsize(insn);
|
2016-01-17 21:34:09 +08:00
|
|
|
SRC_EA(env, src, opsize, 1, NULL);
|
|
|
|
reg = gen_extend(DREG(insn, 9), opsize, 1);
|
|
|
|
gen_update_cc_cmp(s, reg, src, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(cmpa)
|
|
|
|
{
|
|
|
|
int opsize;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
if (insn & 0x100) {
|
|
|
|
opsize = OS_LONG;
|
|
|
|
} else {
|
|
|
|
opsize = OS_WORD;
|
|
|
|
}
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, src, opsize, 1, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = AREG(insn, 9);
|
2016-11-24 04:45:56 +08:00
|
|
|
gen_update_cc_cmp(s, reg, src, OS_LONG);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(eor)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
2016-01-17 06:32:31 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 06:32:31 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
|
|
|
|
SRC_EA(env, src, opsize, 0, &addr);
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2016-01-17 06:32:31 +08:00
|
|
|
tcg_gen_xor_i32(dest, src, DREG(insn, 9));
|
|
|
|
gen_logic_cc(s, dest, opsize);
|
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2016-01-17 06:05:55 +08:00
|
|
|
static void do_exg(TCGv reg1, TCGv reg2)
|
|
|
|
{
|
|
|
|
TCGv temp = tcg_temp_new();
|
|
|
|
tcg_gen_mov_i32(temp, reg1);
|
|
|
|
tcg_gen_mov_i32(reg1, reg2);
|
|
|
|
tcg_gen_mov_i32(reg2, temp);
|
|
|
|
tcg_temp_free(temp);
|
|
|
|
}
|
|
|
|
|
2016-11-23 20:57:56 +08:00
|
|
|
DISAS_INSN(exg_dd)
|
2016-01-17 06:05:55 +08:00
|
|
|
{
|
|
|
|
/* exchange Dx and Dy */
|
|
|
|
do_exg(DREG(insn, 9), DREG(insn, 0));
|
|
|
|
}
|
|
|
|
|
2016-11-23 20:57:56 +08:00
|
|
|
DISAS_INSN(exg_aa)
|
2016-01-17 06:05:55 +08:00
|
|
|
{
|
|
|
|
/* exchange Ax and Ay */
|
|
|
|
do_exg(AREG(insn, 9), AREG(insn, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(exg_da)
|
|
|
|
{
|
|
|
|
/* exchange Dx and Ay */
|
|
|
|
do_exg(DREG(insn, 9), AREG(insn, 0));
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
DISAS_INSN(and)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
2016-01-17 06:38:08 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
dest = tcg_temp_new();
|
2016-01-17 06:38:08 +08:00
|
|
|
|
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
reg = DREG(insn, 9);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (insn & 0x100) {
|
2016-01-17 06:38:08 +08:00
|
|
|
SRC_EA(env, src, opsize, 0, &addr);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_and_i32(dest, src, reg);
|
2016-01-17 06:38:08 +08:00
|
|
|
DEST_EA(env, insn, opsize, dest, &addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2016-01-17 06:38:08 +08:00
|
|
|
SRC_EA(env, src, opsize, 0, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_and_i32(dest, src, reg);
|
2016-01-17 06:38:08 +08:00
|
|
|
gen_partset_reg(opsize, reg, dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2016-01-17 06:38:08 +08:00
|
|
|
tcg_temp_free(dest);
|
|
|
|
gen_logic_cc(s, dest, opsize);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(adda)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2016-01-17 06:33:43 +08:00
|
|
|
SRC_EA(env, src, (insn & 0x100) ? OS_LONG : OS_WORD, 1, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = AREG(insn, 9);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_add_i32(reg, reg, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2015-08-14 22:59:26 +08:00
|
|
|
static inline void gen_addx(DisasContext *s, TCGv src, TCGv dest, int opsize)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2015-08-14 22:59:26 +08:00
|
|
|
TCGv tmp;
|
|
|
|
|
|
|
|
gen_flush_flags(s); /* compute old Z */
|
|
|
|
|
|
|
|
/* Perform addition with carry.
|
|
|
|
* (X, N) = src + dest + X;
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmp = tcg_const_i32(0);
|
|
|
|
tcg_gen_add2_i32(QREG_CC_N, QREG_CC_X, QREG_CC_X, tmp, dest, tmp);
|
|
|
|
tcg_gen_add2_i32(QREG_CC_N, QREG_CC_X, QREG_CC_N, QREG_CC_X, src, tmp);
|
|
|
|
gen_ext(QREG_CC_N, QREG_CC_N, opsize, 1);
|
|
|
|
|
|
|
|
/* Compute signed-overflow for addition. */
|
|
|
|
|
|
|
|
tcg_gen_xor_i32(QREG_CC_V, QREG_CC_N, src);
|
|
|
|
tcg_gen_xor_i32(tmp, dest, src);
|
|
|
|
tcg_gen_andc_i32(QREG_CC_V, QREG_CC_V, tmp);
|
|
|
|
tcg_temp_free(tmp);
|
|
|
|
|
|
|
|
/* Copy the rest of the results into place. */
|
|
|
|
tcg_gen_or_i32(QREG_CC_Z, QREG_CC_Z, QREG_CC_N); /* !Z is sticky */
|
|
|
|
tcg_gen_mov_i32(QREG_CC_C, QREG_CC_X);
|
|
|
|
|
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
|
|
|
|
|
|
|
/* result is in QREG_CC_N */
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(addx_reg)
|
|
|
|
{
|
|
|
|
TCGv dest;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv src;
|
2015-08-14 22:59:26 +08:00
|
|
|
int opsize;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2015-08-14 22:59:26 +08:00
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
|
|
|
|
dest = gen_extend(DREG(insn, 9), opsize, 1);
|
|
|
|
src = gen_extend(DREG(insn, 0), opsize, 1);
|
|
|
|
|
|
|
|
gen_addx(s, src, dest, opsize);
|
|
|
|
|
|
|
|
gen_partset_reg(opsize, DREG(insn, 9), QREG_CC_N);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(addx_mem)
|
|
|
|
{
|
|
|
|
TCGv src;
|
|
|
|
TCGv addr_src;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr_dest;
|
|
|
|
int opsize;
|
|
|
|
|
|
|
|
opsize = insn_opsize(insn);
|
|
|
|
|
|
|
|
addr_src = AREG(insn, 0);
|
|
|
|
tcg_gen_subi_i32(addr_src, addr_src, opsize_bytes(opsize));
|
|
|
|
src = gen_load(s, opsize, addr_src, 1);
|
|
|
|
|
|
|
|
addr_dest = AREG(insn, 9);
|
|
|
|
tcg_gen_subi_i32(addr_dest, addr_dest, opsize_bytes(opsize));
|
|
|
|
dest = gen_load(s, opsize, addr_dest, 1);
|
|
|
|
|
|
|
|
gen_addx(s, src, dest, opsize);
|
|
|
|
|
|
|
|
gen_store(s, opsize, addr_dest, QREG_CC_N);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
/* TODO: This could be implemented without helper functions. */
|
2006-10-22 08:18:54 +08:00
|
|
|
DISAS_INSN(shift_im)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2006-10-22 08:18:54 +08:00
|
|
|
int tmp;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv shift;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2015-08-14 22:59:20 +08:00
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
reg = DREG(insn, 0);
|
|
|
|
tmp = (insn >> 9) & 7;
|
|
|
|
if (tmp == 0)
|
2008-05-25 06:29:16 +08:00
|
|
|
tmp = 8;
|
2011-03-25 17:36:36 +08:00
|
|
|
shift = tcg_const_i32(tmp);
|
2008-05-25 06:29:16 +08:00
|
|
|
/* No need to flush flags becuse we know we will set C flag. */
|
2006-10-22 08:18:54 +08:00
|
|
|
if (insn & 0x100) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_shl_cc(reg, cpu_env, reg, shift);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
|
|
|
if (insn & 8) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_shr_cc(reg, cpu_env, reg, shift);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_sar_cc(reg, cpu_env, reg, shift);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(shift_reg)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv shift;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
shift = DREG(insn, 9);
|
2006-10-22 08:18:54 +08:00
|
|
|
if (insn & 0x100) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_shl_cc(reg, cpu_env, reg, shift);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
|
|
|
if (insn & 8) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_shr_cc(reg, cpu_env, reg, shift);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_sar_cc(reg, cpu_env, reg, shift);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
}
|
2015-08-14 22:59:20 +08:00
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(ff1)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2007-05-28 10:20:34 +08:00
|
|
|
reg = DREG(insn, 0);
|
2015-08-09 08:41:40 +08:00
|
|
|
gen_logic_cc(s, reg, OS_LONG);
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_ff1(reg, reg);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
static TCGv gen_get_sr(DisasContext *s)
|
2007-05-24 03:58:11 +08:00
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv ccr;
|
|
|
|
TCGv sr;
|
2007-05-24 03:58:11 +08:00
|
|
|
|
|
|
|
ccr = gen_get_ccr(s);
|
2008-11-17 22:43:54 +08:00
|
|
|
sr = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(sr, QREG_SR, 0xffe0);
|
|
|
|
tcg_gen_or_i32(sr, sr, ccr);
|
2007-05-24 03:58:11 +08:00
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
DISAS_INSN(strldsr)
|
|
|
|
{
|
|
|
|
uint16_t ext;
|
|
|
|
uint32_t addr;
|
|
|
|
|
|
|
|
addr = s->pc - 2;
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2007-05-24 03:58:11 +08:00
|
|
|
if (ext != 0x46FC) {
|
2006-10-22 08:18:54 +08:00
|
|
|
gen_exception(s, addr, EXCP_UNSUPPORTED);
|
2007-05-24 03:58:11 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s) || (ext & SR_S) == 0) {
|
2006-10-22 08:18:54 +08:00
|
|
|
gen_exception(s, addr, EXCP_PRIVILEGE);
|
2007-05-24 03:58:11 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gen_push(s, gen_get_sr(s));
|
|
|
|
gen_set_sr_im(s, ext, 0);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_from_sr)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv sr;
|
2007-05-24 03:58:11 +08:00
|
|
|
|
2016-01-18 01:55:13 +08:00
|
|
|
if (IS_USER(s) && !m68k_feature(env, M68K_FEATURE_M68000)) {
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sr = gen_get_sr(s);
|
2016-01-18 01:55:13 +08:00
|
|
|
DEST_EA(env, insn, OS_WORD, sr, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_to_sr)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-14 22:59:20 +08:00
|
|
|
gen_set_sr(env, s, insn, 0);
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_lookup_tb(s);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_from_usp)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
2015-06-19 21:43:25 +08:00
|
|
|
tcg_gen_ld_i32(AREG(insn, 0), cpu_env,
|
|
|
|
offsetof(CPUM68KState, sp[M68K_USP]));
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_to_usp)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
2015-06-19 21:43:25 +08:00
|
|
|
tcg_gen_st_i32(AREG(insn, 0), cpu_env,
|
|
|
|
offsetof(CPUM68KState, sp[M68K_USP]));
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(halt)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_exception(s, s->pc, EXCP_HALT_INSN);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(stop)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
uint16_t ext;
|
|
|
|
|
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2007-05-24 03:58:11 +08:00
|
|
|
|
|
|
|
gen_set_sr_im(s, ext, 0);
|
2013-01-18 01:51:17 +08:00
|
|
|
tcg_gen_movi_i32(cpu_halted, 1);
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_exception(s, s->pc, EXCP_HLT);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(rte)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_RTE);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(movec)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
uint16_t ext;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2007-05-24 03:58:11 +08:00
|
|
|
|
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2007-05-24 03:58:11 +08:00
|
|
|
|
|
|
|
if (ext & 0x8000) {
|
|
|
|
reg = AREG(ext, 12);
|
|
|
|
} else {
|
|
|
|
reg = DREG(ext, 12);
|
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_movec(cpu_env, tcg_const_i32(ext & 0xfff), reg);
|
2007-05-24 03:58:11 +08:00
|
|
|
gen_lookup_tb(s);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(intouch)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* ICache fetch. Implement as no-op. */
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(cpushl)
|
|
|
|
{
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Cache push/invalidate. Implement as no-op. */
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(wddata)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(wdebug)
|
|
|
|
{
|
2013-09-03 23:38:47 +08:00
|
|
|
M68kCPU *cpu = m68k_env_get_cpu(env);
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* TODO: Implement wdebug. */
|
2013-09-03 23:38:47 +08:00
|
|
|
cpu_abort(CPU(cpu), "WDEBUG not implemented");
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(trap)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_TRAP0 + (insn & 0xf));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ??? FP exceptions are not implemented. Most exceptions are deferred until
|
|
|
|
immediately before the next FP instruction is executed. */
|
|
|
|
DISAS_INSN(fpu)
|
|
|
|
{
|
|
|
|
uint16_t ext;
|
2008-11-17 22:43:54 +08:00
|
|
|
int32_t offset;
|
2006-10-22 08:18:54 +08:00
|
|
|
int opmode;
|
2008-11-17 22:43:54 +08:00
|
|
|
TCGv_i64 src;
|
|
|
|
TCGv_i64 dest;
|
|
|
|
TCGv_i64 res;
|
|
|
|
TCGv tmp32;
|
2006-10-22 08:18:54 +08:00
|
|
|
int round;
|
2008-11-17 22:43:54 +08:00
|
|
|
int set_dest;
|
2006-10-22 08:18:54 +08:00
|
|
|
int opsize;
|
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
opmode = ext & 0x7f;
|
|
|
|
switch ((ext >> 13) & 7) {
|
|
|
|
case 0: case 2:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
goto undef;
|
|
|
|
case 3: /* fmove out */
|
|
|
|
src = FREG(ext, 7);
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp32 = tcg_temp_new_i32();
|
2006-10-22 08:18:54 +08:00
|
|
|
/* fmove */
|
|
|
|
/* ??? TODO: Proper behavior on overflow. */
|
|
|
|
switch ((ext >> 10) & 7) {
|
|
|
|
case 0:
|
|
|
|
opsize = OS_LONG;
|
2008-11-17 22:43:54 +08:00
|
|
|
gen_helper_f64_to_i32(tmp32, cpu_env, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
opsize = OS_SINGLE;
|
2008-11-17 22:43:54 +08:00
|
|
|
gen_helper_f64_to_f32(tmp32, cpu_env, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
opsize = OS_WORD;
|
2008-11-17 22:43:54 +08:00
|
|
|
gen_helper_f64_to_i32(tmp32, cpu_env, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
2008-11-17 22:43:54 +08:00
|
|
|
case 5: /* OS_DOUBLE */
|
|
|
|
tcg_gen_mov_i32(tmp32, AREG(insn, 0));
|
2009-02-23 22:17:33 +08:00
|
|
|
switch ((insn >> 3) & 7) {
|
2008-11-17 22:43:54 +08:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2009-02-23 23:19:34 +08:00
|
|
|
break;
|
2008-11-17 22:43:54 +08:00
|
|
|
case 4:
|
|
|
|
tcg_gen_addi_i32(tmp32, tmp32, -8);
|
|
|
|
break;
|
|
|
|
case 5:
|
2012-09-08 18:48:20 +08:00
|
|
|
offset = cpu_ldsw_code(env, s->pc);
|
2008-11-17 22:43:54 +08:00
|
|
|
s->pc += 2;
|
|
|
|
tcg_gen_addi_i32(tmp32, tmp32, offset);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto undef;
|
|
|
|
}
|
|
|
|
gen_store64(s, tmp32, src);
|
2009-02-23 22:17:33 +08:00
|
|
|
switch ((insn >> 3) & 7) {
|
2008-11-17 22:43:54 +08:00
|
|
|
case 3:
|
|
|
|
tcg_gen_addi_i32(tmp32, tmp32, 8);
|
|
|
|
tcg_gen_mov_i32(AREG(insn, 0), tmp32);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
tcg_gen_mov_i32(AREG(insn, 0), tmp32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tcg_temp_free_i32(tmp32);
|
|
|
|
return;
|
2006-10-22 08:18:54 +08:00
|
|
|
case 6:
|
|
|
|
opsize = OS_BYTE;
|
2008-11-17 22:43:54 +08:00
|
|
|
gen_helper_f64_to_i32(tmp32, cpu_env, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto undef;
|
|
|
|
}
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, insn, opsize, tmp32, NULL);
|
2008-11-17 22:43:54 +08:00
|
|
|
tcg_temp_free_i32(tmp32);
|
2006-10-22 08:18:54 +08:00
|
|
|
return;
|
|
|
|
case 4: /* fmove to control register. */
|
|
|
|
switch ((ext >> 10) & 7) {
|
|
|
|
case 4: /* FPCR */
|
|
|
|
/* Not implemented. Ignore writes. */
|
|
|
|
break;
|
|
|
|
case 1: /* FPIAR */
|
|
|
|
case 2: /* FPSR */
|
|
|
|
default:
|
|
|
|
cpu_abort(NULL, "Unimplemented: fmove to control %d",
|
|
|
|
(ext >> 10) & 7);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5: /* fmove from control register. */
|
|
|
|
switch ((ext >> 10) & 7) {
|
|
|
|
case 4: /* FPCR */
|
|
|
|
/* Not implemented. Always return zero. */
|
2011-03-25 17:36:36 +08:00
|
|
|
tmp32 = tcg_const_i32(0);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 1: /* FPIAR */
|
|
|
|
case 2: /* FPSR */
|
|
|
|
default:
|
|
|
|
cpu_abort(NULL, "Unimplemented: fmove from control %d",
|
|
|
|
(ext >> 10) & 7);
|
|
|
|
goto undef;
|
|
|
|
}
|
2012-09-08 18:48:20 +08:00
|
|
|
DEST_EA(env, insn, OS_LONG, tmp32, NULL);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
2007-09-17 05:08:06 +08:00
|
|
|
case 6: /* fmovem */
|
2006-10-22 08:18:54 +08:00
|
|
|
case 7:
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv addr;
|
|
|
|
uint16_t mask;
|
|
|
|
int i;
|
|
|
|
if ((ext & 0x1f00) != 0x1000 || (ext & 0xff) == 0)
|
|
|
|
goto undef;
|
2012-09-08 18:48:20 +08:00
|
|
|
tmp32 = gen_lea(env, s, insn, OS_LONG);
|
2008-11-17 22:43:54 +08:00
|
|
|
if (IS_NULL_QREG(tmp32)) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-11-17 22:43:54 +08:00
|
|
|
addr = tcg_temp_new_i32();
|
|
|
|
tcg_gen_mov_i32(addr, tmp32);
|
2008-05-25 06:29:16 +08:00
|
|
|
mask = 0x80;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (ext & mask) {
|
|
|
|
dest = FREG(i, 0);
|
|
|
|
if (ext & (1 << 13)) {
|
|
|
|
/* store */
|
|
|
|
tcg_gen_qemu_stf64(dest, addr, IS_USER(s));
|
|
|
|
} else {
|
|
|
|
/* load */
|
|
|
|
tcg_gen_qemu_ldf64(dest, addr, IS_USER(s));
|
|
|
|
}
|
|
|
|
if (ext & (mask - 1))
|
|
|
|
tcg_gen_addi_i32(addr, addr, 8);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
mask >>= 1;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2009-02-25 06:17:35 +08:00
|
|
|
tcg_temp_free_i32(addr);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ext & (1 << 14)) {
|
|
|
|
/* Source effective address. */
|
|
|
|
switch ((ext >> 10) & 7) {
|
|
|
|
case 0: opsize = OS_LONG; break;
|
|
|
|
case 1: opsize = OS_SINGLE; break;
|
|
|
|
case 4: opsize = OS_WORD; break;
|
|
|
|
case 5: opsize = OS_DOUBLE; break;
|
|
|
|
case 6: opsize = OS_BYTE; break;
|
|
|
|
default:
|
|
|
|
goto undef;
|
|
|
|
}
|
|
|
|
if (opsize == OS_DOUBLE) {
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp32 = tcg_temp_new_i32();
|
|
|
|
tcg_gen_mov_i32(tmp32, AREG(insn, 0));
|
2009-02-23 22:17:33 +08:00
|
|
|
switch ((insn >> 3) & 7) {
|
2008-11-17 22:43:54 +08:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2009-02-23 23:19:34 +08:00
|
|
|
break;
|
2008-11-17 22:43:54 +08:00
|
|
|
case 4:
|
|
|
|
tcg_gen_addi_i32(tmp32, tmp32, -8);
|
|
|
|
break;
|
|
|
|
case 5:
|
2012-09-08 18:48:20 +08:00
|
|
|
offset = cpu_ldsw_code(env, s->pc);
|
2008-11-17 22:43:54 +08:00
|
|
|
s->pc += 2;
|
|
|
|
tcg_gen_addi_i32(tmp32, tmp32, offset);
|
|
|
|
break;
|
|
|
|
case 7:
|
2012-09-08 18:48:20 +08:00
|
|
|
offset = cpu_ldsw_code(env, s->pc);
|
2008-11-17 22:43:54 +08:00
|
|
|
offset += s->pc - 2;
|
|
|
|
s->pc += 2;
|
|
|
|
tcg_gen_addi_i32(tmp32, tmp32, offset);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto undef;
|
|
|
|
}
|
|
|
|
src = gen_load64(s, tmp32);
|
2009-02-23 22:17:33 +08:00
|
|
|
switch ((insn >> 3) & 7) {
|
2008-11-17 22:43:54 +08:00
|
|
|
case 3:
|
|
|
|
tcg_gen_addi_i32(tmp32, tmp32, 8);
|
|
|
|
tcg_gen_mov_i32(AREG(insn, 0), tmp32);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
tcg_gen_mov_i32(AREG(insn, 0), tmp32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tcg_temp_free_i32(tmp32);
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, tmp32, opsize, 1, NULL);
|
2008-11-17 22:43:54 +08:00
|
|
|
src = tcg_temp_new_i64();
|
2006-10-22 08:18:54 +08:00
|
|
|
switch (opsize) {
|
|
|
|
case OS_LONG:
|
|
|
|
case OS_WORD:
|
|
|
|
case OS_BYTE:
|
2008-11-17 22:43:54 +08:00
|
|
|
gen_helper_i32_to_f64(src, cpu_env, tmp32);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case OS_SINGLE:
|
2008-11-17 22:43:54 +08:00
|
|
|
gen_helper_f32_to_f64(src, cpu_env, tmp32);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Source register. */
|
|
|
|
src = FREG(ext, 10);
|
|
|
|
}
|
|
|
|
dest = FREG(ext, 7);
|
2008-11-17 22:43:54 +08:00
|
|
|
res = tcg_temp_new_i64();
|
2006-10-22 08:18:54 +08:00
|
|
|
if (opmode != 0x3a)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_f64(res, dest);
|
2006-10-22 08:18:54 +08:00
|
|
|
round = 1;
|
2008-11-17 22:43:54 +08:00
|
|
|
set_dest = 1;
|
2006-10-22 08:18:54 +08:00
|
|
|
switch (opmode) {
|
|
|
|
case 0: case 0x40: case 0x44: /* fmove */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_f64(res, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 1: /* fint */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_iround_f64(res, cpu_env, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
case 3: /* fintrz */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_itrunc_f64(res, cpu_env, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
case 4: case 0x41: case 0x45: /* fsqrt */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_sqrt_f64(res, cpu_env, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 0x18: case 0x58: case 0x5c: /* fabs */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_abs_f64(res, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 0x1a: case 0x5a: case 0x5e: /* fneg */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_chs_f64(res, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 0x20: case 0x60: case 0x64: /* fdiv */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_div_f64(res, cpu_env, res, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 0x22: case 0x62: case 0x66: /* fadd */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_add_f64(res, cpu_env, res, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 0x23: case 0x63: case 0x67: /* fmul */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_mul_f64(res, cpu_env, res, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 0x28: case 0x68: case 0x6c: /* fsub */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_sub_f64(res, cpu_env, res, src);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 0x38: /* fcmp */
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_sub_cmp_f64(res, cpu_env, res, src);
|
2008-11-17 22:43:54 +08:00
|
|
|
set_dest = 0;
|
2006-10-22 08:18:54 +08:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
case 0x3a: /* ftst */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_f64(res, src);
|
2008-11-17 22:43:54 +08:00
|
|
|
set_dest = 0;
|
2006-10-22 08:18:54 +08:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto undef;
|
|
|
|
}
|
2008-11-17 22:43:54 +08:00
|
|
|
if (ext & (1 << 14)) {
|
|
|
|
tcg_temp_free_i64(src);
|
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
if (round) {
|
|
|
|
if (opmode & 0x40) {
|
|
|
|
if ((opmode & 0x4) != 0)
|
|
|
|
round = 0;
|
|
|
|
} else if ((s->fpcr & M68K_FPCR_PREC) == 0) {
|
|
|
|
round = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (round) {
|
2008-11-17 22:43:54 +08:00
|
|
|
TCGv tmp = tcg_temp_new_i32();
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_f64_to_f32(tmp, cpu_env, res);
|
|
|
|
gen_helper_f32_to_f64(res, cpu_env, tmp);
|
2008-11-17 22:43:54 +08:00
|
|
|
tcg_temp_free_i32(tmp);
|
2007-09-17 05:08:06 +08:00
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_f64(QREG_FP_RESULT, res);
|
2008-11-17 22:43:54 +08:00
|
|
|
if (set_dest) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_f64(dest, res);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2008-11-17 22:43:54 +08:00
|
|
|
tcg_temp_free_i64(res);
|
2006-10-22 08:18:54 +08:00
|
|
|
return;
|
|
|
|
undef:
|
2008-11-17 22:43:54 +08:00
|
|
|
/* FIXME: Is this right for offset addressing modes? */
|
2006-10-22 08:18:54 +08:00
|
|
|
s->pc -= 2;
|
2012-09-08 18:48:20 +08:00
|
|
|
disas_undef_fpu(env, s, insn);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(fbcc)
|
|
|
|
{
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t addr;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv flag;
|
2015-02-14 04:51:55 +08:00
|
|
|
TCGLabel *l1;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
addr = s->pc;
|
2012-09-08 18:48:20 +08:00
|
|
|
offset = cpu_ldsw_code(env, s->pc);
|
2006-10-22 08:18:54 +08:00
|
|
|
s->pc += 2;
|
|
|
|
if (insn & (1 << 6)) {
|
2015-06-24 08:28:59 +08:00
|
|
|
offset = (offset << 16) | read_im16(env, s);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
l1 = gen_new_label();
|
|
|
|
/* TODO: Raise BSUN exception. */
|
2008-11-17 22:43:54 +08:00
|
|
|
flag = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_compare_f64(flag, cpu_env, QREG_FP_RESULT);
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Jump to l1 if condition is true. */
|
|
|
|
switch (insn & 0xf) {
|
|
|
|
case 0: /* f */
|
|
|
|
break;
|
|
|
|
case 1: /* eq (=0) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 2: /* ogt (=1) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(1), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 3: /* oge (=0 or =1) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LEU, flag, tcg_const_i32(1), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 4: /* olt (=-1) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LT, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 5: /* ole (=-1 or =0) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LE, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 6: /* ogl (=-1 or =1) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(flag, flag, 1);
|
|
|
|
tcg_gen_brcond_i32(TCG_COND_NE, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 7: /* or (=2) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(2), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 8: /* un (<2) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LT, flag, tcg_const_i32(2), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 9: /* ueq (=0 or =2) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(flag, flag, 1);
|
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 10: /* ugt (>0) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_GT, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 11: /* uge (>=0) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_GE, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 12: /* ult (=-1 or =2) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_GEU, flag, tcg_const_i32(2), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 13: /* ule (!=1) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_NE, flag, tcg_const_i32(1), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 14: /* ne (!=0) */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_NE, flag, tcg_const_i32(0), l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case 15: /* t */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_br(l1);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
gen_jmp_tb(s, 0, s->pc);
|
|
|
|
gen_set_label(l1);
|
|
|
|
gen_jmp_tb(s, 1, addr + offset);
|
|
|
|
}
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
DISAS_INSN(frestore)
|
|
|
|
{
|
2013-09-03 23:38:47 +08:00
|
|
|
M68kCPU *cpu = m68k_env_get_cpu(env);
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
/* TODO: Implement frestore. */
|
2013-09-03 23:38:47 +08:00
|
|
|
cpu_abort(CPU(cpu), "FRESTORE not implemented");
|
2007-05-24 03:58:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(fsave)
|
|
|
|
{
|
2013-09-03 23:38:47 +08:00
|
|
|
M68kCPU *cpu = m68k_env_get_cpu(env);
|
|
|
|
|
2007-05-24 03:58:11 +08:00
|
|
|
/* TODO: Implement fsave. */
|
2013-09-03 23:38:47 +08:00
|
|
|
cpu_abort(CPU(cpu), "FSAVE not implemented");
|
2007-05-24 03:58:11 +08:00
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
static inline TCGv gen_mac_extract_word(DisasContext *s, TCGv val, int upper)
|
2007-05-29 22:57:59 +08:00
|
|
|
{
|
2008-11-17 22:43:54 +08:00
|
|
|
TCGv tmp = tcg_temp_new();
|
2007-05-29 22:57:59 +08:00
|
|
|
if (s->env->macsr & MACSR_FI) {
|
|
|
|
if (upper)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(tmp, val, 0xffff0000);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_shli_i32(tmp, val, 16);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else if (s->env->macsr & MACSR_SU) {
|
|
|
|
if (upper)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_sari_i32(tmp, val, 16);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16s_i32(tmp, val);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else {
|
|
|
|
if (upper)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_shri_i32(tmp, val, 16);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext16u_i32(tmp, val);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
static void gen_mac_clear_flags(void)
|
|
|
|
{
|
|
|
|
tcg_gen_andi_i32(QREG_MACSR, QREG_MACSR,
|
|
|
|
~(MACSR_V | MACSR_Z | MACSR_N | MACSR_EV));
|
|
|
|
}
|
|
|
|
|
2007-05-29 22:57:59 +08:00
|
|
|
DISAS_INSN(mac)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv rx;
|
|
|
|
TCGv ry;
|
2007-05-29 22:57:59 +08:00
|
|
|
uint16_t ext;
|
|
|
|
int acc;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
|
|
|
TCGv loadval;
|
2007-05-29 22:57:59 +08:00
|
|
|
int dual;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv saved_flags;
|
|
|
|
|
2008-11-17 22:43:54 +08:00
|
|
|
if (!s->done_mac) {
|
|
|
|
s->mactmp = tcg_temp_new_i64();
|
|
|
|
s->done_mac = 1;
|
|
|
|
}
|
2007-05-29 22:57:59 +08:00
|
|
|
|
2015-06-24 08:28:59 +08:00
|
|
|
ext = read_im16(env, s);
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
acc = ((insn >> 7) & 1) | ((ext >> 3) & 2);
|
|
|
|
dual = ((insn & 0x30) != 0 && (ext & 3) != 0);
|
2007-06-03 20:35:08 +08:00
|
|
|
if (dual && !m68k_feature(s->env, M68K_FEATURE_CF_EMAC_B)) {
|
2012-09-08 18:48:20 +08:00
|
|
|
disas_undef(env, s, insn);
|
2007-06-03 20:35:08 +08:00
|
|
|
return;
|
|
|
|
}
|
2007-05-29 22:57:59 +08:00
|
|
|
if (insn & 0x30) {
|
|
|
|
/* MAC with load. */
|
2012-09-08 18:48:20 +08:00
|
|
|
tmp = gen_lea(env, s, insn, OS_LONG);
|
2008-11-17 22:43:54 +08:00
|
|
|
addr = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_and_i32(addr, tmp, QREG_MAC_MASK);
|
2007-05-29 22:57:59 +08:00
|
|
|
/* Load the value now to ensure correct exception behavior.
|
|
|
|
Perform writeback after reading the MAC inputs. */
|
|
|
|
loadval = gen_load(s, OS_LONG, addr, 0);
|
|
|
|
|
|
|
|
acc ^= 1;
|
|
|
|
rx = (ext & 0x8000) ? AREG(ext, 12) : DREG(insn, 12);
|
|
|
|
ry = (ext & 8) ? AREG(ext, 0) : DREG(ext, 0);
|
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
loadval = addr = NULL_QREG;
|
2007-05-29 22:57:59 +08:00
|
|
|
rx = (insn & 0x40) ? AREG(insn, 9) : DREG(insn, 9);
|
|
|
|
ry = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_mac_clear_flags();
|
|
|
|
#if 0
|
2007-05-29 22:57:59 +08:00
|
|
|
l1 = -1;
|
2008-05-25 06:29:16 +08:00
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 22:57:59 +08:00
|
|
|
if ((s->env->macsr & MACSR_OMC) != 0 && !dual) {
|
|
|
|
/* Skip the multiply if we know we will ignore it. */
|
|
|
|
l1 = gen_new_label();
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_MACSR, 1 << (acc + 8));
|
2007-05-29 22:57:59 +08:00
|
|
|
gen_op_jmp_nz32(tmp, l1);
|
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
#endif
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
if ((ext & 0x0800) == 0) {
|
|
|
|
/* Word. */
|
|
|
|
rx = gen_mac_extract_word(s, rx, (ext & 0x80) != 0);
|
|
|
|
ry = gen_mac_extract_word(s, ry, (ext & 0x40) != 0);
|
|
|
|
}
|
|
|
|
if (s->env->macsr & MACSR_FI) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macmulf(s->mactmp, cpu_env, rx, ry);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else {
|
|
|
|
if (s->env->macsr & MACSR_SU)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macmuls(s->mactmp, cpu_env, rx, ry);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macmulu(s->mactmp, cpu_env, rx, ry);
|
2007-05-29 22:57:59 +08:00
|
|
|
switch ((ext >> 9) & 3) {
|
|
|
|
case 1:
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_shli_i64(s->mactmp, s->mactmp, 1);
|
2007-05-29 22:57:59 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_shri_i64(s->mactmp, s->mactmp, 1);
|
2007-05-29 22:57:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dual) {
|
|
|
|
/* Save the overflow flag from the multiply. */
|
2008-11-17 22:43:54 +08:00
|
|
|
saved_flags = tcg_temp_new();
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(saved_flags, QREG_MACSR);
|
|
|
|
} else {
|
|
|
|
saved_flags = NULL_QREG;
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 22:57:59 +08:00
|
|
|
if ((s->env->macsr & MACSR_OMC) != 0 && dual) {
|
|
|
|
/* Skip the accumulate if the value is already saturated. */
|
|
|
|
l1 = gen_new_label();
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2011-03-25 17:36:36 +08:00
|
|
|
gen_op_and32(tmp, QREG_MACSR, tcg_const_i32(MACSR_PAV0 << acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
gen_op_jmp_nz32(tmp, l1);
|
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
#endif
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
if (insn & 0x100)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_sub_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_add_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macsatf(cpu_env, tcg_const_i32(acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
else if (s->env->macsr & MACSR_SU)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macsats(cpu_env, tcg_const_i32(acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macsatu(cpu_env, tcg_const_i32(acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
|
2008-05-25 06:29:16 +08:00
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 22:57:59 +08:00
|
|
|
if (l1 != -1)
|
|
|
|
gen_set_label(l1);
|
2008-05-25 06:29:16 +08:00
|
|
|
#endif
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
if (dual) {
|
|
|
|
/* Dual accumulate variant. */
|
|
|
|
acc = (ext >> 2) & 3;
|
|
|
|
/* Restore the overflow flag from the multiplier. */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(QREG_MACSR, saved_flags);
|
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 22:57:59 +08:00
|
|
|
if ((s->env->macsr & MACSR_OMC) != 0) {
|
|
|
|
/* Skip the accumulate if the value is already saturated. */
|
|
|
|
l1 = gen_new_label();
|
2008-11-17 22:43:54 +08:00
|
|
|
tmp = tcg_temp_new();
|
2011-03-25 17:36:36 +08:00
|
|
|
gen_op_and32(tmp, QREG_MACSR, tcg_const_i32(MACSR_PAV0 << acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
gen_op_jmp_nz32(tmp, l1);
|
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
#endif
|
2007-05-29 22:57:59 +08:00
|
|
|
if (ext & 2)
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_sub_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_add_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 22:57:59 +08:00
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macsatf(cpu_env, tcg_const_i32(acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
else if (s->env->macsr & MACSR_SU)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macsats(cpu_env, tcg_const_i32(acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_macsatu(cpu_env, tcg_const_i32(acc));
|
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 22:57:59 +08:00
|
|
|
if (l1 != -1)
|
|
|
|
gen_set_label(l1);
|
2008-05-25 06:29:16 +08:00
|
|
|
#endif
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_mac_set_flags(cpu_env, tcg_const_i32(acc));
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
if (insn & 0x30) {
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv rw;
|
2007-05-29 22:57:59 +08:00
|
|
|
rw = (insn & 0x40) ? AREG(insn, 9) : DREG(insn, 9);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(rw, loadval);
|
2007-05-29 22:57:59 +08:00
|
|
|
/* FIXME: Should address writeback happen with the masked or
|
|
|
|
unmasked value? */
|
|
|
|
switch ((insn >> 3) & 7) {
|
|
|
|
case 3: /* Post-increment. */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_addi_i32(AREG(insn, 0), addr, 4);
|
2007-05-29 22:57:59 +08:00
|
|
|
break;
|
|
|
|
case 4: /* Pre-decrement. */
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(AREG(insn, 0), addr);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_mac)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv rx;
|
2008-11-17 22:43:54 +08:00
|
|
|
TCGv_i64 acc;
|
2008-05-25 06:29:16 +08:00
|
|
|
int accnum;
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
rx = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
accnum = (insn >> 9) & 3;
|
|
|
|
acc = MACREG(accnum);
|
2007-05-29 22:57:59 +08:00
|
|
|
if (s->env->macsr & MACSR_FI) {
|
2008-11-17 22:43:54 +08:00
|
|
|
gen_helper_get_macf(rx, cpu_env, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else if ((s->env->macsr & MACSR_OMC) == 0) {
|
2015-07-25 02:49:53 +08:00
|
|
|
tcg_gen_extrl_i64_i32(rx, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else if (s->env->macsr & MACSR_SU) {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_get_macs(rx, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_get_macu(rx, acc);
|
|
|
|
}
|
|
|
|
if (insn & 0x40) {
|
|
|
|
tcg_gen_movi_i64(acc, 0);
|
|
|
|
tcg_gen_andi_i32(QREG_MACSR, QREG_MACSR, ~(MACSR_PAV0 << accnum));
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_mac)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
/* FIXME: This can be done without a helper. */
|
2007-05-29 22:57:59 +08:00
|
|
|
int src;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv dest;
|
2007-05-29 22:57:59 +08:00
|
|
|
src = insn & 3;
|
2008-05-25 06:29:16 +08:00
|
|
|
dest = tcg_const_i32((insn >> 9) & 3);
|
|
|
|
gen_helper_mac_move(cpu_env, dest, tcg_const_i32(src));
|
|
|
|
gen_mac_clear_flags();
|
|
|
|
gen_helper_mac_set_flags(cpu_env, dest);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_macsr)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2007-05-29 22:57:59 +08:00
|
|
|
|
|
|
|
reg = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, QREG_MACSR);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_mask)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
2007-05-29 22:57:59 +08:00
|
|
|
reg = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_mov_i32(reg, QREG_MAC_MASK);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_mext)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv reg;
|
|
|
|
TCGv acc;
|
2007-05-29 22:57:59 +08:00
|
|
|
reg = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 06:29:16 +08:00
|
|
|
acc = tcg_const_i32((insn & 0x400) ? 2 : 0);
|
2007-05-29 22:57:59 +08:00
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_get_mac_extf(reg, cpu_env, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_get_mac_exti(reg, cpu_env, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(macsr_to_ccr)
|
|
|
|
{
|
2015-08-14 22:59:20 +08:00
|
|
|
TCGv tmp = tcg_temp_new();
|
|
|
|
tcg_gen_andi_i32(tmp, QREG_MACSR, 0xf);
|
|
|
|
gen_helper_set_sr(cpu_env, tmp);
|
|
|
|
tcg_temp_free(tmp);
|
2015-08-09 07:44:24 +08:00
|
|
|
set_cc_op(s, CC_OP_FLAGS);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_mac)
|
|
|
|
{
|
2008-11-17 22:43:54 +08:00
|
|
|
TCGv_i64 acc;
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv val;
|
|
|
|
int accnum;
|
|
|
|
accnum = (insn >> 9) & 3;
|
|
|
|
acc = MACREG(accnum);
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, val, OS_LONG, 0, NULL);
|
2007-05-29 22:57:59 +08:00
|
|
|
if (s->env->macsr & MACSR_FI) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext_i32_i64(acc, val);
|
|
|
|
tcg_gen_shli_i64(acc, acc, 8);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else if (s->env->macsr & MACSR_SU) {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ext_i32_i64(acc, val);
|
2007-05-29 22:57:59 +08:00
|
|
|
} else {
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_extu_i32_i64(acc, val);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_andi_i32(QREG_MACSR, QREG_MACSR, ~(MACSR_PAV0 << accnum));
|
|
|
|
gen_mac_clear_flags();
|
|
|
|
gen_helper_mac_set_flags(cpu_env, tcg_const_i32(accnum));
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_macsr)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv val;
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, val, OS_LONG, 0, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_set_macsr(cpu_env, val);
|
2007-05-29 22:57:59 +08:00
|
|
|
gen_lookup_tb(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_mask)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv val;
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, val, OS_LONG, 0, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_ori_i32(QREG_MAC_MASK, val, 0xffff0000);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_mext)
|
|
|
|
{
|
2008-05-25 06:29:16 +08:00
|
|
|
TCGv val;
|
|
|
|
TCGv acc;
|
2012-09-08 18:48:20 +08:00
|
|
|
SRC_EA(env, val, OS_LONG, 0, NULL);
|
2008-05-25 06:29:16 +08:00
|
|
|
acc = tcg_const_i32((insn & 0x400) ? 2 : 0);
|
2007-05-29 22:57:59 +08:00
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_set_mac_extf(cpu_env, val, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
else if (s->env->macsr & MACSR_SU)
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_set_mac_exts(cpu_env, val, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
else
|
2008-05-25 06:29:16 +08:00
|
|
|
gen_helper_set_mac_extu(cpu_env, val, acc);
|
2007-05-29 22:57:59 +08:00
|
|
|
}
|
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
static disas_proc opcode_table[65536];
|
|
|
|
|
|
|
|
static void
|
|
|
|
register_opcode (disas_proc proc, uint16_t opcode, uint16_t mask)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int from;
|
|
|
|
int to;
|
|
|
|
|
|
|
|
/* Sanity check. All set bits must be included in the mask. */
|
2007-05-28 09:46:43 +08:00
|
|
|
if (opcode & ~mask) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"qemu internal error: bogus opcode definition %04x/%04x\n",
|
|
|
|
opcode, mask);
|
2006-10-22 08:18:54 +08:00
|
|
|
abort();
|
2007-05-28 09:46:43 +08:00
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
/* This could probably be cleverer. For now just optimize the case where
|
|
|
|
the top bits are known. */
|
|
|
|
/* Find the first zero bit in the mask. */
|
|
|
|
i = 0x8000;
|
|
|
|
while ((i & mask) != 0)
|
|
|
|
i >>= 1;
|
|
|
|
/* Iterate over all combinations of this and lower bits. */
|
|
|
|
if (i == 0)
|
|
|
|
i = 1;
|
|
|
|
else
|
|
|
|
i <<= 1;
|
|
|
|
from = opcode & ~(i - 1);
|
|
|
|
to = from + i;
|
2007-05-24 03:58:11 +08:00
|
|
|
for (i = from; i < to; i++) {
|
2006-10-22 08:18:54 +08:00
|
|
|
if ((i & mask) == opcode)
|
|
|
|
opcode_table[i] = proc;
|
2007-05-24 03:58:11 +08:00
|
|
|
}
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Register m68k opcode handlers. Order is important.
|
|
|
|
Later insn override earlier ones. */
|
2007-05-27 00:52:21 +08:00
|
|
|
void register_m68k_insns (CPUM68KState *env)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2016-02-03 17:22:35 +08:00
|
|
|
/* Build the opcode table only once to avoid
|
|
|
|
multithreading issues. */
|
|
|
|
if (opcode_table[0] != NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-24 02:55:08 +08:00
|
|
|
|
|
|
|
/* use BASE() for instruction available
|
|
|
|
* for CF_ISA_A and M68000.
|
|
|
|
*/
|
|
|
|
#define BASE(name, opcode, mask) \
|
|
|
|
register_opcode(disas_##name, 0x##opcode, 0x##mask)
|
2007-06-03 20:35:08 +08:00
|
|
|
#define INSN(name, opcode, mask, feature) do { \
|
2007-05-27 00:52:21 +08:00
|
|
|
if (m68k_feature(env, M68K_FEATURE_##feature)) \
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(name, opcode, mask); \
|
2007-06-03 20:35:08 +08:00
|
|
|
} while(0)
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(undef, 0000, 0000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(arith_im, 0080, fff8, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(arith_im, 0000, ff00, M68000);
|
|
|
|
INSN(undef, 00c0, ffc0, M68000);
|
2007-06-03 20:35:08 +08:00
|
|
|
INSN(bitrev, 00c0, fff8, CF_ISA_APLUSC);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(bitop_reg, 0100, f1c0);
|
|
|
|
BASE(bitop_reg, 0140, f1c0);
|
|
|
|
BASE(bitop_reg, 0180, f1c0);
|
|
|
|
BASE(bitop_reg, 01c0, f1c0);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(arith_im, 0280, fff8, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(arith_im, 0200, ff00, M68000);
|
|
|
|
INSN(undef, 02c0, ffc0, M68000);
|
2007-06-03 20:35:08 +08:00
|
|
|
INSN(byterev, 02c0, fff8, CF_ISA_APLUSC);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(arith_im, 0480, fff8, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(arith_im, 0400, ff00, M68000);
|
|
|
|
INSN(undef, 04c0, ffc0, M68000);
|
|
|
|
INSN(arith_im, 0600, ff00, M68000);
|
|
|
|
INSN(undef, 06c0, ffc0, M68000);
|
2007-06-03 20:35:08 +08:00
|
|
|
INSN(ff1, 04c0, fff8, CF_ISA_APLUSC);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(arith_im, 0680, fff8, CF_ISA_A);
|
|
|
|
INSN(arith_im, 0c00, ff38, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(arith_im, 0c00, ff00, M68000);
|
|
|
|
BASE(bitop_im, 0800, ffc0);
|
|
|
|
BASE(bitop_im, 0840, ffc0);
|
|
|
|
BASE(bitop_im, 0880, ffc0);
|
|
|
|
BASE(bitop_im, 08c0, ffc0);
|
|
|
|
INSN(arith_im, 0a80, fff8, CF_ISA_A);
|
|
|
|
INSN(arith_im, 0a00, ff00, M68000);
|
|
|
|
BASE(move, 1000, f000);
|
|
|
|
BASE(move, 2000, f000);
|
|
|
|
BASE(move, 3000, f000);
|
2007-06-03 20:35:08 +08:00
|
|
|
INSN(strldsr, 40e7, ffff, CF_ISA_APLUSC);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(negx, 4080, fff8, CF_ISA_A);
|
2015-08-14 22:59:26 +08:00
|
|
|
INSN(negx, 4000, ff00, M68000);
|
|
|
|
INSN(undef, 40c0, ffc0, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(move_from_sr, 40c0, fff8, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(move_from_sr, 40c0, ffc0, M68000);
|
|
|
|
BASE(lea, 41c0, f1c0);
|
|
|
|
BASE(clr, 4200, ff00);
|
|
|
|
BASE(undef, 42c0, ffc0);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(move_from_ccr, 42c0, fff8, CF_ISA_A);
|
2016-01-18 01:55:13 +08:00
|
|
|
INSN(move_from_ccr, 42c0, ffc0, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(neg, 4480, fff8, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(neg, 4400, ff00, M68000);
|
|
|
|
INSN(undef, 44c0, ffc0, M68000);
|
|
|
|
BASE(move_to_ccr, 44c0, ffc0);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(not, 4680, fff8, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(not, 4600, ff00, M68000);
|
|
|
|
INSN(undef, 46c0, ffc0, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(move_to_sr, 46c0, ffc0, CF_ISA_A);
|
2016-01-13 03:44:21 +08:00
|
|
|
INSN(linkl, 4808, fff8, M68000);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(pea, 4840, ffc0);
|
|
|
|
BASE(swap, 4840, fff8);
|
2016-01-17 08:13:07 +08:00
|
|
|
INSN(bkpt, 4848, fff8, BKPT);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(movem, 48c0, fbc0);
|
|
|
|
BASE(ext, 4880, fff8);
|
|
|
|
BASE(ext, 48c0, fff8);
|
|
|
|
BASE(ext, 49c0, fff8);
|
|
|
|
BASE(tst, 4a00, ff00);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(tas, 4ac0, ffc0, CF_ISA_B);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(tas, 4ac0, ffc0, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(halt, 4ac8, ffff, CF_ISA_A);
|
|
|
|
INSN(pulse, 4acc, ffff, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(illegal, 4afc, ffff);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(mull, 4c00, ffc0, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(mull, 4c00, ffc0, LONG_MULDIV);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(divl, 4c40, ffc0, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(divl, 4c40, ffc0, LONG_MULDIV);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(sats, 4c80, fff8, CF_ISA_B);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(trap, 4e40, fff0);
|
|
|
|
BASE(link, 4e50, fff8);
|
|
|
|
BASE(unlk, 4e58, fff8);
|
2007-06-03 19:13:39 +08:00
|
|
|
INSN(move_to_usp, 4e60, fff8, USP);
|
|
|
|
INSN(move_from_usp, 4e68, fff8, USP);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(nop, 4e71, ffff);
|
|
|
|
BASE(stop, 4e72, ffff);
|
|
|
|
BASE(rte, 4e73, ffff);
|
|
|
|
BASE(rts, 4e75, ffff);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(movec, 4e7b, ffff, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(jump, 4e80, ffc0);
|
2016-01-17 07:57:01 +08:00
|
|
|
BASE(jump, 4ec0, ffc0);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(addsubq, 5000, f080, M68000);
|
2016-01-17 07:57:01 +08:00
|
|
|
BASE(addsubq, 5080, f0c0);
|
2016-01-11 06:53:20 +08:00
|
|
|
INSN(scc, 50c0, f0f8, CF_ISA_A); /* Scc.B Dx */
|
|
|
|
INSN(scc, 50c0, f0c0, M68000); /* Scc.B <EA> */
|
2016-01-11 06:53:20 +08:00
|
|
|
INSN(dbcc, 50c8, f0f8, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(tpf, 51f8, fff8, CF_ISA_A);
|
2007-06-03 20:35:08 +08:00
|
|
|
|
|
|
|
/* Branch instructions. */
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(branch, 6000, f000);
|
2007-06-03 20:35:08 +08:00
|
|
|
/* Disable long branch instructions, then add back the ones we want. */
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(undef, 60ff, f0ff); /* All long branches. */
|
2007-06-03 20:35:08 +08:00
|
|
|
INSN(branch, 60ff, f0ff, CF_ISA_B);
|
|
|
|
INSN(undef, 60ff, ffff, CF_ISA_B); /* bra.l */
|
|
|
|
INSN(branch, 60ff, ffff, BRAL);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(branch, 60ff, f0ff, BCCL);
|
2007-06-03 20:35:08 +08:00
|
|
|
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(moveq, 7000, f100);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(mvzs, 7100, f100, CF_ISA_B);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(or, 8000, f000);
|
|
|
|
BASE(divw, 80c0, f0c0);
|
|
|
|
BASE(addsub, 9000, f000);
|
2015-08-14 22:59:26 +08:00
|
|
|
INSN(undef, 90c0, f0c0, CF_ISA_A);
|
|
|
|
INSN(subx_reg, 9180, f1f8, CF_ISA_A);
|
|
|
|
INSN(subx_reg, 9100, f138, M68000);
|
|
|
|
INSN(subx_mem, 9108, f138, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(suba, 91c0, f1c0, CF_ISA_A);
|
2016-01-17 06:33:43 +08:00
|
|
|
INSN(suba, 90c0, f0c0, M68000);
|
2007-05-29 22:57:59 +08:00
|
|
|
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(undef_mac, a000, f000);
|
2007-05-29 22:57:59 +08:00
|
|
|
INSN(mac, a000, f100, CF_EMAC);
|
|
|
|
INSN(from_mac, a180, f9b0, CF_EMAC);
|
|
|
|
INSN(move_mac, a110, f9fc, CF_EMAC);
|
|
|
|
INSN(from_macsr,a980, f9f0, CF_EMAC);
|
|
|
|
INSN(from_mask, ad80, fff0, CF_EMAC);
|
|
|
|
INSN(from_mext, ab80, fbf0, CF_EMAC);
|
|
|
|
INSN(macsr_to_ccr, a9c0, ffff, CF_EMAC);
|
|
|
|
INSN(to_mac, a100, f9c0, CF_EMAC);
|
|
|
|
INSN(to_macsr, a900, ffc0, CF_EMAC);
|
|
|
|
INSN(to_mext, ab00, fbc0, CF_EMAC);
|
|
|
|
INSN(to_mask, ad00, ffc0, CF_EMAC);
|
|
|
|
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(mov3q, a140, f1c0, CF_ISA_B);
|
|
|
|
INSN(cmp, b000, f1c0, CF_ISA_B); /* cmp.b */
|
|
|
|
INSN(cmp, b040, f1c0, CF_ISA_B); /* cmp.w */
|
|
|
|
INSN(cmpa, b0c0, f1c0, CF_ISA_B); /* cmpa.w */
|
|
|
|
INSN(cmp, b080, f1c0, CF_ISA_A);
|
|
|
|
INSN(cmpa, b1c0, f1c0, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(cmp, b000, f100, M68000);
|
|
|
|
INSN(eor, b100, f100, M68000);
|
|
|
|
INSN(cmpa, b0c0, f0c0, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(eor, b180, f1c0, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(and, c000, f000);
|
2016-01-17 06:05:55 +08:00
|
|
|
INSN(exg_dd, c140, f1f8, M68000);
|
|
|
|
INSN(exg_aa, c148, f1f8, M68000);
|
|
|
|
INSN(exg_da, c188, f1f8, M68000);
|
2015-06-24 02:55:08 +08:00
|
|
|
BASE(mulw, c0c0, f0c0);
|
|
|
|
BASE(addsub, d000, f000);
|
2015-08-14 22:59:26 +08:00
|
|
|
INSN(undef, d0c0, f0c0, CF_ISA_A);
|
|
|
|
INSN(addx_reg, d180, f1f8, CF_ISA_A);
|
|
|
|
INSN(addx_reg, d100, f138, M68000);
|
|
|
|
INSN(addx_mem, d108, f138, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(adda, d1c0, f1c0, CF_ISA_A);
|
2015-06-24 02:55:08 +08:00
|
|
|
INSN(adda, d0c0, f0c0, M68000);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(shift_im, e080, f0f0, CF_ISA_A);
|
|
|
|
INSN(shift_reg, e0a0, f0f0, CF_ISA_A);
|
|
|
|
INSN(undef_fpu, f000, f000, CF_ISA_A);
|
2006-10-22 08:18:54 +08:00
|
|
|
INSN(fpu, f200, ffc0, CF_FPU);
|
|
|
|
INSN(fbcc, f280, ffc0, CF_FPU);
|
2007-05-24 03:58:11 +08:00
|
|
|
INSN(frestore, f340, ffc0, CF_FPU);
|
|
|
|
INSN(fsave, f340, ffc0, CF_FPU);
|
2007-05-27 00:52:21 +08:00
|
|
|
INSN(intouch, f340, ffc0, CF_ISA_A);
|
|
|
|
INSN(cpushl, f428, ff38, CF_ISA_A);
|
|
|
|
INSN(wddata, fb00, ff00, CF_ISA_A);
|
|
|
|
INSN(wdebug, fbc0, ffc0, CF_ISA_A);
|
2006-10-22 08:18:54 +08:00
|
|
|
#undef INSN
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ??? Some of this implementation is not exception safe. We should always
|
|
|
|
write back the result to memory before setting the condition codes. */
|
2012-03-14 08:38:22 +08:00
|
|
|
static void disas_m68k_insn(CPUM68KState * env, DisasContext *s)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2016-11-04 04:50:01 +08:00
|
|
|
uint16_t insn = read_im16(env, s);
|
2012-09-08 18:48:20 +08:00
|
|
|
opcode_table[insn](env, s, insn);
|
2016-11-04 04:50:01 +08:00
|
|
|
do_writebacks(s);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* generate intermediate code for basic block 'tb'. */
|
2015-09-02 11:01:40 +08:00
|
|
|
void gen_intermediate_code(CPUM68KState *env, TranslationBlock *tb)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2015-09-02 11:01:40 +08:00
|
|
|
M68kCPU *cpu = m68k_env_get_cpu(env);
|
2013-06-22 02:20:45 +08:00
|
|
|
CPUState *cs = CPU(cpu);
|
2006-10-22 08:18:54 +08:00
|
|
|
DisasContext dc1, *dc = &dc1;
|
|
|
|
target_ulong pc_start;
|
|
|
|
int pc_offset;
|
2008-06-29 09:03:05 +08:00
|
|
|
int num_insns;
|
|
|
|
int max_insns;
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
/* generate intermediate code */
|
|
|
|
pc_start = tb->pc;
|
2007-09-17 16:09:54 +08:00
|
|
|
|
2006-10-22 08:18:54 +08:00
|
|
|
dc->tb = tb;
|
|
|
|
|
2007-05-27 05:16:48 +08:00
|
|
|
dc->env = env;
|
2006-10-22 08:18:54 +08:00
|
|
|
dc->is_jmp = DISAS_NEXT;
|
|
|
|
dc->pc = pc_start;
|
|
|
|
dc->cc_op = CC_OP_DYNAMIC;
|
2015-08-14 22:59:20 +08:00
|
|
|
dc->cc_op_synced = 1;
|
2013-06-22 02:20:45 +08:00
|
|
|
dc->singlestep_enabled = cs->singlestep_enabled;
|
2006-10-22 08:18:54 +08:00
|
|
|
dc->fpcr = env->fpcr;
|
2007-05-24 03:58:11 +08:00
|
|
|
dc->user = (env->sr & SR_S) == 0;
|
2008-11-17 22:43:54 +08:00
|
|
|
dc->done_mac = 0;
|
2016-11-04 04:50:01 +08:00
|
|
|
dc->writeback_mask = 0;
|
2008-06-29 09:03:05 +08:00
|
|
|
num_insns = 0;
|
|
|
|
max_insns = tb->cflags & CF_COUNT_MASK;
|
2015-09-01 05:34:41 +08:00
|
|
|
if (max_insns == 0) {
|
2008-06-29 09:03:05 +08:00
|
|
|
max_insns = CF_COUNT_MASK;
|
2015-09-01 05:34:41 +08:00
|
|
|
}
|
|
|
|
if (max_insns > TCG_MAX_INSNS) {
|
|
|
|
max_insns = TCG_MAX_INSNS;
|
|
|
|
}
|
2008-06-29 09:03:05 +08:00
|
|
|
|
2014-11-26 18:40:05 +08:00
|
|
|
gen_tb_start(tb);
|
2006-10-22 08:18:54 +08:00
|
|
|
do {
|
|
|
|
pc_offset = dc->pc - pc_start;
|
|
|
|
gen_throws_exception = NULL;
|
2015-08-09 07:44:24 +08:00
|
|
|
tcg_gen_insn_start(dc->pc, dc->cc_op);
|
2015-09-18 05:25:46 +08:00
|
|
|
num_insns++;
|
2015-08-30 03:59:29 +08:00
|
|
|
|
2015-09-18 06:58:10 +08:00
|
|
|
if (unlikely(cpu_breakpoint_test(cs, dc->pc, BP_ANY))) {
|
|
|
|
gen_exception(dc, dc->pc, EXCP_DEBUG);
|
|
|
|
dc->is_jmp = DISAS_JUMP;
|
2015-10-14 06:07:49 +08:00
|
|
|
/* The address covered by the breakpoint must be included in
|
|
|
|
[tb->pc, tb->pc + tb->size) in order to for it to be
|
|
|
|
properly cleared -- thus we increment the PC here so that
|
|
|
|
the logic setting tb->size below does the right thing. */
|
|
|
|
dc->pc += 2;
|
2015-09-18 06:58:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:25:46 +08:00
|
|
|
if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {
|
2008-06-29 09:03:05 +08:00
|
|
|
gen_io_start();
|
2015-08-30 03:59:29 +08:00
|
|
|
}
|
|
|
|
|
2007-05-27 06:11:13 +08:00
|
|
|
dc->insn_pc = dc->pc;
|
2006-10-22 08:18:54 +08:00
|
|
|
disas_m68k_insn(env, dc);
|
2014-03-31 06:36:56 +08:00
|
|
|
} while (!dc->is_jmp && !tcg_op_buf_full() &&
|
2013-06-22 02:20:45 +08:00
|
|
|
!cs->singlestep_enabled &&
|
2009-04-06 04:08:59 +08:00
|
|
|
!singlestep &&
|
2008-06-29 09:03:05 +08:00
|
|
|
(pc_offset) < (TARGET_PAGE_SIZE - 32) &&
|
|
|
|
num_insns < max_insns);
|
2006-10-22 08:18:54 +08:00
|
|
|
|
2008-06-29 09:03:05 +08:00
|
|
|
if (tb->cflags & CF_LAST_IO)
|
|
|
|
gen_io_end();
|
2013-06-22 02:20:45 +08:00
|
|
|
if (unlikely(cs->singlestep_enabled)) {
|
2006-10-22 08:18:54 +08:00
|
|
|
/* Make sure the pc is updated, and raise a debug exception. */
|
|
|
|
if (!dc->is_jmp) {
|
2015-08-09 07:44:24 +08:00
|
|
|
update_cc_op(dc);
|
2008-05-25 06:29:16 +08:00
|
|
|
tcg_gen_movi_i32(QREG_PC, dc->pc);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
2012-09-02 15:27:38 +08:00
|
|
|
gen_helper_raise_exception(cpu_env, tcg_const_i32(EXCP_DEBUG));
|
2006-10-22 08:18:54 +08:00
|
|
|
} else {
|
|
|
|
switch(dc->is_jmp) {
|
|
|
|
case DISAS_NEXT:
|
2015-08-09 07:44:24 +08:00
|
|
|
update_cc_op(dc);
|
2006-10-22 08:18:54 +08:00
|
|
|
gen_jmp_tb(dc, 0, dc->pc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case DISAS_JUMP:
|
|
|
|
case DISAS_UPDATE:
|
2015-08-09 07:44:24 +08:00
|
|
|
update_cc_op(dc);
|
2006-10-22 08:18:54 +08:00
|
|
|
/* indicate that the hash table must be used to find the next TB */
|
2008-02-01 18:50:11 +08:00
|
|
|
tcg_gen_exit_tb(0);
|
2006-10-22 08:18:54 +08:00
|
|
|
break;
|
|
|
|
case DISAS_TB_JUMP:
|
|
|
|
/* nothing more to generate */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 02:10:05 +08:00
|
|
|
gen_tb_end(tb, num_insns);
|
2006-10-22 08:18:54 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG_DISAS
|
2016-04-21 02:39:35 +08:00
|
|
|
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
|
|
|
|
&& qemu_log_in_addr_range(pc_start)) {
|
2016-09-23 06:17:10 +08:00
|
|
|
qemu_log_lock();
|
2009-01-16 06:34:14 +08:00
|
|
|
qemu_log("----------------\n");
|
|
|
|
qemu_log("IN: %s\n", lookup_symbol(pc_start));
|
2015-05-25 05:20:41 +08:00
|
|
|
log_target_disas(cs, pc_start, dc->pc - pc_start, 0);
|
2009-01-16 06:34:14 +08:00
|
|
|
qemu_log("\n");
|
2016-09-23 06:17:10 +08:00
|
|
|
qemu_log_unlock();
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
#endif
|
2015-09-02 11:01:40 +08:00
|
|
|
tb->size = dc->pc - pc_start;
|
|
|
|
tb->icount = num_insns;
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2013-05-27 07:33:50 +08:00
|
|
|
void m68k_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
|
|
|
|
int flags)
|
2006-10-22 08:18:54 +08:00
|
|
|
{
|
2013-05-27 07:33:50 +08:00
|
|
|
M68kCPU *cpu = M68K_CPU(cs);
|
|
|
|
CPUM68KState *env = &cpu->env;
|
2006-10-22 08:18:54 +08:00
|
|
|
int i;
|
|
|
|
uint16_t sr;
|
|
|
|
CPU_DoubleU u;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
u.d = env->fregs[i];
|
2015-08-14 22:59:16 +08:00
|
|
|
cpu_fprintf(f, "D%d = %08x A%d = %08x F%d = %08x%08x (%12g)\n",
|
|
|
|
i, env->dregs[i], i, env->aregs[i],
|
|
|
|
i, u.l.upper, u.l.lower, *(double *)&u.d);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
cpu_fprintf (f, "PC = %08x ", env->pc);
|
2015-08-14 22:59:17 +08:00
|
|
|
sr = env->sr | cpu_m68k_get_ccr(env);
|
2015-08-14 22:59:16 +08:00
|
|
|
cpu_fprintf(f, "SR = %04x %c%c%c%c%c ", sr, (sr & CCF_X) ? 'X' : '-',
|
|
|
|
(sr & CCF_N) ? 'N' : '-', (sr & CCF_Z) ? 'Z' : '-',
|
|
|
|
(sr & CCF_V) ? 'V' : '-', (sr & CCF_C) ? 'C' : '-');
|
2007-11-11 01:43:49 +08:00
|
|
|
cpu_fprintf (f, "FPRESULT = %12g\n", *(double *)&env->fp_result);
|
2006-10-22 08:18:54 +08:00
|
|
|
}
|
|
|
|
|
2015-09-02 06:51:12 +08:00
|
|
|
void restore_state_to_opc(CPUM68KState *env, TranslationBlock *tb,
|
|
|
|
target_ulong *data)
|
2008-04-28 08:32:32 +08:00
|
|
|
{
|
2015-08-09 07:44:24 +08:00
|
|
|
int cc_op = data[1];
|
2015-09-02 06:51:12 +08:00
|
|
|
env->pc = data[0];
|
2015-08-09 07:44:24 +08:00
|
|
|
if (cc_op != CC_OP_DYNAMIC) {
|
|
|
|
env->cc_op = cc_op;
|
|
|
|
}
|
2008-04-28 08:32:32 +08:00
|
|
|
}
|