2006-10-22 04:18:54 +04:00
|
|
|
/*
|
|
|
|
* m68k translation
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-05-23 23:58:11 +04:00
|
|
|
* Copyright (c) 2005-2007 CodeSourcery
|
2006-10-22 04:18:54 +04: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
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
2008-05-25 02:29:16 +04:00
|
|
|
#include <assert.h>
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "exec-all.h"
|
|
|
|
#include "disas.h"
|
2008-02-01 13:50:11 +03:00
|
|
|
#include "tcg-op.h"
|
2008-08-30 13:51:20 +04:00
|
|
|
#include "qemu-log.h"
|
2008-05-25 02:29:16 +04:00
|
|
|
|
|
|
|
#define GEN_HELPER 1
|
|
|
|
#include "helpers.h"
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
//#define DEBUG_DISPATCH 1
|
|
|
|
|
2008-07-10 21:17:54 +04:00
|
|
|
/* Fake floating point. */
|
|
|
|
#define TCG_TYPE_F32 TCG_TYPE_I32
|
|
|
|
#define TCG_TYPE_F64 TCG_TYPE_I64
|
|
|
|
#define tcg_gen_mov_f64 tcg_gen_mov_i64
|
|
|
|
#define tcg_gen_qemu_ldf32 tcg_gen_qemu_ld32u
|
|
|
|
#define tcg_gen_qemu_ldf64 tcg_gen_qemu_ld64
|
|
|
|
#define tcg_gen_qemu_stf32 tcg_gen_qemu_st32
|
|
|
|
#define tcg_gen_qemu_stf64 tcg_gen_qemu_st64
|
|
|
|
#define gen_helper_pack_32_f32 tcg_gen_mov_i32
|
|
|
|
#define gen_helper_pack_f32_32 tcg_gen_mov_i32
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
#define DEFO32(name, offset) static TCGv QREG_##name;
|
|
|
|
#define DEFO64(name, offset) static TCGv QREG_##name;
|
|
|
|
#define DEFF64(name, offset) static TCGv QREG_##name;
|
|
|
|
#include "qregs.def"
|
|
|
|
#undef DEFO32
|
|
|
|
#undef DEFO64
|
|
|
|
#undef DEFF64
|
|
|
|
|
|
|
|
static TCGv cpu_env;
|
|
|
|
|
|
|
|
static char cpu_reg_names[3*8*3 + 5*4];
|
|
|
|
static TCGv cpu_dregs[8];
|
|
|
|
static TCGv cpu_aregs[8];
|
|
|
|
static TCGv cpu_fregs[8];
|
|
|
|
static TCGv cpu_macc[4];
|
|
|
|
|
|
|
|
#define DREG(insn, pos) cpu_dregs[((insn) >> (pos)) & 7]
|
|
|
|
#define AREG(insn, pos) cpu_aregs[((insn) >> (pos)) & 7]
|
|
|
|
#define FREG(insn, pos) cpu_fregs[((insn) >> (pos)) & 7]
|
|
|
|
#define MACREG(acc) cpu_macc[acc]
|
|
|
|
#define QREG_SP cpu_aregs[7]
|
|
|
|
|
|
|
|
static TCGv NULL_QREG;
|
|
|
|
#define IS_NULL_QREG(t) (GET_TCGV(t) == GET_TCGV(NULL_QREG))
|
|
|
|
/* Used to distinguish stores from bad addressing modes. */
|
|
|
|
static TCGv store_dummy;
|
|
|
|
|
2008-06-29 05:03:05 +04:00
|
|
|
#include "gen-icount.h"
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
void m68k_tcg_init(void)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define DEFO32(name, offset) QREG_##name = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, offset), #name);
|
|
|
|
#define DEFO64(name, offset) QREG_##name = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, offset), #name);
|
|
|
|
#define DEFF64(name, offset) DEFO64(name, offset)
|
|
|
|
#include "qregs.def"
|
|
|
|
#undef DEFO32
|
|
|
|
#undef DEFO64
|
|
|
|
#undef DEFF64
|
|
|
|
|
|
|
|
cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
|
|
|
|
|
|
|
|
p = cpu_reg_names;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
sprintf(p, "D%d", i);
|
|
|
|
cpu_dregs[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
|
|
|
|
offsetof(CPUM68KState, dregs[i]), p);
|
|
|
|
p += 3;
|
|
|
|
sprintf(p, "A%d", i);
|
|
|
|
cpu_aregs[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
|
|
|
|
offsetof(CPUM68KState, aregs[i]), p);
|
|
|
|
p += 3;
|
|
|
|
sprintf(p, "F%d", i);
|
2008-07-10 21:17:54 +04:00
|
|
|
cpu_fregs[i] = tcg_global_mem_new(TCG_TYPE_F64, TCG_AREG0,
|
2008-05-25 02:29:16 +04:00
|
|
|
offsetof(CPUM68KState, fregs[i]), p);
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
sprintf(p, "ACC%d", i);
|
2008-07-10 21:17:54 +04:00
|
|
|
cpu_macc[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
|
2008-05-25 02:29:16 +04:00
|
|
|
offsetof(CPUM68KState, macc[i]), p);
|
|
|
|
p += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
NULL_QREG = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, -4, "NULL");
|
|
|
|
store_dummy = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, -8, "NULL");
|
|
|
|
|
|
|
|
#define DEF_HELPER(name, ret, args) \
|
|
|
|
tcg_register_helper(HELPER(name), #name);
|
|
|
|
#include "helpers.h"
|
|
|
|
}
|
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
static inline void qemu_assert(int cond, const char *msg)
|
|
|
|
{
|
|
|
|
if (!cond) {
|
|
|
|
fprintf (stderr, "badness: %s\n", msg);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal defines */
|
|
|
|
typedef struct DisasContext {
|
2007-05-27 01:16:48 +04:00
|
|
|
CPUM68KState *env;
|
2007-05-27 02:11:13 +04:00
|
|
|
target_ulong insn_pc; /* Start of the current instruction. */
|
2006-10-22 04:18:54 +04:00
|
|
|
target_ulong pc;
|
|
|
|
int is_jmp;
|
|
|
|
int cc_op;
|
2007-05-23 23:58:11 +04:00
|
|
|
int user;
|
2006-10-22 04:18:54 +04:00
|
|
|
uint32_t fpcr;
|
|
|
|
struct TranslationBlock *tb;
|
|
|
|
int singlestep_enabled;
|
2007-06-10 01:30:14 +04:00
|
|
|
int is_mem;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv mactmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
} DisasContext;
|
|
|
|
|
|
|
|
#define DISAS_JUMP_NEXT 4
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
#define IS_USER(s) 1
|
|
|
|
#else
|
|
|
|
#define IS_USER(s) s->user
|
|
|
|
#endif
|
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
/* XXX: move that elsewhere */
|
|
|
|
/* ??? Fix exceptions. */
|
|
|
|
static void *gen_throws_exception;
|
|
|
|
#define gen_last_qop NULL
|
|
|
|
|
|
|
|
#define OS_BYTE 0
|
|
|
|
#define OS_WORD 1
|
|
|
|
#define OS_LONG 2
|
|
|
|
#define OS_SINGLE 4
|
|
|
|
#define OS_DOUBLE 5
|
|
|
|
|
|
|
|
typedef void (*disas_proc)(DisasContext *, uint16_t);
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
#ifdef DEBUG_DISPATCH
|
|
|
|
#define DISAS_INSN(name) \
|
|
|
|
static void real_disas_##name (DisasContext *s, uint16_t insn); \
|
|
|
|
static void disas_##name (DisasContext *s, uint16_t insn) { \
|
|
|
|
if (logfile) fprintf(logfile, "Dispatch " #name "\n"); \
|
|
|
|
real_disas_##name(s, insn); } \
|
|
|
|
static void real_disas_##name (DisasContext *s, uint16_t insn)
|
|
|
|
#else
|
2006-10-22 04:18:54 +04:00
|
|
|
#define DISAS_INSN(name) \
|
|
|
|
static void disas_##name (DisasContext *s, uint16_t insn)
|
2007-05-23 23:58:11 +04:00
|
|
|
#endif
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
/* FIXME: Remove this. */
|
|
|
|
#define gen_im32(val) tcg_const_i32(val)
|
|
|
|
|
|
|
|
#define QMODE_I32 TCG_TYPE_I32
|
|
|
|
#define QMODE_I64 TCG_TYPE_I64
|
|
|
|
#define QMODE_F32 TCG_TYPE_F32
|
|
|
|
#define QMODE_F64 TCG_TYPE_F64
|
|
|
|
static inline TCGv gen_new_qreg(int mode)
|
|
|
|
{
|
|
|
|
return tcg_temp_new(mode);
|
|
|
|
}
|
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
/* Generate a load from the specified address. Narrow values are
|
|
|
|
sign extended to full register width. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static inline TCGv gen_load(DisasContext * s, int opsize, TCGv addr, int sign)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
|
|
|
int index = IS_USER(s);
|
2007-06-10 01:30:14 +04:00
|
|
|
s->is_mem = 1;
|
2006-10-22 04:18:54 +04:00
|
|
|
switch(opsize) {
|
|
|
|
case OS_BYTE:
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if (sign)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_ld8s(tmp, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_ld8u(tmp, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if (sign)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_ld16s(tmp, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_ld16u(tmp, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_ld32u(tmp, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_SINGLE:
|
|
|
|
tmp = gen_new_qreg(QMODE_F32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_ldf32(tmp, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_DOUBLE:
|
|
|
|
tmp = gen_new_qreg(QMODE_F64);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_ldf64(tmp, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_assert(0, "bad load size");
|
|
|
|
}
|
|
|
|
gen_throws_exception = gen_last_qop;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate a store. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static inline void gen_store(DisasContext *s, int opsize, TCGv addr, TCGv val)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
int index = IS_USER(s);
|
2007-06-10 01:30:14 +04:00
|
|
|
s->is_mem = 1;
|
2006-10-22 04:18:54 +04:00
|
|
|
switch(opsize) {
|
|
|
|
case OS_BYTE:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_st8(val, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_st16(val, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_st32(val, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_SINGLE:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_stf32(val, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_DOUBLE:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_qemu_stf64(val, addr, index);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_assert(0, "bad store size");
|
|
|
|
}
|
|
|
|
gen_throws_exception = gen_last_qop;
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
typedef enum {
|
|
|
|
EA_STORE,
|
|
|
|
EA_LOADU,
|
|
|
|
EA_LOADS
|
|
|
|
} ea_what;
|
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
/* Generate an unsigned load if VAL is 0 a signed load if val is -1,
|
|
|
|
otherwise generate a store. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static TCGv gen_ldst(DisasContext *s, int opsize, TCGv addr, TCGv val,
|
|
|
|
ea_what what)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
if (what == EA_STORE) {
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_store(s, opsize, addr, val);
|
2008-05-25 02:29:16 +04:00
|
|
|
return store_dummy;
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
return gen_load(s, opsize, addr, what == EA_LOADS);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-27 01:16:48 +04:00
|
|
|
/* Read a 32-bit immediate constant. */
|
|
|
|
static inline uint32_t read_im32(DisasContext *s)
|
|
|
|
{
|
|
|
|
uint32_t im;
|
|
|
|
im = ((uint32_t)lduw_code(s->pc)) << 16;
|
|
|
|
s->pc += 2;
|
|
|
|
im |= lduw_code(s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
return im;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate and address index. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static TCGv gen_addr_index(uint16_t ext, TCGv tmp)
|
2007-05-27 01:16:48 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv add;
|
2007-05-27 01:16:48 +04:00
|
|
|
int scale;
|
|
|
|
|
|
|
|
add = (ext & 0x8000) ? AREG(ext, 12) : DREG(ext, 12);
|
|
|
|
if ((ext & 0x800) == 0) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16s_i32(tmp, add);
|
2007-05-27 01:16:48 +04:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
scale = (ext >> 9) & 3;
|
|
|
|
if (scale != 0) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shli_i32(tmp, add, scale);
|
2007-05-27 01:16:48 +04:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
return add;
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
/* Handle a base + index + displacement effective addresss.
|
|
|
|
A NULL_QREG base means pc-relative. */
|
|
|
|
static TCGv gen_lea_indexed(DisasContext *s, int opsize, TCGv base)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
|
|
|
uint32_t offset;
|
|
|
|
uint16_t ext;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv add;
|
|
|
|
TCGv tmp;
|
2007-05-27 01:16:48 +04:00
|
|
|
uint32_t bd, od;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
offset = s->pc;
|
2007-05-23 23:58:11 +04:00
|
|
|
ext = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
2007-05-27 01:16:48 +04:00
|
|
|
|
|
|
|
if ((ext & 0x800) == 0 && !m68k_feature(s->env, M68K_FEATURE_WORD_INDEX))
|
2008-05-25 02:29:16 +04:00
|
|
|
return NULL_QREG;
|
2007-05-27 01:16:48 +04:00
|
|
|
|
|
|
|
if (ext & 0x100) {
|
|
|
|
/* full extension word format */
|
|
|
|
if (!m68k_feature(s->env, M68K_FEATURE_EXT_FULL))
|
2008-05-25 02:29:16 +04:00
|
|
|
return NULL_QREG;
|
2007-05-27 01:16:48 +04:00
|
|
|
|
|
|
|
if ((ext & 0x30) > 0x10) {
|
|
|
|
/* base displacement */
|
|
|
|
if ((ext & 0x30) == 0x20) {
|
|
|
|
bd = (int16_t)lduw_code(s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
} else {
|
|
|
|
bd = read_im32(s);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bd = 0;
|
|
|
|
}
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if ((ext & 0x44) == 0) {
|
|
|
|
/* pre-index */
|
|
|
|
add = gen_addr_index(ext, tmp);
|
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
add = NULL_QREG;
|
2007-05-27 01:16:48 +04:00
|
|
|
}
|
|
|
|
if ((ext & 0x80) == 0) {
|
|
|
|
/* base not suppressed */
|
2008-05-25 02:29:16 +04:00
|
|
|
if (IS_NULL_QREG(base)) {
|
2007-05-27 01:16:48 +04:00
|
|
|
base = gen_im32(offset + bd);
|
|
|
|
bd = 0;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
if (!IS_NULL_QREG(add)) {
|
|
|
|
tcg_gen_add_i32(tmp, add, base);
|
2007-05-27 01:16:48 +04:00
|
|
|
add = tmp;
|
|
|
|
} else {
|
|
|
|
add = base;
|
|
|
|
}
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
if (!IS_NULL_QREG(add)) {
|
2007-05-27 01:16:48 +04:00
|
|
|
if (bd != 0) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(tmp, add, bd);
|
2007-05-27 01:16:48 +04:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
add = gen_im32(bd);
|
|
|
|
}
|
|
|
|
if ((ext & 3) != 0) {
|
|
|
|
/* memory indirect */
|
|
|
|
base = gen_load(s, OS_LONG, add, 0);
|
|
|
|
if ((ext & 0x44) == 4) {
|
|
|
|
add = gen_addr_index(ext, tmp);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_add_i32(tmp, add, base);
|
2007-05-27 01:16:48 +04:00
|
|
|
add = tmp;
|
|
|
|
} else {
|
|
|
|
add = base;
|
|
|
|
}
|
|
|
|
if ((ext & 3) > 1) {
|
|
|
|
/* outer displacement */
|
|
|
|
if ((ext & 3) == 2) {
|
|
|
|
od = (int16_t)lduw_code(s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
} else {
|
|
|
|
od = read_im32(s);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
od = 0;
|
|
|
|
}
|
|
|
|
if (od != 0) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(tmp, add, od);
|
2007-05-27 01:16:48 +04:00
|
|
|
add = tmp;
|
|
|
|
}
|
|
|
|
}
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2007-05-27 01:16:48 +04:00
|
|
|
/* brief extension word format */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
add = gen_addr_index(ext, tmp);
|
2008-05-25 02:29:16 +04:00
|
|
|
if (!IS_NULL_QREG(base)) {
|
|
|
|
tcg_gen_add_i32(tmp, add, base);
|
2007-05-27 01:16:48 +04:00
|
|
|
if ((int8_t)ext)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(tmp, tmp, (int8_t)ext);
|
2007-05-27 01:16:48 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(tmp, add, offset + (int8_t)ext);
|
2007-05-27 01:16:48 +04:00
|
|
|
}
|
|
|
|
add = tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
2007-05-27 01:16:48 +04:00
|
|
|
return add;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the CPU env CC_OP state. */
|
|
|
|
static inline void gen_flush_cc_op(DisasContext *s)
|
|
|
|
{
|
|
|
|
if (s->cc_op != CC_OP_DYNAMIC)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_movi_i32(QREG_CC_OP, s->cc_op);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Evaluate all the CC flags. */
|
|
|
|
static inline void gen_flush_flags(DisasContext *s)
|
|
|
|
{
|
|
|
|
if (s->cc_op == CC_OP_FLAGS)
|
|
|
|
return;
|
2007-06-10 00:48:46 +04:00
|
|
|
gen_flush_cc_op(s);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_flush_flags(cpu_env, QREG_CC_OP);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_FLAGS;
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
static void gen_logic_cc(DisasContext *s, TCGv val)
|
|
|
|
{
|
|
|
|
tcg_gen_mov_i32(QREG_CC_DEST, val);
|
|
|
|
s->cc_op = CC_OP_LOGIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gen_update_cc_add(TCGv dest, TCGv src)
|
|
|
|
{
|
|
|
|
tcg_gen_mov_i32(QREG_CC_DEST, dest);
|
|
|
|
tcg_gen_mov_i32(QREG_CC_SRC, src);
|
|
|
|
}
|
|
|
|
|
2006-10-22 04:18:54 +04: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;
|
|
|
|
default:
|
|
|
|
qemu_assert(0, "bad operand size");
|
2008-10-05 15:47:55 +04:00
|
|
|
return 0;
|
2006-10-22 04:18:54 +04: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 02:29:16 +04:00
|
|
|
static void gen_partset_reg(int opsize, TCGv reg, TCGv val)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(reg, reg, 0xffffff00);
|
2006-10-22 04:18:54 +04:00
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext8u_i32(tmp, val);
|
|
|
|
tcg_gen_or_i32(reg, reg, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(reg, reg, 0xffff0000);
|
2006-10-22 04:18:54 +04:00
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16u_i32(tmp, val);
|
|
|
|
tcg_gen_or_i32(reg, reg, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_SINGLE:
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_pack_32_f32(reg, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_assert(0, "Bad operand size");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sign or zero extend a value. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static inline TCGv gen_extend(TCGv val, int opsize, int sign)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE:
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if (sign)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext8s_i32(tmp, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext8u_i32(tmp, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_WORD:
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if (sign)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16s_i32(tmp, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16u_i32(tmp, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
tmp = val;
|
|
|
|
break;
|
|
|
|
case OS_SINGLE:
|
|
|
|
tmp = gen_new_qreg(QMODE_F32);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_pack_f32_32(tmp, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_assert(0, "Bad operand size");
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate code for an "effective address". Does not adjust the base
|
|
|
|
register for autoincrememnt addressing modes. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static TCGv gen_lea(DisasContext *s, uint16_t insn, int opsize)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
uint16_t ext;
|
|
|
|
uint32_t offset;
|
|
|
|
|
|
|
|
switch ((insn >> 3) & 7) {
|
|
|
|
case 0: /* Data register direct. */
|
|
|
|
case 1: /* Address register direct. */
|
2008-05-25 02:29:16 +04:00
|
|
|
return NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
case 2: /* Indirect register */
|
|
|
|
case 3: /* Indirect postincrement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
return AREG(insn, 0);
|
2006-10-22 04:18:54 +04:00
|
|
|
case 4: /* Indirect predecrememnt. */
|
2008-05-25 02:29:16 +04:00
|
|
|
reg = AREG(insn, 0);
|
2006-10-22 04:18:54 +04:00
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_subi_i32(tmp, reg, opsize_bytes(opsize));
|
2006-10-22 04:18:54 +04:00
|
|
|
return tmp;
|
|
|
|
case 5: /* Indirect displacement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
reg = AREG(insn, 0);
|
2006-10-22 04:18:54 +04:00
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2007-05-23 23:58:11 +04:00
|
|
|
ext = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(tmp, reg, (int16_t)ext);
|
2006-10-22 04:18:54 +04:00
|
|
|
return tmp;
|
|
|
|
case 6: /* Indirect index + displacement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
reg = AREG(insn, 0);
|
2006-10-22 04:18:54 +04:00
|
|
|
return gen_lea_indexed(s, opsize, reg);
|
|
|
|
case 7: /* Other */
|
2008-05-25 02:29:16 +04:00
|
|
|
switch (insn & 7) {
|
2006-10-22 04:18:54 +04:00
|
|
|
case 0: /* Absolute short. */
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = ldsw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
return gen_im32(offset);
|
|
|
|
case 1: /* Absolute long. */
|
|
|
|
offset = read_im32(s);
|
|
|
|
return gen_im32(offset);
|
|
|
|
case 2: /* pc displacement */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
offset = s->pc;
|
2007-05-23 23:58:11 +04:00
|
|
|
offset += ldsw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
return gen_im32(offset);
|
|
|
|
case 3: /* pc index+displacement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
return gen_lea_indexed(s, opsize, NULL_QREG);
|
2006-10-22 04:18:54 +04:00
|
|
|
case 4: /* Immediate. */
|
|
|
|
default:
|
2008-05-25 02:29:16 +04:00
|
|
|
return NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Should never happen. */
|
2008-05-25 02:29:16 +04:00
|
|
|
return NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function for gen_ea. Reuse the computed address between the
|
|
|
|
for read/write operands. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static inline TCGv gen_ea_once(DisasContext *s, uint16_t insn, int opsize,
|
|
|
|
TCGv val, TCGv *addrp, ea_what what)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
if (addrp && what == EA_STORE) {
|
2006-10-22 04:18:54 +04:00
|
|
|
tmp = *addrp;
|
|
|
|
} else {
|
|
|
|
tmp = gen_lea(s, insn, opsize);
|
2008-05-25 02:29:16 +04:00
|
|
|
if (IS_NULL_QREG(tmp))
|
|
|
|
return tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
if (addrp)
|
|
|
|
*addrp = tmp;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
return gen_ldst(s, opsize, tmp, val, what);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate code to load/store a value ito/from an EA. If VAL > 0 this is
|
|
|
|
a write otherwise it is a read (0 == sign extend, -1 == zero extend).
|
|
|
|
ADDRP is non-null for readwrite operands. */
|
2008-05-25 02:29:16 +04:00
|
|
|
static TCGv gen_ea(DisasContext *s, uint16_t insn, int opsize, TCGv val,
|
|
|
|
TCGv *addrp, ea_what what)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv result;
|
2006-10-22 04:18:54 +04:00
|
|
|
uint32_t offset;
|
|
|
|
|
|
|
|
switch ((insn >> 3) & 7) {
|
|
|
|
case 0: /* Data register direct. */
|
2008-05-25 02:29:16 +04:00
|
|
|
reg = DREG(insn, 0);
|
|
|
|
if (what == EA_STORE) {
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_partset_reg(opsize, reg, val);
|
2008-05-25 02:29:16 +04:00
|
|
|
return store_dummy;
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
return gen_extend(reg, opsize, what == EA_LOADS);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
case 1: /* Address register direct. */
|
2008-05-25 02:29:16 +04:00
|
|
|
reg = AREG(insn, 0);
|
|
|
|
if (what == EA_STORE) {
|
|
|
|
tcg_gen_mov_i32(reg, val);
|
|
|
|
return store_dummy;
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
return gen_extend(reg, opsize, what == EA_LOADS);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
case 2: /* Indirect register */
|
2008-05-25 02:29:16 +04:00
|
|
|
reg = AREG(insn, 0);
|
|
|
|
return gen_ldst(s, opsize, reg, val, what);
|
2006-10-22 04:18:54 +04:00
|
|
|
case 3: /* Indirect postincrement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
reg = AREG(insn, 0);
|
|
|
|
result = gen_ldst(s, opsize, reg, val, what);
|
2006-10-22 04:18:54 +04:00
|
|
|
/* ??? This is not exception safe. The instruction may still
|
|
|
|
fault after this point. */
|
2008-05-25 02:29:16 +04:00
|
|
|
if (what == EA_STORE || !addrp)
|
|
|
|
tcg_gen_addi_i32(reg, reg, opsize_bytes(opsize));
|
2006-10-22 04:18:54 +04:00
|
|
|
return result;
|
|
|
|
case 4: /* Indirect predecrememnt. */
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
|
|
|
if (addrp && what == EA_STORE) {
|
2006-10-22 04:18:54 +04:00
|
|
|
tmp = *addrp;
|
|
|
|
} else {
|
|
|
|
tmp = gen_lea(s, insn, opsize);
|
2008-05-25 02:29:16 +04:00
|
|
|
if (IS_NULL_QREG(tmp))
|
|
|
|
return tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
if (addrp)
|
|
|
|
*addrp = tmp;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
result = gen_ldst(s, opsize, tmp, val, what);
|
2006-10-22 04:18:54 +04:00
|
|
|
/* ??? This is not exception safe. The instruction may still
|
|
|
|
fault after this point. */
|
2008-05-25 02:29:16 +04:00
|
|
|
if (what == EA_STORE || !addrp) {
|
|
|
|
reg = AREG(insn, 0);
|
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
case 5: /* Indirect displacement. */
|
|
|
|
case 6: /* Indirect index + displacement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
return gen_ea_once(s, insn, opsize, val, addrp, what);
|
2006-10-22 04:18:54 +04:00
|
|
|
case 7: /* Other */
|
2008-05-25 02:29:16 +04:00
|
|
|
switch (insn & 7) {
|
2006-10-22 04:18:54 +04:00
|
|
|
case 0: /* Absolute short. */
|
|
|
|
case 1: /* Absolute long. */
|
|
|
|
case 2: /* pc displacement */
|
|
|
|
case 3: /* pc index+displacement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
return gen_ea_once(s, insn, opsize, val, addrp, what);
|
2006-10-22 04:18:54 +04:00
|
|
|
case 4: /* Immediate. */
|
|
|
|
/* Sign extend values for consistency. */
|
|
|
|
switch (opsize) {
|
|
|
|
case OS_BYTE:
|
2008-05-25 02:29:16 +04:00
|
|
|
if (what == EA_LOADS)
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = ldsb_code(s->pc + 1);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = ldub_code(s->pc + 1);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
break;
|
|
|
|
case OS_WORD:
|
2008-05-25 02:29:16 +04:00
|
|
|
if (what == EA_LOADS)
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = ldsw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
break;
|
|
|
|
case OS_LONG:
|
|
|
|
offset = read_im32(s);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_assert(0, "Bad immediate operand");
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
return tcg_const_i32(offset);
|
2006-10-22 04:18:54 +04:00
|
|
|
default:
|
2008-05-25 02:29:16 +04:00
|
|
|
return NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Should never happen. */
|
2008-05-25 02:29:16 +04:00
|
|
|
return NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
/* This generates a conditional branch, clobbering all temporaries. */
|
2006-10-22 04:18:54 +04:00
|
|
|
static void gen_jmpcc(DisasContext *s, int cond, int l1)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
/* TODO: Optimize compare/branch pairs rather than always flushing
|
|
|
|
flag state to CC_OP_FLAGS. */
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_flush_flags(s);
|
|
|
|
switch (cond) {
|
|
|
|
case 0: /* T */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_br(l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 1: /* F */
|
|
|
|
break;
|
|
|
|
case 2: /* HI (!C && !Z) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_C | CCF_Z);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 3: /* LS (C || Z) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_C | CCF_Z);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 4: /* CC (!C) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_C);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 5: /* CS (C) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_C);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 6: /* NE (!Z) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_Z);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 7: /* EQ (Z) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_Z);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 8: /* VC (!V) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_V);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 9: /* VS (V) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_V);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 10: /* PL (!N) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_N);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 11: /* MI (N) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_N);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 12: /* GE (!(N ^ V)) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
assert(CCF_V == (CCF_N >> 2));
|
|
|
|
tcg_gen_shri_i32(tmp, QREG_CC_DEST, 2);
|
|
|
|
tcg_gen_xor_i32(tmp, tmp, QREG_CC_DEST);
|
|
|
|
tcg_gen_andi_i32(tmp, tmp, CCF_V);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 13: /* LT (N ^ V) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
assert(CCF_V == (CCF_N >> 2));
|
|
|
|
tcg_gen_shri_i32(tmp, QREG_CC_DEST, 2);
|
|
|
|
tcg_gen_xor_i32(tmp, tmp, QREG_CC_DEST);
|
|
|
|
tcg_gen_andi_i32(tmp, tmp, CCF_V);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 14: /* GT (!(Z || (N ^ V))) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
assert(CCF_V == (CCF_N >> 2));
|
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_N);
|
|
|
|
tcg_gen_shri_i32(tmp, tmp, 2);
|
|
|
|
tcg_gen_xor_i32(tmp, tmp, QREG_CC_DEST);
|
|
|
|
tcg_gen_andi_i32(tmp, tmp, CCF_V | CCF_Z);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 15: /* LE (Z || (N ^ V)) */
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
assert(CCF_V == (CCF_N >> 2));
|
|
|
|
tcg_gen_andi_i32(tmp, QREG_CC_DEST, CCF_N);
|
|
|
|
tcg_gen_shri_i32(tmp, tmp, 2);
|
|
|
|
tcg_gen_xor_i32(tmp, tmp, QREG_CC_DEST);
|
|
|
|
tcg_gen_andi_i32(tmp, tmp, CCF_V | CCF_Z);
|
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, tmp, 0, l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Should ever happen. */
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(scc)
|
|
|
|
{
|
|
|
|
int l1;
|
|
|
|
int cond;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
l1 = gen_new_label();
|
|
|
|
cond = (insn >> 8) & 0xf;
|
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(reg, reg, 0xffffff00);
|
|
|
|
/* This is safe because we modify the reg directly, with no other values
|
|
|
|
live. */
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_jmpcc(s, cond ^ 1, l1);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ori_i32(reg, reg, 0xff);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_set_label(l1);
|
|
|
|
}
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
/* Force a TB lookup after an instruction that changes the CPU state. */
|
|
|
|
static void gen_lookup_tb(DisasContext *s)
|
|
|
|
{
|
|
|
|
gen_flush_cc_op(s);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_movi_i32(QREG_PC, s->pc);
|
2007-05-23 23:58:11 +04:00
|
|
|
s->is_jmp = DISAS_UPDATE;
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
/* Generate a jump to an immediate address. */
|
|
|
|
static void gen_jmp_im(DisasContext *s, uint32_t dest)
|
|
|
|
{
|
|
|
|
gen_flush_cc_op(s);
|
|
|
|
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 04:18:54 +04:00
|
|
|
{
|
|
|
|
gen_flush_cc_op(s);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(QREG_PC, dest);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->is_jmp = DISAS_JUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gen_exception(DisasContext *s, uint32_t where, int nr)
|
|
|
|
{
|
|
|
|
gen_flush_cc_op(s);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_jmp_im(s, where);
|
|
|
|
gen_helper_raise_exception(tcg_const_i32(nr));
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
2007-05-27 02:11:13 +04:00
|
|
|
static inline void gen_addr_fault(DisasContext *s)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->insn_pc, EXCP_ADDRESS);
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
#define SRC_EA(result, opsize, op_sign, addrp) do { \
|
|
|
|
result = gen_ea(s, insn, opsize, NULL_QREG, addrp, op_sign ? EA_LOADS : EA_LOADU); \
|
|
|
|
if (IS_NULL_QREG(result)) { \
|
2007-05-27 02:11:13 +04:00
|
|
|
gen_addr_fault(s); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DEST_EA(insn, opsize, val, addrp) do { \
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv ea_result = gen_ea(s, insn, opsize, val, addrp, EA_STORE); \
|
|
|
|
if (IS_NULL_QREG(ea_result)) { \
|
2007-05-27 02:11:13 +04:00
|
|
|
gen_addr_fault(s); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
/* Generate a jump to an immediate address. */
|
|
|
|
static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest)
|
|
|
|
{
|
|
|
|
TranslationBlock *tb;
|
|
|
|
|
|
|
|
tb = s->tb;
|
2008-07-03 21:57:36 +04:00
|
|
|
if (unlikely(s->singlestep_enabled)) {
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_exception(s, dest, EXCP_DEBUG);
|
|
|
|
} else if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) ||
|
|
|
|
(s->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
|
2008-02-01 13:50:11 +03:00
|
|
|
tcg_gen_goto_tb(n);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_movi_i32(QREG_PC, dest);
|
2008-02-01 13:50:11 +03:00
|
|
|
tcg_gen_exit_tb((long)tb + n);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_jmp_im(s, dest);
|
2008-02-01 13:50:11 +03:00
|
|
|
tcg_gen_exit_tb(0);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
s->is_jmp = DISAS_TB_JUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_UNSUPPORTED);
|
|
|
|
cpu_abort(cpu_single_env, "Illegal instruction: %04x @ %08x",
|
|
|
|
insn, s->pc - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mulw)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv src;
|
2006-10-22 04:18:54 +04:00
|
|
|
int sign;
|
|
|
|
|
|
|
|
sign = (insn & 0x100) != 0;
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if (sign)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16s_i32(tmp, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16u_i32(tmp, reg);
|
|
|
|
SRC_EA(src, OS_WORD, sign, NULL);
|
|
|
|
tcg_gen_mul_i32(tmp, tmp, src);
|
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
/* Unlike m68k, coldfire always clears the overflow bit. */
|
|
|
|
gen_logic_cc(s, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(divw)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv src;
|
2006-10-22 04:18:54 +04:00
|
|
|
int sign;
|
|
|
|
|
|
|
|
sign = (insn & 0x100) != 0;
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
if (sign) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16s_i32(QREG_DIV1, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16u_i32(QREG_DIV1, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
SRC_EA(src, OS_WORD, sign, NULL);
|
|
|
|
tcg_gen_mov_i32(QREG_DIV2, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
if (sign) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_divs(cpu_env, tcg_const_i32(1));
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_divu(cpu_env, tcg_const_i32(1));
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
src = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16u_i32(tmp, QREG_DIV1);
|
|
|
|
tcg_gen_shli_i32(src, QREG_DIV2, 16);
|
|
|
|
tcg_gen_or_i32(reg, tmp, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_FLAGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(divl)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv num;
|
|
|
|
TCGv den;
|
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
uint16_t ext;
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
ext = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
if (ext & 0x87f8) {
|
|
|
|
gen_exception(s, s->pc - 4, EXCP_UNSUPPORTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
num = DREG(ext, 12);
|
|
|
|
reg = DREG(ext, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(QREG_DIV1, num);
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(den, OS_LONG, 0, NULL);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(QREG_DIV2, den);
|
2006-10-22 04:18:54 +04:00
|
|
|
if (ext & 0x0800) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_divs(cpu_env, tcg_const_i32(0));
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_divu(cpu_env, tcg_const_i32(0));
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
if ((ext & 7) == ((ext >> 12) & 7)) {
|
2006-10-22 04:18:54 +04:00
|
|
|
/* div */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32 (reg, QREG_DIV1);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
|
|
|
/* rem */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32 (reg, QREG_DIV2);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
s->cc_op = CC_OP_FLAGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(addsub)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv src;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
int add;
|
|
|
|
|
|
|
|
add = (insn & 0x4000) != 0;
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
|
|
|
if (insn & 0x100) {
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(tmp, OS_LONG, 0, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
src = reg;
|
|
|
|
} else {
|
|
|
|
tmp = reg;
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
if (add) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_add_i32(dest, tmp, src);
|
|
|
|
gen_helper_xflag_lt(QREG_CC_X, dest, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_ADD;
|
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_xflag_lt(QREG_CC_X, tmp, src);
|
|
|
|
tcg_gen_sub_i32(dest, tmp, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_SUB;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_update_cc_add(dest, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
if (insn & 0x100) {
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, dest, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, dest);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Reverse the order of the bits in REG. */
|
|
|
|
DISAS_INSN(bitrev)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_bitrev(reg, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(bitop_reg)
|
|
|
|
{
|
|
|
|
int opsize;
|
|
|
|
int op;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src1;
|
|
|
|
TCGv src2;
|
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
|
|
|
TCGv dest;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
if ((insn & 0x38) != 0)
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
else
|
|
|
|
opsize = OS_LONG;
|
|
|
|
op = (insn >> 6) & 3;
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src1, opsize, 0, op ? &addr: NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
src2 = DREG(insn, 9);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
|
|
|
|
|
|
|
gen_flush_flags(s);
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if (opsize == OS_BYTE)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, src2, 7);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, src2, 31);
|
2006-10-22 04:18:54 +04:00
|
|
|
src2 = tmp;
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shr_i32(tmp, src1, src2);
|
|
|
|
tcg_gen_andi_i32(tmp, tmp, 1);
|
|
|
|
tcg_gen_shli_i32(tmp, tmp, 2);
|
|
|
|
/* Clear CCF_Z if bit set. */
|
|
|
|
tcg_gen_ori_i32(QREG_CC_DEST, QREG_CC_DEST, CCF_Z);
|
|
|
|
tcg_gen_xor_i32(QREG_CC_DEST, QREG_CC_DEST, tmp);
|
|
|
|
|
|
|
|
tcg_gen_shl_i32(tmp, tcg_const_i32(1), src2);
|
2006-10-22 04:18:54 +04:00
|
|
|
switch (op) {
|
|
|
|
case 1: /* bchg */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_xor_i32(dest, src1, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 2: /* bclr */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_not_i32(tmp, tmp);
|
|
|
|
tcg_gen_and_i32(dest, src1, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 3: /* bset */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_or_i32(dest, src1, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
default: /* btst */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (op)
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, opsize, dest, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(sats)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = DREG(insn, 0);
|
|
|
|
gen_flush_flags(s);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_sats(reg, reg, QREG_CC_DEST);
|
|
|
|
gen_logic_cc(s, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
static void gen_push(DisasContext *s, TCGv val)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_subi_i32(tmp, QREG_SP, 4);
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_store(s, OS_LONG, tmp, val);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(QREG_SP, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(movem)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
int i;
|
|
|
|
uint16_t mask;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
int is_load;
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
mask = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
tmp = gen_lea(s, insn, OS_LONG);
|
2008-05-25 02:29:16 +04:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 02:11:13 +04:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2006-10-22 04:18:54 +04:00
|
|
|
addr = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(addr, tmp);
|
2006-10-22 04:18:54 +04: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-23 23:58:11 +04:00
|
|
|
tmp = gen_load(s, OS_LONG, addr, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_store(s, OS_LONG, addr, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
if (mask != 1)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(addr, addr, 4);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(bitop_im)
|
|
|
|
{
|
|
|
|
int opsize;
|
|
|
|
int op;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src1;
|
2006-10-22 04:18:54 +04:00
|
|
|
uint32_t mask;
|
|
|
|
int bitnum;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
if ((insn & 0x38) != 0)
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
else
|
|
|
|
opsize = OS_LONG;
|
|
|
|
op = (insn >> 6) & 3;
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
bitnum = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
if (bitnum & 0xff00) {
|
|
|
|
disas_undef(s, insn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src1, opsize, 0, op ? &addr: NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
gen_flush_flags(s);
|
|
|
|
if (opsize == OS_BYTE)
|
|
|
|
bitnum &= 7;
|
|
|
|
else
|
|
|
|
bitnum &= 31;
|
|
|
|
mask = 1 << bitnum;
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
assert (CCF_Z == (1 << 2));
|
|
|
|
if (bitnum > 2)
|
|
|
|
tcg_gen_shri_i32(tmp, src1, bitnum - 2);
|
|
|
|
else if (bitnum < 2)
|
|
|
|
tcg_gen_shli_i32(tmp, src1, 2 - bitnum);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(tmp, src1);
|
|
|
|
tcg_gen_andi_i32(tmp, tmp, CCF_Z);
|
|
|
|
/* Clear CCF_Z if bit set. */
|
|
|
|
tcg_gen_ori_i32(QREG_CC_DEST, QREG_CC_DEST, CCF_Z);
|
|
|
|
tcg_gen_xor_i32(QREG_CC_DEST, QREG_CC_DEST, tmp);
|
|
|
|
if (op) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
DEST_EA(insn, opsize, tmp, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(arith_im)
|
|
|
|
{
|
|
|
|
int op;
|
2008-05-25 02:29:16 +04:00
|
|
|
uint32_t im;
|
|
|
|
TCGv src1;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
op = (insn >> 9) & 7;
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src1, OS_LONG, 0, (op == 6) ? NULL : &addr);
|
2008-05-25 02:29:16 +04:00
|
|
|
im = read_im32(s);
|
2006-10-22 04:18:54 +04:00
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
|
|
|
switch (op) {
|
|
|
|
case 0: /* ori */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ori_i32(dest, src1, im);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, dest);
|
|
|
|
break;
|
|
|
|
case 1: /* andi */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(dest, src1, im);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, dest);
|
|
|
|
break;
|
|
|
|
case 2: /* subi */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(dest, src1);
|
|
|
|
gen_helper_xflag_lt(QREG_CC_X, dest, gen_im32(im));
|
|
|
|
tcg_gen_subi_i32(dest, dest, im);
|
|
|
|
gen_update_cc_add(dest, gen_im32(im));
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_SUB;
|
|
|
|
break;
|
|
|
|
case 3: /* addi */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(dest, src1);
|
|
|
|
tcg_gen_addi_i32(dest, dest, im);
|
|
|
|
gen_update_cc_add(dest, gen_im32(im));
|
|
|
|
gen_helper_xflag_lt(QREG_CC_X, dest, gen_im32(im));
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_ADD;
|
|
|
|
break;
|
|
|
|
case 5: /* eori */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_xori_i32(dest, src1, im);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, dest);
|
|
|
|
break;
|
|
|
|
case 6: /* cmpi */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(dest, src1);
|
|
|
|
tcg_gen_subi_i32(dest, dest, im);
|
|
|
|
gen_update_cc_add(dest, gen_im32(im));
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_SUB;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (op != 6) {
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, dest, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(byterev)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_bswap_i32(reg, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv dest;
|
2006-10-22 04:18:54 +04: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();
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
SRC_EA(src, opsize, 1, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
op = (insn >> 6) & 7;
|
|
|
|
if (op == 1) {
|
|
|
|
/* movea */
|
|
|
|
/* The value will already have been sign extended. */
|
|
|
|
dest = AREG(insn, 9);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(dest, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
|
|
|
/* normal move */
|
|
|
|
uint16_t dest_ea;
|
|
|
|
dest_ea = ((insn >> 9) & 7) | (op << 3);
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(dest_ea, opsize, src, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
/* This will be correct because loads sign extend. */
|
|
|
|
gen_logic_cc(s, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(negx)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
gen_flush_flags(s);
|
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_subx_cc(reg, cpu_env, tcg_const_i32(0), reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(lea)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = AREG(insn, 9);
|
|
|
|
tmp = gen_lea(s, insn, OS_LONG);
|
2008-05-25 02:29:16 +04:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 02:11:13 +04:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(clr)
|
|
|
|
{
|
|
|
|
int opsize;
|
|
|
|
|
|
|
|
switch ((insn >> 6) & 3) {
|
|
|
|
case 0: /* clr.b */
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
break;
|
|
|
|
case 1: /* clr.w */
|
|
|
|
opsize = OS_WORD;
|
|
|
|
break;
|
|
|
|
case 2: /* clr.l */
|
|
|
|
opsize = OS_LONG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, opsize, gen_im32(0), NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, gen_im32(0));
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
static TCGv gen_get_ccr(DisasContext *s)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv dest;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
gen_flush_flags(s);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shli_i32(dest, QREG_CC_X, 4);
|
|
|
|
tcg_gen_or_i32(dest, dest, QREG_CC_DEST);
|
2007-05-23 23:58:11 +04:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_from_ccr)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv ccr;
|
2007-05-23 23:58:11 +04:00
|
|
|
|
|
|
|
ccr = gen_get_ccr(s);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = DREG(insn, 0);
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_partset_reg(OS_WORD, reg, ccr);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(neg)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv src1;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
|
|
|
src1 = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(src1, reg);
|
|
|
|
tcg_gen_neg_i32(reg, src1);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_SUB;
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_update_cc_add(reg, src1);
|
|
|
|
gen_helper_xflag_lt(QREG_CC_X, tcg_const_i32(0), src1);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_SUB;
|
|
|
|
}
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
static void gen_set_sr_im(DisasContext *s, uint16_t val, int ccr_only)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_movi_i32(QREG_CC_DEST, val & 0xf);
|
|
|
|
tcg_gen_movi_i32(QREG_CC_X, (val & 0x10) >> 4);
|
2007-05-23 23:58:11 +04:00
|
|
|
if (!ccr_only) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_set_sr(cpu_env, tcg_const_i32(val & 0xff00));
|
2007-05-23 23:58:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gen_set_sr(DisasContext *s, uint16_t insn, int ccr_only)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
s->cc_op = CC_OP_FLAGS;
|
|
|
|
if ((insn & 0x38) == 0)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(QREG_CC_DEST, reg, 0xf);
|
|
|
|
tcg_gen_shri_i32(tmp, reg, 4);
|
|
|
|
tcg_gen_andi_i32(QREG_CC_X, tmp, 1);
|
2007-05-23 23:58:11 +04:00
|
|
|
if (!ccr_only) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_set_sr(cpu_env, reg);
|
2007-05-23 23:58:11 +04:00
|
|
|
}
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
2007-05-23 23:58:11 +04:00
|
|
|
else if ((insn & 0x3f) == 0x3c)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
uint16_t val;
|
|
|
|
val = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_set_sr_im(s, val, ccr_only);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
disas_undef(s, insn);
|
|
|
|
}
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
DISAS_INSN(move_to_ccr)
|
|
|
|
{
|
|
|
|
gen_set_sr(s, insn, 1);
|
|
|
|
}
|
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
DISAS_INSN(not)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_not_i32(reg, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(swap)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src1;
|
|
|
|
TCGv src2;
|
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
src1 = gen_new_qreg(QMODE_I32);
|
|
|
|
src2 = gen_new_qreg(QMODE_I32);
|
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shli_i32(src1, reg, 16);
|
|
|
|
tcg_gen_shri_i32(src2, reg, 16);
|
|
|
|
tcg_gen_or_i32(reg, src1, src2);
|
|
|
|
gen_logic_cc(s, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(pea)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
tmp = gen_lea(s, insn, OS_LONG);
|
2008-05-25 02:29:16 +04:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 02:11:13 +04:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_push(s, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(ext)
|
|
|
|
{
|
|
|
|
int op;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
|
|
|
op = (insn >> 6) & 7;
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
if (op == 3)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16s_i32(tmp, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext8s_i32(tmp, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
if (op == 2)
|
|
|
|
gen_partset_reg(OS_WORD, reg, tmp);
|
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(tst)
|
|
|
|
{
|
|
|
|
int opsize;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
switch ((insn >> 6) & 3) {
|
|
|
|
case 0: /* tst.b */
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
break;
|
|
|
|
case 1: /* tst.w */
|
|
|
|
opsize = OS_WORD;
|
|
|
|
break;
|
|
|
|
case 2: /* tst.l */
|
|
|
|
opsize = OS_LONG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
SRC_EA(tmp, opsize, 1, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 02:29:16 +04:00
|
|
|
TCGv dest;
|
|
|
|
TCGv src1;
|
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
SRC_EA(src1, OS_BYTE, 1, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, src1);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ori_i32(dest, src1, 0x80);
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_BYTE, dest, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mull)
|
|
|
|
{
|
|
|
|
uint16_t ext;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv src1;
|
|
|
|
TCGv dest;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
/* The upper 32 bits of the product are discarded, so
|
|
|
|
muls.l and mulu.l are functionally equivalent. */
|
2007-05-23 23:58:11 +04:00
|
|
|
ext = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
if (ext & 0x87ff) {
|
|
|
|
gen_exception(s, s->pc - 4, EXCP_UNSUPPORTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reg = DREG(ext, 12);
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src1, OS_LONG, 0, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mul_i32(dest, src1, reg);
|
|
|
|
tcg_gen_mov_i32(reg, dest);
|
2006-10-22 04:18:54 +04:00
|
|
|
/* Unlike m68k, coldfire always clears the overflow bit. */
|
|
|
|
gen_logic_cc(s, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(link)
|
|
|
|
{
|
|
|
|
int16_t offset;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = ldsw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
reg = AREG(insn, 0);
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_subi_i32(tmp, QREG_SP, 4);
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_store(s, OS_LONG, tmp, reg);
|
2008-05-25 02:29:16 +04:00
|
|
|
if ((insn & 7) != 7)
|
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
|
|
|
tcg_gen_addi_i32(QREG_SP, tmp, offset);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(unlk)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
src = gen_new_qreg(QMODE_I32);
|
|
|
|
reg = AREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(src, reg);
|
2007-05-23 23:58:11 +04:00
|
|
|
tmp = gen_load(s, OS_LONG, src, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, tmp);
|
|
|
|
tcg_gen_addi_i32(QREG_SP, src, 4);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(nop)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(rts)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
tmp = gen_load(s, OS_LONG, QREG_SP, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(QREG_SP, QREG_SP, 4);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_jmp(s, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(jump)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
/* Load the target address first to ensure correct exception
|
|
|
|
behavior. */
|
|
|
|
tmp = gen_lea(s, insn, OS_LONG);
|
2008-05-25 02:29:16 +04:00
|
|
|
if (IS_NULL_QREG(tmp)) {
|
2007-05-27 02:11:13 +04:00
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
2006-10-22 04:18:54 +04:00
|
|
|
if ((insn & 0x40) == 0) {
|
|
|
|
/* jsr */
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_push(s, gen_im32(s->pc));
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
gen_jmp(s, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(addsubq)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src1;
|
|
|
|
TCGv src2;
|
|
|
|
TCGv dest;
|
2006-10-22 04:18:54 +04:00
|
|
|
int val;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src1, OS_LONG, 0, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
val = (insn >> 9) & 7;
|
|
|
|
if (val == 0)
|
|
|
|
val = 8;
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(dest, src1);
|
2006-10-22 04:18:54 +04:00
|
|
|
if ((insn & 0x38) == 0x08) {
|
|
|
|
/* Don't update condition codes if the destination is an
|
|
|
|
address register. */
|
|
|
|
if (insn & 0x0100) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_subi_i32(dest, dest, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(dest, dest, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
src2 = gen_im32(val);
|
2006-10-22 04:18:54 +04:00
|
|
|
if (insn & 0x0100) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_xflag_lt(QREG_CC_X, dest, src2);
|
|
|
|
tcg_gen_subi_i32(dest, dest, val);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_SUB;
|
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(dest, dest, val);
|
|
|
|
gen_helper_xflag_lt(QREG_CC_X, dest, src2);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_ADD;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_update_cc_add(dest, src2);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, dest, &addr);
|
2006-10-22 04:18:54 +04: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:
|
|
|
|
disas_undef(s, insn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(branch)
|
|
|
|
{
|
|
|
|
int32_t offset;
|
|
|
|
uint32_t base;
|
|
|
|
int op;
|
|
|
|
int l1;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
base = s->pc;
|
|
|
|
op = (insn >> 8) & 0xf;
|
|
|
|
offset = (int8_t)insn;
|
|
|
|
if (offset == 0) {
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = ldsw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
} else if (offset == -1) {
|
|
|
|
offset = read_im32(s);
|
|
|
|
}
|
|
|
|
if (op == 1) {
|
|
|
|
/* bsr */
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_push(s, gen_im32(s->pc));
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
gen_flush_cc_op(s);
|
|
|
|
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 02:29:16 +04:00
|
|
|
uint32_t val;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
val = (int8_t)insn;
|
|
|
|
tcg_gen_movi_i32(DREG(insn, 9), val);
|
|
|
|
gen_logic_cc(s, tcg_const_i32(val));
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mvzs)
|
|
|
|
{
|
|
|
|
int opsize;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
if (insn & 0x40)
|
|
|
|
opsize = OS_WORD;
|
|
|
|
else
|
|
|
|
opsize = OS_BYTE;
|
2008-09-05 16:33:31 +04:00
|
|
|
SRC_EA(src, opsize, (insn & 0x80) == 0, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = DREG(insn, 9);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(or)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv src;
|
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
|
|
|
if (insn & 0x100) {
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, &addr);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_or_i32(dest, src, reg);
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, dest, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, NULL);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_or_i32(dest, src, reg);
|
|
|
|
tcg_gen_mov_i32(reg, dest);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
gen_logic_cc(s, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(suba)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = AREG(insn, 9);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_sub_i32(reg, reg, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(subx)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv src;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
gen_flush_flags(s);
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
src = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_subx_cc(reg, cpu_env, reg, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(mov3q)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
2006-10-22 04:18:54 +04:00
|
|
|
int val;
|
|
|
|
|
|
|
|
val = (insn >> 9) & 7;
|
|
|
|
if (val == 0)
|
|
|
|
val = -1;
|
|
|
|
src = gen_im32(val);
|
|
|
|
gen_logic_cc(s, src);
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, src, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(cmp)
|
|
|
|
{
|
|
|
|
int op;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
2006-10-22 04:18:54 +04:00
|
|
|
int opsize;
|
|
|
|
|
|
|
|
op = (insn >> 6) & 3;
|
|
|
|
switch (op) {
|
|
|
|
case 0: /* cmp.b */
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
s->cc_op = CC_OP_CMPB;
|
|
|
|
break;
|
|
|
|
case 1: /* cmp.w */
|
|
|
|
opsize = OS_WORD;
|
|
|
|
s->cc_op = CC_OP_CMPW;
|
|
|
|
break;
|
|
|
|
case 2: /* cmp.l */
|
|
|
|
opsize = OS_LONG;
|
|
|
|
s->cc_op = CC_OP_SUB;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
SRC_EA(src, opsize, 1, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = DREG(insn, 9);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_sub_i32(dest, reg, src);
|
|
|
|
gen_update_cc_add(dest, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(cmpa)
|
|
|
|
{
|
|
|
|
int opsize;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
if (insn & 0x100) {
|
|
|
|
opsize = OS_LONG;
|
|
|
|
} else {
|
|
|
|
opsize = OS_WORD;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
SRC_EA(src, opsize, 1, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = AREG(insn, 9);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_sub_i32(dest, reg, src);
|
|
|
|
gen_update_cc_add(dest, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_SUB;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(eor)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = DREG(insn, 9);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_xor_i32(dest, src, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_logic_cc(s, dest);
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, dest, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(and)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv addr;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
dest = gen_new_qreg(QMODE_I32);
|
|
|
|
if (insn & 0x100) {
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, &addr);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_and_i32(dest, src, reg);
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, dest, &addr);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, NULL);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_and_i32(dest, src, reg);
|
|
|
|
tcg_gen_mov_i32(reg, dest);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
gen_logic_cc(s, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(adda)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2007-05-27 02:11:13 +04:00
|
|
|
SRC_EA(src, OS_LONG, 0, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
reg = AREG(insn, 9);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_add_i32(reg, reg, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(addx)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv src;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
gen_flush_flags(s);
|
|
|
|
reg = DREG(insn, 9);
|
|
|
|
src = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_addx_cc(reg, cpu_env, reg, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->cc_op = CC_OP_FLAGS;
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
/* TODO: This could be implemented without helper functions. */
|
2006-10-22 04:18:54 +04:00
|
|
|
DISAS_INSN(shift_im)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2006-10-22 04:18:54 +04:00
|
|
|
int tmp;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv shift;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
|
|
|
tmp = (insn >> 9) & 7;
|
|
|
|
if (tmp == 0)
|
2008-05-25 02:29:16 +04:00
|
|
|
tmp = 8;
|
|
|
|
shift = gen_im32(tmp);
|
|
|
|
/* No need to flush flags becuse we know we will set C flag. */
|
2006-10-22 04:18:54 +04:00
|
|
|
if (insn & 0x100) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_shl_cc(reg, cpu_env, reg, shift);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
|
|
|
if (insn & 8) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_shr_cc(reg, cpu_env, reg, shift);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_sar_cc(reg, cpu_env, reg, shift);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
s->cc_op = CC_OP_SHIFT;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(shift_reg)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv shift;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
reg = DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
shift = DREG(insn, 9);
|
|
|
|
/* Shift by zero leaves C flag unmodified. */
|
|
|
|
gen_flush_flags(s);
|
2006-10-22 04:18:54 +04:00
|
|
|
if (insn & 0x100) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_shl_cc(reg, cpu_env, reg, shift);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
|
|
|
if (insn & 8) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_shr_cc(reg, cpu_env, reg, shift);
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_sar_cc(reg, cpu_env, reg, shift);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
s->cc_op = CC_OP_SHIFT;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(ff1)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2007-05-28 06:20:34 +04:00
|
|
|
reg = DREG(insn, 0);
|
|
|
|
gen_logic_cc(s, reg);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_ff1(reg, reg);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
static TCGv gen_get_sr(DisasContext *s)
|
2007-05-23 23:58:11 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv ccr;
|
|
|
|
TCGv sr;
|
2007-05-23 23:58:11 +04:00
|
|
|
|
|
|
|
ccr = gen_get_ccr(s);
|
|
|
|
sr = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(sr, QREG_SR, 0xffe0);
|
|
|
|
tcg_gen_or_i32(sr, sr, ccr);
|
2007-05-23 23:58:11 +04:00
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
DISAS_INSN(strldsr)
|
|
|
|
{
|
|
|
|
uint16_t ext;
|
|
|
|
uint32_t addr;
|
|
|
|
|
|
|
|
addr = s->pc - 2;
|
2007-05-23 23:58:11 +04:00
|
|
|
ext = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
2007-05-23 23:58:11 +04:00
|
|
|
if (ext != 0x46FC) {
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_exception(s, addr, EXCP_UNSUPPORTED);
|
2007-05-23 23:58:11 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ext = lduw_code(s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
if (IS_USER(s) || (ext & SR_S) == 0) {
|
2006-10-22 04:18:54 +04:00
|
|
|
gen_exception(s, addr, EXCP_PRIVILEGE);
|
2007-05-23 23:58:11 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gen_push(s, gen_get_sr(s));
|
|
|
|
gen_set_sr_im(s, ext, 0);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_from_sr)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv sr;
|
2007-05-23 23:58:11 +04:00
|
|
|
|
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sr = gen_get_sr(s);
|
|
|
|
reg = DREG(insn, 0);
|
|
|
|
gen_partset_reg(OS_WORD, reg, sr);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_to_sr)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gen_set_sr(s, insn, 0);
|
|
|
|
gen_lookup_tb(s);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_from_usp)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* TODO: Implement USP. */
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_to_usp)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* TODO: Implement USP. */
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(halt)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_exception(s, s->pc, EXCP_HALT_INSN);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(stop)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
uint16_t ext;
|
|
|
|
|
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext = lduw_code(s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
|
|
|
|
gen_set_sr_im(s, ext, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_movi_i32(QREG_HALTED, 1);
|
|
|
|
gen_exception(s, s->pc, EXCP_HLT);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(rte)
|
|
|
|
{
|
2007-05-23 23:58:11 +04: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 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(movec)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
uint16_t ext;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2007-05-23 23:58:11 +04:00
|
|
|
|
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext = lduw_code(s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
|
|
|
|
if (ext & 0x8000) {
|
|
|
|
reg = AREG(ext, 12);
|
|
|
|
} else {
|
|
|
|
reg = DREG(ext, 12);
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_movec(cpu_env, tcg_const_i32(ext & 0xfff), reg);
|
2007-05-23 23:58:11 +04:00
|
|
|
gen_lookup_tb(s);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(intouch)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* ICache fetch. Implement as no-op. */
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(cpushl)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Cache push/invalidate. Implement as no-op. */
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(wddata)
|
|
|
|
{
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(wdebug)
|
|
|
|
{
|
2007-05-23 23:58:11 +04:00
|
|
|
if (IS_USER(s)) {
|
|
|
|
gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* TODO: Implement wdebug. */
|
|
|
|
qemu_assert(0, "WDEBUG not implemented");
|
2006-10-22 04:18:54 +04: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;
|
|
|
|
int opmode;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv src;
|
|
|
|
TCGv dest;
|
|
|
|
TCGv res;
|
2006-10-22 04:18:54 +04:00
|
|
|
int round;
|
|
|
|
int opsize;
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
ext = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
opmode = ext & 0x7f;
|
|
|
|
switch ((ext >> 13) & 7) {
|
|
|
|
case 0: case 2:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
goto undef;
|
|
|
|
case 3: /* fmove out */
|
|
|
|
src = FREG(ext, 7);
|
|
|
|
/* fmove */
|
|
|
|
/* ??? TODO: Proper behavior on overflow. */
|
|
|
|
switch ((ext >> 10) & 7) {
|
|
|
|
case 0:
|
|
|
|
opsize = OS_LONG;
|
|
|
|
res = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_f64_to_i32(res, cpu_env, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
opsize = OS_SINGLE;
|
|
|
|
res = gen_new_qreg(QMODE_F32);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_f64_to_f32(res, cpu_env, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
opsize = OS_WORD;
|
|
|
|
res = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_f64_to_i32(res, cpu_env, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
opsize = OS_DOUBLE;
|
|
|
|
res = src;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
opsize = OS_BYTE;
|
|
|
|
res = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_f64_to_i32(res, cpu_env, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto undef;
|
|
|
|
}
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, opsize, res, NULL);
|
2006-10-22 04:18:54 +04: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. */
|
|
|
|
res = gen_im32(0);
|
|
|
|
break;
|
|
|
|
case 1: /* FPIAR */
|
|
|
|
case 2: /* FPSR */
|
|
|
|
default:
|
|
|
|
cpu_abort(NULL, "Unimplemented: fmove from control %d",
|
|
|
|
(ext >> 10) & 7);
|
|
|
|
goto undef;
|
|
|
|
}
|
2007-05-27 02:11:13 +04:00
|
|
|
DEST_EA(insn, OS_LONG, res, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
2007-09-17 01:08:06 +04:00
|
|
|
case 6: /* fmovem */
|
2006-10-22 04:18:54 +04:00
|
|
|
case 7:
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv addr;
|
|
|
|
uint16_t mask;
|
|
|
|
int i;
|
|
|
|
if ((ext & 0x1f00) != 0x1000 || (ext & 0xff) == 0)
|
|
|
|
goto undef;
|
|
|
|
src = gen_lea(s, insn, OS_LONG);
|
|
|
|
if (IS_NULL_QREG(src)) {
|
|
|
|
gen_addr_fault(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr = gen_new_qreg(QMODE_I32);
|
|
|
|
tcg_gen_mov_i32(addr, src);
|
|
|
|
mask = 0x80;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (ext & mask) {
|
|
|
|
s->is_mem = 1;
|
|
|
|
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 04:18:54 +04:00
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
mask >>= 1;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ext & (1 << 14)) {
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
SRC_EA(tmp, opsize, 1, NULL);
|
2006-10-22 04:18:54 +04:00
|
|
|
if (opsize == OS_DOUBLE) {
|
|
|
|
src = tmp;
|
|
|
|
} else {
|
|
|
|
src = gen_new_qreg(QMODE_F64);
|
|
|
|
switch (opsize) {
|
|
|
|
case OS_LONG:
|
|
|
|
case OS_WORD:
|
|
|
|
case OS_BYTE:
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_i32_to_f64(src, cpu_env, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case OS_SINGLE:
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_f32_to_f64(src, cpu_env, tmp);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Source register. */
|
|
|
|
src = FREG(ext, 10);
|
|
|
|
}
|
|
|
|
dest = FREG(ext, 7);
|
|
|
|
res = gen_new_qreg(QMODE_F64);
|
|
|
|
if (opmode != 0x3a)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_f64(res, dest);
|
2006-10-22 04:18:54 +04:00
|
|
|
round = 1;
|
|
|
|
switch (opmode) {
|
|
|
|
case 0: case 0x40: case 0x44: /* fmove */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_f64(res, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 1: /* fint */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_iround_f64(res, cpu_env, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
case 3: /* fintrz */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_itrunc_f64(res, cpu_env, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
case 4: case 0x41: case 0x45: /* fsqrt */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_sqrt_f64(res, cpu_env, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 0x18: case 0x58: case 0x5c: /* fabs */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_abs_f64(res, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 0x1a: case 0x5a: case 0x5e: /* fneg */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_chs_f64(res, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 0x20: case 0x60: case 0x64: /* fdiv */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_div_f64(res, cpu_env, res, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 0x22: case 0x62: case 0x66: /* fadd */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_add_f64(res, cpu_env, res, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 0x23: case 0x63: case 0x67: /* fmul */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_mul_f64(res, cpu_env, res, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 0x28: case 0x68: case 0x6c: /* fsub */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_sub_f64(res, cpu_env, res, src);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 0x38: /* fcmp */
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_sub_cmp_f64(res, cpu_env, res, src);
|
|
|
|
dest = NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
case 0x3a: /* ftst */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_f64(res, src);
|
|
|
|
dest = NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
round = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto undef;
|
|
|
|
}
|
|
|
|
if (round) {
|
|
|
|
if (opmode & 0x40) {
|
|
|
|
if ((opmode & 0x4) != 0)
|
|
|
|
round = 0;
|
|
|
|
} else if ((s->fpcr & M68K_FPCR_PREC) == 0) {
|
|
|
|
round = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (round) {
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
tmp = gen_new_qreg(QMODE_F32);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_f64_to_f32(tmp, cpu_env, res);
|
|
|
|
gen_helper_f32_to_f64(res, cpu_env, tmp);
|
2007-09-17 01:08:06 +04:00
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_f64(QREG_FP_RESULT, res);
|
|
|
|
if (!IS_NULL_QREG(dest)) {
|
|
|
|
tcg_gen_mov_f64(dest, res);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
undef:
|
|
|
|
s->pc -= 2;
|
|
|
|
disas_undef_fpu(s, insn);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(fbcc)
|
|
|
|
{
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t addr;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv flag;
|
2006-10-22 04:18:54 +04:00
|
|
|
int l1;
|
|
|
|
|
|
|
|
addr = s->pc;
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = ldsw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
if (insn & (1 << 6)) {
|
2007-05-23 23:58:11 +04:00
|
|
|
offset = (offset << 16) | lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
l1 = gen_new_label();
|
|
|
|
/* TODO: Raise BSUN exception. */
|
|
|
|
flag = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_compare_f64(flag, cpu_env, QREG_FP_RESULT);
|
2006-10-22 04:18:54 +04:00
|
|
|
/* Jump to l1 if condition is true. */
|
|
|
|
switch (insn & 0xf) {
|
|
|
|
case 0: /* f */
|
|
|
|
break;
|
|
|
|
case 1: /* eq (=0) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 2: /* ogt (=1) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(1), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 3: /* oge (=0 or =1) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LEU, flag, tcg_const_i32(1), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 4: /* olt (=-1) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LT, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 5: /* ole (=-1 or =0) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LE, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 6: /* ogl (=-1 or =1) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(flag, flag, 1);
|
|
|
|
tcg_gen_brcond_i32(TCG_COND_NE, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 7: /* or (=2) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(2), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 8: /* un (<2) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_LT, flag, tcg_const_i32(2), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 9: /* ueq (=0 or =2) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(flag, flag, 1);
|
|
|
|
tcg_gen_brcond_i32(TCG_COND_EQ, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 10: /* ugt (>0) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_GT, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 11: /* uge (>=0) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_GE, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 12: /* ult (=-1 or =2) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_GEU, flag, tcg_const_i32(2), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 13: /* ule (!=1) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_NE, flag, tcg_const_i32(1), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 14: /* ne (!=0) */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_NE, flag, tcg_const_i32(0), l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case 15: /* t */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_br(l1);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
gen_jmp_tb(s, 0, s->pc);
|
|
|
|
gen_set_label(l1);
|
|
|
|
gen_jmp_tb(s, 1, addr + offset);
|
|
|
|
}
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
DISAS_INSN(frestore)
|
|
|
|
{
|
|
|
|
/* TODO: Implement frestore. */
|
|
|
|
qemu_assert(0, "FRESTORE not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(fsave)
|
|
|
|
{
|
|
|
|
/* TODO: Implement fsave. */
|
|
|
|
qemu_assert(0, "FSAVE not implemented");
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
static inline TCGv gen_mac_extract_word(DisasContext *s, TCGv val, int upper)
|
2007-05-29 18:57:59 +04:00
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp = gen_new_qreg(QMODE_I32);
|
2007-05-29 18:57:59 +04:00
|
|
|
if (s->env->macsr & MACSR_FI) {
|
|
|
|
if (upper)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, val, 0xffff0000);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shli_i32(tmp, val, 16);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else if (s->env->macsr & MACSR_SU) {
|
|
|
|
if (upper)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_sari_i32(tmp, val, 16);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16s_i32(tmp, val);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else {
|
|
|
|
if (upper)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shri_i32(tmp, val, 16);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext16u_i32(tmp, val);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04: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 18:57:59 +04:00
|
|
|
DISAS_INSN(mac)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv rx;
|
|
|
|
TCGv ry;
|
2007-05-29 18:57:59 +04:00
|
|
|
uint16_t ext;
|
|
|
|
int acc;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv tmp;
|
|
|
|
TCGv addr;
|
|
|
|
TCGv loadval;
|
2007-05-29 18:57:59 +04:00
|
|
|
int dual;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv saved_flags;
|
|
|
|
|
|
|
|
if (IS_NULL_QREG(s->mactmp))
|
|
|
|
s->mactmp = tcg_temp_new(TCG_TYPE_I64);
|
2007-05-29 18:57:59 +04:00
|
|
|
|
|
|
|
ext = lduw_code(s->pc);
|
|
|
|
s->pc += 2;
|
|
|
|
|
|
|
|
acc = ((insn >> 7) & 1) | ((ext >> 3) & 2);
|
|
|
|
dual = ((insn & 0x30) != 0 && (ext & 3) != 0);
|
2007-06-03 16:35:08 +04:00
|
|
|
if (dual && !m68k_feature(s->env, M68K_FEATURE_CF_EMAC_B)) {
|
|
|
|
disas_undef(s, insn);
|
|
|
|
return;
|
|
|
|
}
|
2007-05-29 18:57:59 +04:00
|
|
|
if (insn & 0x30) {
|
|
|
|
/* MAC with load. */
|
|
|
|
tmp = gen_lea(s, insn, OS_LONG);
|
|
|
|
addr = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_and_i32(addr, tmp, QREG_MAC_MASK);
|
2007-05-29 18:57:59 +04: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 02:29:16 +04:00
|
|
|
loadval = addr = NULL_QREG;
|
2007-05-29 18:57:59 +04:00
|
|
|
rx = (insn & 0x40) ? AREG(insn, 9) : DREG(insn, 9);
|
|
|
|
ry = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_mac_clear_flags();
|
|
|
|
#if 0
|
2007-05-29 18:57:59 +04:00
|
|
|
l1 = -1;
|
2008-05-25 02:29:16 +04:00
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 18:57:59 +04:00
|
|
|
if ((s->env->macsr & MACSR_OMC) != 0 && !dual) {
|
|
|
|
/* Skip the multiply if we know we will ignore it. */
|
|
|
|
l1 = gen_new_label();
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_andi_i32(tmp, QREG_MACSR, 1 << (acc + 8));
|
2007-05-29 18:57:59 +04:00
|
|
|
gen_op_jmp_nz32(tmp, l1);
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
#endif
|
2007-05-29 18:57:59 +04: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 02:29:16 +04:00
|
|
|
gen_helper_macmulf(s->mactmp, cpu_env, rx, ry);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else {
|
|
|
|
if (s->env->macsr & MACSR_SU)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macmuls(s->mactmp, cpu_env, rx, ry);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macmulu(s->mactmp, cpu_env, rx, ry);
|
2007-05-29 18:57:59 +04:00
|
|
|
switch ((ext >> 9) & 3) {
|
|
|
|
case 1:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shli_i64(s->mactmp, s->mactmp, 1);
|
2007-05-29 18:57:59 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_shri_i64(s->mactmp, s->mactmp, 1);
|
2007-05-29 18:57:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dual) {
|
|
|
|
/* Save the overflow flag from the multiply. */
|
|
|
|
saved_flags = gen_new_qreg(QMODE_I32);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(saved_flags, QREG_MACSR);
|
|
|
|
} else {
|
|
|
|
saved_flags = NULL_QREG;
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 18:57:59 +04:00
|
|
|
if ((s->env->macsr & MACSR_OMC) != 0 && dual) {
|
|
|
|
/* Skip the accumulate if the value is already saturated. */
|
|
|
|
l1 = gen_new_label();
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
gen_op_and32(tmp, QREG_MACSR, gen_im32(MACSR_PAV0 << acc));
|
|
|
|
gen_op_jmp_nz32(tmp, l1);
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
#endif
|
2007-05-29 18:57:59 +04:00
|
|
|
|
|
|
|
if (insn & 0x100)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_sub_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_add_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 18:57:59 +04:00
|
|
|
|
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macsatf(cpu_env, tcg_const_i32(acc));
|
2007-05-29 18:57:59 +04:00
|
|
|
else if (s->env->macsr & MACSR_SU)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macsats(cpu_env, tcg_const_i32(acc));
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macsatu(cpu_env, tcg_const_i32(acc));
|
2007-05-29 18:57:59 +04:00
|
|
|
|
2008-05-25 02:29:16 +04:00
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 18:57:59 +04:00
|
|
|
if (l1 != -1)
|
|
|
|
gen_set_label(l1);
|
2008-05-25 02:29:16 +04:00
|
|
|
#endif
|
2007-05-29 18:57:59 +04:00
|
|
|
|
|
|
|
if (dual) {
|
|
|
|
/* Dual accumulate variant. */
|
|
|
|
acc = (ext >> 2) & 3;
|
|
|
|
/* Restore the overflow flag from the multiplier. */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(QREG_MACSR, saved_flags);
|
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 18:57:59 +04:00
|
|
|
if ((s->env->macsr & MACSR_OMC) != 0) {
|
|
|
|
/* Skip the accumulate if the value is already saturated. */
|
|
|
|
l1 = gen_new_label();
|
|
|
|
tmp = gen_new_qreg(QMODE_I32);
|
|
|
|
gen_op_and32(tmp, QREG_MACSR, gen_im32(MACSR_PAV0 << acc));
|
|
|
|
gen_op_jmp_nz32(tmp, l1);
|
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
#endif
|
2007-05-29 18:57:59 +04:00
|
|
|
if (ext & 2)
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_sub_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_add_i64(MACREG(acc), MACREG(acc), s->mactmp);
|
2007-05-29 18:57:59 +04:00
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macsatf(cpu_env, tcg_const_i32(acc));
|
2007-05-29 18:57:59 +04:00
|
|
|
else if (s->env->macsr & MACSR_SU)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macsats(cpu_env, tcg_const_i32(acc));
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_macsatu(cpu_env, tcg_const_i32(acc));
|
|
|
|
#if 0
|
|
|
|
/* Disabled because conditional branches clobber temporary vars. */
|
2007-05-29 18:57:59 +04:00
|
|
|
if (l1 != -1)
|
|
|
|
gen_set_label(l1);
|
2008-05-25 02:29:16 +04:00
|
|
|
#endif
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_mac_set_flags(cpu_env, tcg_const_i32(acc));
|
2007-05-29 18:57:59 +04:00
|
|
|
|
|
|
|
if (insn & 0x30) {
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv rw;
|
2007-05-29 18:57:59 +04:00
|
|
|
rw = (insn & 0x40) ? AREG(insn, 9) : DREG(insn, 9);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(rw, loadval);
|
2007-05-29 18:57:59 +04:00
|
|
|
/* FIXME: Should address writeback happen with the masked or
|
|
|
|
unmasked value? */
|
|
|
|
switch ((insn >> 3) & 7) {
|
|
|
|
case 3: /* Post-increment. */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_addi_i32(AREG(insn, 0), addr, 4);
|
2007-05-29 18:57:59 +04:00
|
|
|
break;
|
|
|
|
case 4: /* Pre-decrement. */
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(AREG(insn, 0), addr);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_mac)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv rx;
|
|
|
|
TCGv acc;
|
|
|
|
int accnum;
|
2007-05-29 18:57:59 +04:00
|
|
|
|
|
|
|
rx = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
accnum = (insn >> 9) & 3;
|
|
|
|
acc = MACREG(accnum);
|
2007-05-29 18:57:59 +04:00
|
|
|
if (s->env->macsr & MACSR_FI) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_get_macf(cpu_env, rx, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else if ((s->env->macsr & MACSR_OMC) == 0) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_trunc_i64_i32(rx, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else if (s->env->macsr & MACSR_SU) {
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_get_macs(rx, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04: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 18:57:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(move_mac)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
/* FIXME: This can be done without a helper. */
|
2007-05-29 18:57:59 +04:00
|
|
|
int src;
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv dest;
|
2007-05-29 18:57:59 +04:00
|
|
|
src = insn & 3;
|
2008-05-25 02:29:16 +04: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 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_macsr)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2007-05-29 18:57:59 +04:00
|
|
|
|
|
|
|
reg = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, QREG_MACSR);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_mask)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
2007-05-29 18:57:59 +04:00
|
|
|
reg = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_mov_i32(reg, QREG_MAC_MASK);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(from_mext)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv reg;
|
|
|
|
TCGv acc;
|
2007-05-29 18:57:59 +04:00
|
|
|
reg = (insn & 8) ? AREG(insn, 0) : DREG(insn, 0);
|
2008-05-25 02:29:16 +04:00
|
|
|
acc = tcg_const_i32((insn & 0x400) ? 2 : 0);
|
2007-05-29 18:57:59 +04:00
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_get_mac_extf(reg, cpu_env, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_get_mac_exti(reg, cpu_env, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(macsr_to_ccr)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_movi_i32(QREG_CC_X, 0);
|
|
|
|
tcg_gen_andi_i32(QREG_CC_DEST, QREG_MACSR, 0xf);
|
2007-05-29 18:57:59 +04:00
|
|
|
s->cc_op = CC_OP_FLAGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_mac)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv acc;
|
|
|
|
TCGv val;
|
|
|
|
int accnum;
|
|
|
|
accnum = (insn >> 9) & 3;
|
|
|
|
acc = MACREG(accnum);
|
2007-05-29 18:57:59 +04:00
|
|
|
SRC_EA(val, OS_LONG, 0, NULL);
|
|
|
|
if (s->env->macsr & MACSR_FI) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext_i32_i64(acc, val);
|
|
|
|
tcg_gen_shli_i64(acc, acc, 8);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else if (s->env->macsr & MACSR_SU) {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ext_i32_i64(acc, val);
|
2007-05-29 18:57:59 +04:00
|
|
|
} else {
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_extu_i32_i64(acc, val);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
2008-05-25 02:29:16 +04: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 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_macsr)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv val;
|
2007-05-29 18:57:59 +04:00
|
|
|
SRC_EA(val, OS_LONG, 0, NULL);
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_set_macsr(cpu_env, val);
|
2007-05-29 18:57:59 +04:00
|
|
|
gen_lookup_tb(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_mask)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv val;
|
2007-05-29 18:57:59 +04:00
|
|
|
SRC_EA(val, OS_LONG, 0, NULL);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_ori_i32(QREG_MAC_MASK, val, 0xffff0000);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DISAS_INSN(to_mext)
|
|
|
|
{
|
2008-05-25 02:29:16 +04:00
|
|
|
TCGv val;
|
|
|
|
TCGv acc;
|
2007-05-29 18:57:59 +04:00
|
|
|
SRC_EA(val, OS_LONG, 0, NULL);
|
2008-05-25 02:29:16 +04:00
|
|
|
acc = tcg_const_i32((insn & 0x400) ? 2 : 0);
|
2007-05-29 18:57:59 +04:00
|
|
|
if (s->env->macsr & MACSR_FI)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_set_mac_extf(cpu_env, val, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
else if (s->env->macsr & MACSR_SU)
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_set_mac_exts(cpu_env, val, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
else
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_set_mac_extu(cpu_env, val, acc);
|
2007-05-29 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
2006-10-22 04:18:54 +04: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 05:46:43 +04:00
|
|
|
if (opcode & ~mask) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"qemu internal error: bogus opcode definition %04x/%04x\n",
|
|
|
|
opcode, mask);
|
2006-10-22 04:18:54 +04:00
|
|
|
abort();
|
2007-05-28 05:46:43 +04:00
|
|
|
}
|
2006-10-22 04:18:54 +04: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-23 23:58:11 +04:00
|
|
|
for (i = from; i < to; i++) {
|
2006-10-22 04:18:54 +04:00
|
|
|
if ((i & mask) == opcode)
|
|
|
|
opcode_table[i] = proc;
|
2007-05-23 23:58:11 +04:00
|
|
|
}
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Register m68k opcode handlers. Order is important.
|
|
|
|
Later insn override earlier ones. */
|
2007-05-26 20:52:21 +04:00
|
|
|
void register_m68k_insns (CPUM68KState *env)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2007-06-03 16:35:08 +04:00
|
|
|
#define INSN(name, opcode, mask, feature) do { \
|
2007-05-26 20:52:21 +04:00
|
|
|
if (m68k_feature(env, M68K_FEATURE_##feature)) \
|
2007-06-03 16:35:08 +04:00
|
|
|
register_opcode(disas_##name, 0x##opcode, 0x##mask); \
|
|
|
|
} while(0)
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(undef, 0000, 0000, CF_ISA_A);
|
|
|
|
INSN(arith_im, 0080, fff8, CF_ISA_A);
|
2007-06-03 16:35:08 +04:00
|
|
|
INSN(bitrev, 00c0, fff8, CF_ISA_APLUSC);
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(bitop_reg, 0100, f1c0, CF_ISA_A);
|
|
|
|
INSN(bitop_reg, 0140, f1c0, CF_ISA_A);
|
|
|
|
INSN(bitop_reg, 0180, f1c0, CF_ISA_A);
|
|
|
|
INSN(bitop_reg, 01c0, f1c0, CF_ISA_A);
|
|
|
|
INSN(arith_im, 0280, fff8, CF_ISA_A);
|
2007-06-03 16:35:08 +04:00
|
|
|
INSN(byterev, 02c0, fff8, CF_ISA_APLUSC);
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(arith_im, 0480, fff8, CF_ISA_A);
|
2007-06-03 16:35:08 +04:00
|
|
|
INSN(ff1, 04c0, fff8, CF_ISA_APLUSC);
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(arith_im, 0680, fff8, CF_ISA_A);
|
|
|
|
INSN(bitop_im, 0800, ffc0, CF_ISA_A);
|
|
|
|
INSN(bitop_im, 0840, ffc0, CF_ISA_A);
|
|
|
|
INSN(bitop_im, 0880, ffc0, CF_ISA_A);
|
|
|
|
INSN(bitop_im, 08c0, ffc0, CF_ISA_A);
|
|
|
|
INSN(arith_im, 0a80, fff8, CF_ISA_A);
|
|
|
|
INSN(arith_im, 0c00, ff38, CF_ISA_A);
|
|
|
|
INSN(move, 1000, f000, CF_ISA_A);
|
|
|
|
INSN(move, 2000, f000, CF_ISA_A);
|
|
|
|
INSN(move, 3000, f000, CF_ISA_A);
|
2007-06-03 16:35:08 +04:00
|
|
|
INSN(strldsr, 40e7, ffff, CF_ISA_APLUSC);
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(negx, 4080, fff8, CF_ISA_A);
|
|
|
|
INSN(move_from_sr, 40c0, fff8, CF_ISA_A);
|
|
|
|
INSN(lea, 41c0, f1c0, CF_ISA_A);
|
|
|
|
INSN(clr, 4200, ff00, CF_ISA_A);
|
|
|
|
INSN(undef, 42c0, ffc0, CF_ISA_A);
|
|
|
|
INSN(move_from_ccr, 42c0, fff8, CF_ISA_A);
|
|
|
|
INSN(neg, 4480, fff8, CF_ISA_A);
|
|
|
|
INSN(move_to_ccr, 44c0, ffc0, CF_ISA_A);
|
|
|
|
INSN(not, 4680, fff8, CF_ISA_A);
|
|
|
|
INSN(move_to_sr, 46c0, ffc0, CF_ISA_A);
|
|
|
|
INSN(pea, 4840, ffc0, CF_ISA_A);
|
|
|
|
INSN(swap, 4840, fff8, CF_ISA_A);
|
|
|
|
INSN(movem, 48c0, fbc0, CF_ISA_A);
|
|
|
|
INSN(ext, 4880, fff8, CF_ISA_A);
|
|
|
|
INSN(ext, 48c0, fff8, CF_ISA_A);
|
|
|
|
INSN(ext, 49c0, fff8, CF_ISA_A);
|
|
|
|
INSN(tst, 4a00, ff00, CF_ISA_A);
|
|
|
|
INSN(tas, 4ac0, ffc0, CF_ISA_B);
|
|
|
|
INSN(halt, 4ac8, ffff, CF_ISA_A);
|
|
|
|
INSN(pulse, 4acc, ffff, CF_ISA_A);
|
|
|
|
INSN(illegal, 4afc, ffff, CF_ISA_A);
|
|
|
|
INSN(mull, 4c00, ffc0, CF_ISA_A);
|
|
|
|
INSN(divl, 4c40, ffc0, CF_ISA_A);
|
|
|
|
INSN(sats, 4c80, fff8, CF_ISA_B);
|
|
|
|
INSN(trap, 4e40, fff0, CF_ISA_A);
|
|
|
|
INSN(link, 4e50, fff8, CF_ISA_A);
|
|
|
|
INSN(unlk, 4e58, fff8, CF_ISA_A);
|
2007-06-03 15:13:39 +04:00
|
|
|
INSN(move_to_usp, 4e60, fff8, USP);
|
|
|
|
INSN(move_from_usp, 4e68, fff8, USP);
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(nop, 4e71, ffff, CF_ISA_A);
|
|
|
|
INSN(stop, 4e72, ffff, CF_ISA_A);
|
|
|
|
INSN(rte, 4e73, ffff, CF_ISA_A);
|
|
|
|
INSN(rts, 4e75, ffff, CF_ISA_A);
|
|
|
|
INSN(movec, 4e7b, ffff, CF_ISA_A);
|
|
|
|
INSN(jump, 4e80, ffc0, CF_ISA_A);
|
|
|
|
INSN(jump, 4ec0, ffc0, CF_ISA_A);
|
|
|
|
INSN(addsubq, 5180, f1c0, CF_ISA_A);
|
|
|
|
INSN(scc, 50c0, f0f8, CF_ISA_A);
|
|
|
|
INSN(addsubq, 5080, f1c0, CF_ISA_A);
|
|
|
|
INSN(tpf, 51f8, fff8, CF_ISA_A);
|
2007-06-03 16:35:08 +04:00
|
|
|
|
|
|
|
/* Branch instructions. */
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(branch, 6000, f000, CF_ISA_A);
|
2007-06-03 16:35:08 +04:00
|
|
|
/* Disable long branch instructions, then add back the ones we want. */
|
|
|
|
INSN(undef, 60ff, f0ff, CF_ISA_A); /* All long branches. */
|
|
|
|
INSN(branch, 60ff, f0ff, CF_ISA_B);
|
|
|
|
INSN(undef, 60ff, ffff, CF_ISA_B); /* bra.l */
|
|
|
|
INSN(branch, 60ff, ffff, BRAL);
|
|
|
|
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(moveq, 7000, f100, CF_ISA_A);
|
|
|
|
INSN(mvzs, 7100, f100, CF_ISA_B);
|
|
|
|
INSN(or, 8000, f000, CF_ISA_A);
|
|
|
|
INSN(divw, 80c0, f0c0, CF_ISA_A);
|
|
|
|
INSN(addsub, 9000, f000, CF_ISA_A);
|
|
|
|
INSN(subx, 9180, f1f8, CF_ISA_A);
|
|
|
|
INSN(suba, 91c0, f1c0, CF_ISA_A);
|
2007-05-29 18:57:59 +04:00
|
|
|
|
2007-05-26 20:52:21 +04:00
|
|
|
INSN(undef_mac, a000, f000, CF_ISA_A);
|
2007-05-29 18:57:59 +04: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-26 20:52:21 +04: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);
|
|
|
|
INSN(eor, b180, f1c0, CF_ISA_A);
|
|
|
|
INSN(and, c000, f000, CF_ISA_A);
|
|
|
|
INSN(mulw, c0c0, f0c0, CF_ISA_A);
|
|
|
|
INSN(addsub, d000, f000, CF_ISA_A);
|
|
|
|
INSN(addx, d180, f1f8, CF_ISA_A);
|
|
|
|
INSN(adda, d1c0, f1c0, CF_ISA_A);
|
|
|
|
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 04:18:54 +04:00
|
|
|
INSN(fpu, f200, ffc0, CF_FPU);
|
|
|
|
INSN(fbcc, f280, ffc0, CF_FPU);
|
2007-05-23 23:58:11 +04:00
|
|
|
INSN(frestore, f340, ffc0, CF_FPU);
|
|
|
|
INSN(fsave, f340, ffc0, CF_FPU);
|
2007-05-26 20:52:21 +04: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 04:18:54 +04: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. */
|
|
|
|
static void disas_m68k_insn(CPUState * env, DisasContext *s)
|
|
|
|
{
|
|
|
|
uint16_t insn;
|
|
|
|
|
2007-05-23 23:58:11 +04:00
|
|
|
insn = lduw_code(s->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
s->pc += 2;
|
|
|
|
|
|
|
|
opcode_table[insn](s, insn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* generate intermediate code for basic block 'tb'. */
|
2008-07-18 22:01:29 +04:00
|
|
|
static inline void
|
2007-03-20 00:46:06 +03:00
|
|
|
gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
|
|
|
|
int search_pc)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
|
|
|
DisasContext dc1, *dc = &dc1;
|
|
|
|
uint16_t *gen_opc_end;
|
|
|
|
int j, lj;
|
|
|
|
target_ulong pc_start;
|
|
|
|
int pc_offset;
|
|
|
|
int last_cc_op;
|
2008-06-29 05:03:05 +04:00
|
|
|
int num_insns;
|
|
|
|
int max_insns;
|
2006-10-22 04:18:54 +04:00
|
|
|
|
|
|
|
/* generate intermediate code */
|
|
|
|
pc_start = tb->pc;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2006-10-22 04:18:54 +04:00
|
|
|
dc->tb = tb;
|
|
|
|
|
|
|
|
gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
|
|
|
|
|
2007-05-27 01:16:48 +04:00
|
|
|
dc->env = env;
|
2006-10-22 04:18:54 +04:00
|
|
|
dc->is_jmp = DISAS_NEXT;
|
|
|
|
dc->pc = pc_start;
|
|
|
|
dc->cc_op = CC_OP_DYNAMIC;
|
|
|
|
dc->singlestep_enabled = env->singlestep_enabled;
|
|
|
|
dc->fpcr = env->fpcr;
|
2007-05-23 23:58:11 +04:00
|
|
|
dc->user = (env->sr & SR_S) == 0;
|
2007-06-10 01:30:14 +04:00
|
|
|
dc->is_mem = 0;
|
2008-05-25 02:29:16 +04:00
|
|
|
dc->mactmp = NULL_QREG;
|
2006-10-22 04:18:54 +04:00
|
|
|
lj = -1;
|
2008-06-29 05:03:05 +04:00
|
|
|
num_insns = 0;
|
|
|
|
max_insns = tb->cflags & CF_COUNT_MASK;
|
|
|
|
if (max_insns == 0)
|
|
|
|
max_insns = CF_COUNT_MASK;
|
|
|
|
|
|
|
|
gen_icount_start();
|
2006-10-22 04:18:54 +04:00
|
|
|
do {
|
|
|
|
pc_offset = dc->pc - pc_start;
|
|
|
|
gen_throws_exception = NULL;
|
|
|
|
if (env->nb_breakpoints > 0) {
|
|
|
|
for(j = 0; j < env->nb_breakpoints; j++) {
|
|
|
|
if (env->breakpoints[j] == dc->pc) {
|
|
|
|
gen_exception(dc, dc->pc, EXCP_DEBUG);
|
|
|
|
dc->is_jmp = DISAS_JUMP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dc->is_jmp)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (search_pc) {
|
|
|
|
j = gen_opc_ptr - gen_opc_buf;
|
|
|
|
if (lj < j) {
|
|
|
|
lj++;
|
|
|
|
while (lj < j)
|
|
|
|
gen_opc_instr_start[lj++] = 0;
|
|
|
|
}
|
|
|
|
gen_opc_pc[lj] = dc->pc;
|
|
|
|
gen_opc_instr_start[lj] = 1;
|
2008-06-29 05:03:05 +04:00
|
|
|
gen_opc_icount[lj] = num_insns;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
2008-06-29 05:03:05 +04:00
|
|
|
if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
|
|
|
|
gen_io_start();
|
2006-10-22 04:18:54 +04:00
|
|
|
last_cc_op = dc->cc_op;
|
2007-05-27 02:11:13 +04:00
|
|
|
dc->insn_pc = dc->pc;
|
2006-10-22 04:18:54 +04:00
|
|
|
disas_m68k_insn(env, dc);
|
2008-06-29 05:03:05 +04:00
|
|
|
num_insns++;
|
2007-06-10 01:30:14 +04:00
|
|
|
|
|
|
|
/* Terminate the TB on memory ops if watchpoints are present. */
|
2008-06-30 21:22:19 +04:00
|
|
|
/* FIXME: This should be replaced by the deterministic execution
|
2007-06-10 01:30:14 +04:00
|
|
|
* IRQ raising bits. */
|
|
|
|
if (dc->is_mem && env->nb_watchpoints)
|
|
|
|
break;
|
2006-10-22 04:18:54 +04:00
|
|
|
} while (!dc->is_jmp && gen_opc_ptr < gen_opc_end &&
|
|
|
|
!env->singlestep_enabled &&
|
2008-06-29 05:03:05 +04:00
|
|
|
(pc_offset) < (TARGET_PAGE_SIZE - 32) &&
|
|
|
|
num_insns < max_insns);
|
2006-10-22 04:18:54 +04:00
|
|
|
|
2008-06-29 05:03:05 +04:00
|
|
|
if (tb->cflags & CF_LAST_IO)
|
|
|
|
gen_io_end();
|
2008-07-03 21:57:36 +04:00
|
|
|
if (unlikely(env->singlestep_enabled)) {
|
2006-10-22 04:18:54 +04:00
|
|
|
/* Make sure the pc is updated, and raise a debug exception. */
|
|
|
|
if (!dc->is_jmp) {
|
|
|
|
gen_flush_cc_op(dc);
|
2008-05-25 02:29:16 +04:00
|
|
|
tcg_gen_movi_i32(QREG_PC, dc->pc);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
2008-05-25 02:29:16 +04:00
|
|
|
gen_helper_raise_exception(tcg_const_i32(EXCP_DEBUG));
|
2006-10-22 04:18:54 +04:00
|
|
|
} else {
|
|
|
|
switch(dc->is_jmp) {
|
|
|
|
case DISAS_NEXT:
|
|
|
|
gen_flush_cc_op(dc);
|
|
|
|
gen_jmp_tb(dc, 0, dc->pc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case DISAS_JUMP:
|
|
|
|
case DISAS_UPDATE:
|
|
|
|
gen_flush_cc_op(dc);
|
|
|
|
/* indicate that the hash table must be used to find the next TB */
|
2008-02-01 13:50:11 +03:00
|
|
|
tcg_gen_exit_tb(0);
|
2006-10-22 04:18:54 +04:00
|
|
|
break;
|
|
|
|
case DISAS_TB_JUMP:
|
|
|
|
/* nothing more to generate */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 05:03:05 +04:00
|
|
|
gen_icount_end(tb, num_insns);
|
2006-10-22 04:18:54 +04:00
|
|
|
*gen_opc_ptr = INDEX_op_end;
|
|
|
|
|
|
|
|
#ifdef DEBUG_DISAS
|
|
|
|
if (loglevel & CPU_LOG_TB_IN_ASM) {
|
|
|
|
fprintf(logfile, "----------------\n");
|
|
|
|
fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
|
|
|
|
target_disas(logfile, pc_start, dc->pc - pc_start, 0);
|
|
|
|
fprintf(logfile, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (search_pc) {
|
|
|
|
j = gen_opc_ptr - gen_opc_buf;
|
|
|
|
lj++;
|
|
|
|
while (lj <= j)
|
|
|
|
gen_opc_instr_start[lj++] = 0;
|
|
|
|
} else {
|
|
|
|
tb->size = dc->pc - pc_start;
|
2008-06-29 05:03:05 +04:00
|
|
|
tb->icount = num_insns;
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//optimize_flags();
|
|
|
|
//expand_target_qops();
|
|
|
|
}
|
|
|
|
|
2008-07-18 22:01:29 +04:00
|
|
|
void gen_intermediate_code(CPUState *env, TranslationBlock *tb)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-07-18 22:01:29 +04:00
|
|
|
gen_intermediate_code_internal(env, tb, 0);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
2008-07-18 22:01:29 +04:00
|
|
|
void gen_intermediate_code_pc(CPUState *env, TranslationBlock *tb)
|
2006-10-22 04:18:54 +04:00
|
|
|
{
|
2008-07-18 22:01:29 +04:00
|
|
|
gen_intermediate_code_internal(env, tb, 1);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
void cpu_dump_state(CPUState *env, FILE *f,
|
2006-10-22 04:18:54 +04:00
|
|
|
int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint16_t sr;
|
|
|
|
CPU_DoubleU u;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
u.d = env->fregs[i];
|
|
|
|
cpu_fprintf (f, "D%d = %08x A%d = %08x F%d = %08x%08x (%12g)\n",
|
|
|
|
i, env->dregs[i], i, env->aregs[i],
|
2007-11-10 20:43:49 +03:00
|
|
|
i, u.l.upper, u.l.lower, *(double *)&u.d);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
cpu_fprintf (f, "PC = %08x ", env->pc);
|
|
|
|
sr = env->sr;
|
|
|
|
cpu_fprintf (f, "SR = %04x %c%c%c%c%c ", sr, (sr & 0x10) ? 'X' : '-',
|
|
|
|
(sr & CCF_N) ? 'N' : '-', (sr & CCF_Z) ? 'Z' : '-',
|
|
|
|
(sr & CCF_V) ? 'V' : '-', (sr & CCF_C) ? 'C' : '-');
|
2007-11-10 20:43:49 +03:00
|
|
|
cpu_fprintf (f, "FPRESULT = %12g\n", *(double *)&env->fp_result);
|
2006-10-22 04:18:54 +04:00
|
|
|
}
|
|
|
|
|
2008-04-28 04:32:32 +04:00
|
|
|
void gen_pc_load(CPUState *env, TranslationBlock *tb,
|
|
|
|
unsigned long searched_pc, int pc_pos, void *puc)
|
|
|
|
{
|
|
|
|
env->pc = gen_opc_pc[pc_pos];
|
|
|
|
}
|