2015-05-13 18:47:23 +00:00
|
|
|
/*
|
|
|
|
* newcpu.h - CPU emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 ARAnyM dev team (see AUTHORS)
|
|
|
|
*
|
|
|
|
* Inspired by Christian Bauer's Basilisk II
|
|
|
|
*
|
|
|
|
* This file is part of the ARAnyM project which builds a new and powerful
|
|
|
|
* TOS/FreeMiNT compatible virtual machine running on almost any hardware.
|
|
|
|
*
|
|
|
|
* ARAnyM is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* ARAnyM 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 General Public License
|
|
|
|
* along with ARAnyM; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* UAE - The Un*x Amiga Emulator
|
|
|
|
*
|
|
|
|
* MC68000 emulation
|
|
|
|
*
|
|
|
|
* Copyright 1995 Bernd Schmidt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "readcpu.h"
|
2015-05-23 13:28:13 +00:00
|
|
|
#include "md-pandora/m68k.h"
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
extern const int areg_byteinc[];
|
|
|
|
extern const int imm8_table[];
|
|
|
|
|
|
|
|
extern int movem_index1[256];
|
|
|
|
extern int movem_index2[256];
|
|
|
|
extern int movem_next[256];
|
|
|
|
|
|
|
|
#ifdef FPUEMU
|
|
|
|
extern int fpp_movem_index1[256];
|
|
|
|
extern int fpp_movem_index2[256];
|
|
|
|
extern int fpp_movem_next[256];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct regstruct;
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
typedef unsigned long REGPARAM3 cpuop_func (uae_u32, struct regstruct ®s) REGPARAM;
|
|
|
|
typedef void REGPARAM3 cpuop_func_ce (uae_u32, struct regstruct ®s) REGPARAM;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
struct cputbl {
|
|
|
|
cpuop_func *handler;
|
|
|
|
uae_u16 opcode;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef JIT
|
|
|
|
typedef unsigned long REGPARAM3 compop_func (uae_u32) REGPARAM;
|
|
|
|
|
|
|
|
struct comptbl {
|
|
|
|
compop_func *handler;
|
|
|
|
uae_u32 specific;
|
|
|
|
uae_u32 opcode;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern unsigned long REGPARAM3 op_illg (uae_u32, struct regstruct ®s) REGPARAM;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
typedef uae_u8 flagtype;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
#ifdef FPUEMU
|
|
|
|
/* You can set this to long double to be more accurate. However, the
|
|
|
|
resulting alignment issues will cost a lot of performance in some
|
|
|
|
apps */
|
|
|
|
#define USE_LONG_DOUBLE 0
|
|
|
|
|
|
|
|
#if USE_LONG_DOUBLE
|
|
|
|
typedef long double fptype;
|
|
|
|
#define LDPTR tbyte ptr
|
|
|
|
#else
|
|
|
|
typedef double fptype;
|
|
|
|
#define LDPTR qword ptr
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
struct regstruct
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 regs[16];
|
|
|
|
struct flag_struct ccrflags;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 pc;
|
|
|
|
uae_u8 *pc_p;
|
|
|
|
uae_u8 *pc_oldp;
|
|
|
|
uae_u32 instruction_pc;
|
2016-04-25 17:12:37 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u16 irc, ir;
|
|
|
|
uae_u32 spcflags;
|
2015-09-09 21:49:41 +02:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
uaecptr usp, isp, msp;
|
|
|
|
uae_u16 sr;
|
|
|
|
flagtype t1;
|
|
|
|
flagtype t0;
|
|
|
|
flagtype s;
|
|
|
|
flagtype m;
|
|
|
|
flagtype x;
|
|
|
|
flagtype stopped;
|
|
|
|
int intmask;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 vbr,sfc,dfc;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
#ifdef FPUEMU
|
2016-04-24 09:45:29 +00:00
|
|
|
fptype fp[8];
|
|
|
|
fptype fp_result;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 fpcr,fpsr, fpiar;
|
|
|
|
uae_u32 fpsr_highbyte;
|
2015-05-13 18:47:23 +00:00
|
|
|
#endif
|
2015-09-09 21:49:41 +02:00
|
|
|
#ifndef CPUEMU_68000_ONLY
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 cacr, caar;
|
|
|
|
uae_u32 itt0, itt1, dtt0, dtt1;
|
|
|
|
uae_u32 tcr, mmusr, urp, srp, buscr;
|
2015-09-09 21:49:41 +02:00
|
|
|
#endif
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 pcr;
|
|
|
|
uae_u32 address_space_mask;
|
|
|
|
|
|
|
|
uae_u8 panic;
|
|
|
|
uae_u32 panic_pc, panic_addr;
|
2016-04-25 17:12:37 +00:00
|
|
|
signed long pissoff;
|
2016-04-24 09:45:29 +00:00
|
|
|
};
|
|
|
|
extern unsigned long int nextevent, is_syncline, currcycle;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern struct regstruct regs;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#include "events.h"
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
STATIC_INLINE uae_u32 munge24(uae_u32 x)
|
|
|
|
{
|
|
|
|
return x & regs.address_space_mask;
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
extern int cpu_cycles;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE void set_special (struct regstruct ®s, uae_u32 x)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
regs.spcflags |= x;
|
2016-04-25 17:12:37 +00:00
|
|
|
cycles_do_special(regs);
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE void unset_special (struct regstruct ®s, uae_u32 x)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
regs.spcflags &= ~x;
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#define m68k_dreg(r,num) ((r).regs[(num)])
|
|
|
|
#define m68k_areg(r,num) (((r).regs + 8)[(num)])
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE void m68k_setpc (struct regstruct ®s, uaecptr newpc)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
regs.pc_p = regs.pc_oldp = get_real_address (newpc);
|
|
|
|
regs.instruction_pc = regs.pc = newpc;
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE uaecptr m68k_getpc (struct regstruct ®s)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
return (uaecptr)(regs.pc + ((uae_u8*)regs.pc_p - (uae_u8*)regs.pc_oldp));
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
2016-04-24 09:45:29 +00:00
|
|
|
#define M68K_GETPC m68k_getpc(regs)
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#define m68k_incpc(o) ((regs).pc_p += (o))
|
2015-09-09 21:49:41 +02:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE uaecptr m68k_getpci (struct regstruct ®s)
|
2015-09-09 21:49:41 +02:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
return regs.pc;
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE void m68k_do_rts (struct regstruct ®s)
|
2015-09-09 21:49:41 +02:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 newpc = get_long (m68k_areg (regs, 7));
|
|
|
|
m68k_setpc (regs, newpc);
|
|
|
|
m68k_areg(regs, 7) += 4;
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE void m68k_do_bsr (struct regstruct ®s, uaecptr oldpc, uae_s32 offset)
|
2015-09-09 21:49:41 +02:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
m68k_areg(regs, 7) -= 4;
|
|
|
|
put_long(m68k_areg(regs, 7), oldpc);
|
|
|
|
m68k_incpc (offset);
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#define get_ibyte(o) do_get_mem_byte((uae_u8 *)((regs).pc_p + (o) + 1))
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#define get_iword(o) do_get_mem_word((uae_u16 *)((regs).pc_p + (o)))
|
|
|
|
#define get_ilong(o) do_get_mem_long((uae_u32 *)((regs).pc_p + (o)))
|
|
|
|
#define get_iword2(regs,o) do_get_mem_word((uae_u16 *)((regs).pc_p + (o)))
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
/* These are only used by the 68020/68881 code, and therefore don't
|
|
|
|
* need to handle prefetch. */
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE uae_u32 next_iword (struct regstruct ®s)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 r = get_iword (0);
|
|
|
|
m68k_incpc (2);
|
|
|
|
return r;
|
2015-05-13 18:47:23 +00:00
|
|
|
}
|
2016-04-24 09:45:29 +00:00
|
|
|
STATIC_INLINE uae_u32 next_ilong (struct regstruct ®s)
|
2015-05-13 18:47:23 +00:00
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
uae_u32 r = get_ilong (0);
|
|
|
|
m68k_incpc (4);
|
|
|
|
return r;
|
2015-09-09 21:49:41 +02:00
|
|
|
}
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
#ifndef x_get_byte
|
|
|
|
#define x_get_byte(x) get_byte(x)
|
|
|
|
#define x_get_word(x) get_word(x)
|
|
|
|
#define x_get_long(x) get_long(x)
|
|
|
|
#define x_put_byte(x,y) put_byte(x,y)
|
|
|
|
#define x_put_word(x,y) put_word(x,y)
|
|
|
|
#define x_put_long(x,y) put_long(x,y)
|
|
|
|
#endif
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern uae_u32 REGPARAM3 x_get_disp_ea_020 (struct regstruct ®s, uae_u32 base, uae_u32 dp) REGPARAM;
|
|
|
|
|
|
|
|
extern void m68k_setstopped (void);
|
|
|
|
extern void m68k_resumestopped (void);
|
|
|
|
|
|
|
|
extern uae_u32 REGPARAM3 get_disp_ea_020 (struct regstruct ®s, uae_u32 base, uae_u32 dp) REGPARAM;
|
|
|
|
extern uae_u32 REGPARAM3 get_bitfield (uae_u32 src, uae_u32 bdata[2], uae_s32 offset, int width) REGPARAM;
|
|
|
|
extern void REGPARAM3 put_bitfield (uae_u32 dst, uae_u32 bdata[2], uae_u32 val, uae_s32 offset, int width) REGPARAM;
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
extern int get_cpu_model(void);
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern void REGPARAM3 MakeSR (struct regstruct ®s) REGPARAM;
|
|
|
|
extern void REGPARAM3 MakeFromSR (struct regstruct ®s) REGPARAM;
|
|
|
|
extern void REGPARAM3 Exception (int, struct regstruct ®s) REGPARAM;
|
2015-09-09 21:49:41 +02:00
|
|
|
extern void doint (void);
|
2015-05-13 18:47:23 +00:00
|
|
|
extern int m68k_move2c (int, uae_u32 *);
|
|
|
|
extern int m68k_movec2 (int, uae_u32 *);
|
2016-04-24 09:45:29 +00:00
|
|
|
extern void m68k_divl (uae_u32, uae_u32, uae_u16);
|
2015-05-13 18:47:23 +00:00
|
|
|
extern void m68k_mull (uae_u32, uae_u32, uae_u16);
|
|
|
|
extern void init_m68k (void);
|
|
|
|
extern void m68k_go (int);
|
2015-09-09 21:49:41 +02:00
|
|
|
extern void m68k_reset (int);
|
2015-05-13 18:47:23 +00:00
|
|
|
extern int getDivu68kCycles(uae_u32 dividend, uae_u16 divisor);
|
|
|
|
extern int getDivs68kCycles(uae_s32 dividend, uae_s16 divisor);
|
|
|
|
|
2015-10-11 14:23:51 +02:00
|
|
|
STATIC_INLINE int bitset_count(uae_u32 data)
|
|
|
|
{
|
2016-04-24 09:45:29 +00:00
|
|
|
unsigned int const MASK1 = 0x55555555;
|
|
|
|
unsigned int const MASK2 = 0x33333333;
|
|
|
|
unsigned int const MASK4 = 0x0f0f0f0f;
|
|
|
|
unsigned int const MASK6 = 0x0000003f;
|
|
|
|
|
|
|
|
unsigned int const w = (data & MASK1) + ((data >> 1) & MASK1);
|
|
|
|
unsigned int const x = (w & MASK2) + ((w >> 2) & MASK2);
|
|
|
|
unsigned int const y = ((x + (x >> 4)) & MASK4);
|
|
|
|
unsigned int const z = (y + (y >> 8));
|
|
|
|
unsigned int const c = (z + (z >> 16)) & MASK6;
|
|
|
|
|
|
|
|
return c;
|
2015-10-11 14:23:51 +02:00
|
|
|
}
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern void mmu_op (uae_u32, struct regstruct ®s, uae_u32);
|
|
|
|
extern void mmu_op30 (uaecptr, uae_u32, struct regstruct ®s, uae_u16, uaecptr);
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern void fpuop_arithmetic(uae_u32, struct regstruct ®s, uae_u16);
|
|
|
|
extern void fpuop_dbcc(uae_u32, struct regstruct ®s, uae_u16);
|
|
|
|
extern void fpuop_scc(uae_u32, struct regstruct ®s, uae_u16);
|
|
|
|
extern void fpuop_trapcc(uae_u32, struct regstruct ®s, uaecptr, uae_u16);
|
|
|
|
extern void fpuop_bcc(uae_u32, struct regstruct ®s, uaecptr, uae_u32);
|
|
|
|
extern void fpuop_save(uae_u32, struct regstruct ®s);
|
|
|
|
extern void fpuop_restore(uae_u32, struct regstruct ®s);
|
|
|
|
extern void fpu_reset (void);
|
2015-05-13 18:47:23 +00:00
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern void exception3 (uae_u32 opcode, uaecptr addr);
|
|
|
|
extern void exception3i (uae_u32 opcode, uaecptr addr);
|
2015-05-13 18:47:23 +00:00
|
|
|
extern void cpureset (void);
|
|
|
|
|
2016-04-24 09:45:29 +00:00
|
|
|
extern void fill_prefetch (void);
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
#define CPU_OP_NAME(a) op ## a
|
|
|
|
|
2015-09-09 21:49:41 +02:00
|
|
|
/* 68060 */
|
2015-05-13 18:47:23 +00:00
|
|
|
extern const struct cputbl op_smalltbl_0_ff[];
|
2015-09-09 21:49:41 +02:00
|
|
|
/* 68040 */
|
2015-05-13 18:47:23 +00:00
|
|
|
extern const struct cputbl op_smalltbl_1_ff[];
|
2015-09-09 21:49:41 +02:00
|
|
|
/* 68030 */
|
2015-05-13 18:47:23 +00:00
|
|
|
extern const struct cputbl op_smalltbl_2_ff[];
|
2015-09-09 21:49:41 +02:00
|
|
|
/* 68020 */
|
2015-05-13 18:47:23 +00:00
|
|
|
extern const struct cputbl op_smalltbl_3_ff[];
|
2015-09-09 21:49:41 +02:00
|
|
|
/* 68010 */
|
2015-05-13 18:47:23 +00:00
|
|
|
extern const struct cputbl op_smalltbl_4_ff[];
|
2015-09-09 21:49:41 +02:00
|
|
|
/* 68000 */
|
2015-05-13 18:47:23 +00:00
|
|
|
extern const struct cputbl op_smalltbl_5_ff[];
|
2015-09-09 21:49:41 +02:00
|
|
|
/* 68000 slow but compatible. */
|
|
|
|
extern const struct cputbl op_smalltbl_11_ff[];
|
2015-05-13 18:47:23 +00:00
|
|
|
|
|
|
|
extern cpuop_func *cpufunctbl[65536] ASM_SYM_FOR_FUNC ("cpufunctbl");
|
|
|
|
|
|
|
|
#ifdef JIT
|
2016-04-24 09:45:29 +00:00
|
|
|
extern void (*flush_icache)(uaecptr, int);
|
2015-05-13 18:47:23 +00:00
|
|
|
extern void compemu_reset(void);
|
2016-04-24 09:45:29 +00:00
|
|
|
extern bool check_prefs_changed_comp (void);
|
2015-05-13 18:47:23 +00:00
|
|
|
#else
|
2016-04-24 09:45:29 +00:00
|
|
|
#define flush_icache(uaecptr, int) do {} while (0)
|
2015-05-13 18:47:23 +00:00
|
|
|
#endif
|
2015-09-09 21:49:41 +02:00
|
|
|
|
|
|
|
extern int movec_illg (int regno);
|