redquark-amiberry-rb/src/include/newcpu.h

404 lines
9.7 KiB
C
Raw Normal View History

2016-11-30 22:25:43 +01:00
/*
* UAE - The Un*x Amiga Emulator
*
* MC68000 emulation
*
* Copyright 1995 Bernd Schmidt
*/
2017-12-04 15:49:40 +01:00
#ifndef UAE_NEWCPU_H
#define UAE_NEWCPU_H
2015-05-13 18:47:23 +00:00
2017-12-04 15:49:40 +01:00
#include "uae/types.h"
2015-05-13 18:47:23 +00:00
#include "readcpu.h"
#include "machdep/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
2016-11-30 22:25:43 +01:00
typedef uae_u32 REGPARAM3 cpuop_func (uae_u32) REGPARAM;
typedef void REGPARAM3 cpuop_func_ce (uae_u32) REGPARAM;
2015-05-13 18:47:23 +00:00
2016-11-30 22:25:43 +01:00
struct cputbl {
2017-12-04 15:49:40 +01:00
cpuop_func *handler;
uae_u16 opcode;
uae_s8 length;
uae_s8 disp020[2];
uae_u8 branch;
2015-05-13 18:47:23 +00:00
};
#ifdef JIT
#define MAX_JIT_CACHE 16384
typedef uae_u32 REGPARAM3 compop_func (uae_u32) REGPARAM;
2015-05-13 18:47:23 +00:00
#define COMP_OPCODE_ISJUMP 0x0001
#define COMP_OPCODE_LONG_OPCODE 0x0002
#define COMP_OPCODE_CMOV 0x0004
#define COMP_OPCODE_ISADDX 0x0008
#define COMP_OPCODE_ISCJUMP 0x0010
#define COMP_OPCODE_USES_FPU 0x0020
2016-11-30 22:25:43 +01:00
struct comptbl {
2017-12-04 15:49:40 +01:00
compop_func *handler;
2016-11-30 22:25:43 +01:00
uae_u32 specific;
2017-12-04 15:49:40 +01:00
uae_u32 opcode;
2015-05-13 18:47:23 +00:00
};
#endif
2016-11-30 22:25:43 +01:00
extern uae_u32 REGPARAM3 op_illg (uae_u32) REGPARAM;
2015-05-13 18:47:23 +00:00
typedef uae_u8 flagtype;
2015-05-13 18:47:23 +00:00
#ifdef FPUEMU
typedef double fptype;
#define LDPTR qword ptr
#endif
2016-11-30 22:25:43 +01:00
typedef struct
2015-05-13 18:47:23 +00:00
{
2016-11-30 22:25:43 +01:00
fptype fp;
} fpdata;
2016-11-30 22:25:43 +01:00
struct regstruct
{
uae_u32 regs[16];
struct flag_struct ccrflags;
uae_u32 pc;
uae_u8 *pc_p;
uae_u8 *pc_oldp;
2017-12-04 15:49:40 +01:00
uae_u16 opcode;
2016-11-30 22:25:43 +01:00
uae_u32 instruction_pc;
2017-12-04 15:49:40 +01:00
uae_u16 irc, ir, db;
volatile uae_atomic spcflags;
2017-12-04 15:49:40 +01:00
2016-11-30 22:25:43 +01:00
uaecptr usp, isp, msp;
uae_u16 sr;
flagtype t1;
flagtype t0;
flagtype s;
flagtype m;
flagtype x;
flagtype stopped;
2017-12-04 15:49:40 +01:00
int halted;
2016-11-30 22:25:43 +01:00
int intmask;
uae_u32 vbr,sfc,dfc;
2015-05-13 18:47:23 +00:00
#ifdef FPUEMU
2016-11-30 22:25:43 +01:00
fpdata fp[8];
#ifdef JIT
fpdata fp_result;
#endif
2016-11-30 22:25:43 +01:00
uae_u32 fpcr,fpsr, fpiar;
uae_u32 fpu_state;
uae_u32 fpu_exp_state;
2017-12-04 15:49:40 +01:00
uae_u16 fp_opword;
uaecptr fp_ea;
uae_u32 fp_exp_pend, fp_unimp_pend;
bool fpu_exp_pre;
bool fp_unimp_ins;
2016-11-30 22:25:43 +01:00
bool fp_exception;
2017-12-04 15:49:40 +01:00
bool fp_branch;
2015-05-13 18:47:23 +00:00
#endif
2016-11-30 22:25:43 +01:00
uae_u32 cacr, caar;
uae_u32 itt0, itt1, dtt0, dtt1;
uae_u32 tcr, mmusr, urp, srp, buscr;
2015-05-13 18:47:23 +00:00
2016-11-30 22:25:43 +01:00
uae_u32 pcr;
uae_u32 address_space_mask;
2017-12-04 15:49:40 +01:00
uae_s32 pissoff;
uae_u8* natmem_offset;
};
2016-11-30 22:25:43 +01:00
extern struct regstruct regs;
2015-05-13 18:47:23 +00:00
2017-12-04 15:49:40 +01:00
#define REGS_DEFINED
#include "machdep/m68k.h"
#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;
2017-12-04 15:49:40 +01:00
extern int m68k_pc_indirect;
2015-05-13 18:47:23 +00:00
2017-12-04 15:49:40 +01:00
STATIC_INLINE void set_special (uae_u32 x)
2015-05-13 18:47:23 +00:00
{
2017-12-04 15:49:40 +01:00
atomic_or(&regs.spcflags, x);
cycles_do_special();
2015-05-13 18:47:23 +00:00
}
2016-11-30 22:25:43 +01:00
STATIC_INLINE void unset_special (uae_u32 x)
2015-05-13 18:47:23 +00:00
{
2017-12-04 15:49:40 +01:00
atomic_and(&regs.spcflags, ~x);
2015-05-13 18:47:23 +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
2017-12-04 15:49:40 +01:00
extern uae_u32(*x_get_byte)(uaecptr addr);
extern uae_u32(*x_get_word)(uaecptr addr);
extern uae_u32(*x_get_long)(uaecptr addr);
extern void(*x_put_byte)(uaecptr addr, uae_u32 v);
extern void(*x_put_word)(uaecptr addr, uae_u32 v);
extern void(*x_put_long)(uaecptr addr, uae_u32 v);
#define x_cp_get_byte x_get_byte
#define x_cp_get_word x_get_word
#define x_cp_get_long x_get_long
#define x_cp_put_byte x_put_byte
#define x_cp_put_word x_put_word
#define x_cp_put_long x_put_long
#define x_cp_next_iword() next_diword()
#define x_cp_next_ilong() next_dilong()
#define x_cp_get_disp_ea_020(base,idx) _get_disp_ea_020(base)
2016-11-30 22:25:43 +01:00
/* direct (regs.pc_p) access */
STATIC_INLINE void m68k_setpc (uaecptr newpc)
2015-05-13 18:47:23 +00:00
{
2016-11-30 22:25:43 +01: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-11-30 22:25:43 +01:00
STATIC_INLINE uaecptr m68k_getpc (void)
2015-05-13 18:47:23 +00:00
{
2016-11-30 22:25:43 +01:00
return (uaecptr)(regs.pc + ((uae_u8*)regs.pc_p - (uae_u8*)regs.pc_oldp));
2015-05-13 18:47:23 +00:00
}
2016-11-30 22:25:43 +01:00
#define M68K_GETPC m68k_getpc()
2018-01-20 18:14:12 +01:00
STATIC_INLINE void m68k_incpc(int o)
{
regs.pc_p += o;
}
2015-05-13 18:47:23 +00:00
2018-01-20 18:14:12 +01:00
STATIC_INLINE uae_u32 get_dibyte(int o)
{
return do_get_mem_byte((uae_u8 *)((regs).pc_p + (o) + 1));
}
2017-12-04 15:49:40 +01:00
STATIC_INLINE uae_u32 get_diword(int o)
{
return do_get_mem_word((uae_u16 *)((regs).pc_p + (o)));
}
2018-01-20 18:14:12 +01:00
STATIC_INLINE uae_u32 get_dilong(int o)
{
return do_get_mem_long((uae_u32 *)((regs).pc_p + (o)));
}
2016-11-30 22:25:43 +01:00
STATIC_INLINE uae_u32 next_diword (void)
2015-09-09 21:49:41 +02:00
{
2016-11-30 22:25:43 +01:00
uae_u32 r = do_get_mem_word((uae_u16 *)((regs).pc_p));
m68k_incpc (2);
return r;
2015-09-09 21:49:41 +02:00
}
2016-11-30 22:25:43 +01:00
STATIC_INLINE uae_u32 next_dilong (void)
{
uae_u32 r = do_get_mem_long((uae_u32 *)((regs).pc_p));
m68k_incpc (4);
return r;
}
STATIC_INLINE void m68k_do_bsr (uaecptr oldpc, uae_s32 offset)
{
m68k_areg(regs, 7) -= 4;
put_long(m68k_areg(regs, 7), oldpc);
m68k_incpc (offset);
}
STATIC_INLINE void m68k_do_rts (void)
{
uae_u32 newpc = get_long (m68k_areg (regs, 7));
m68k_setpc (newpc);
m68k_areg(regs, 7) += 4;
}
/* indirect (regs.pc) access */
2015-09-09 21:49:41 +02:00
2018-01-20 18:14:12 +01:00
STATIC_INLINE void m68k_setpci(uaecptr newpc)
{
regs.instruction_pc = regs.pc = newpc;
}
2016-11-30 22:25:43 +01:00
STATIC_INLINE uaecptr m68k_getpci(void)
2015-09-09 21:49:41 +02:00
{
2016-11-30 22:25:43 +01:00
return regs.pc;
2015-09-09 21:49:41 +02:00
}
2018-01-20 18:14:12 +01:00
STATIC_INLINE void m68k_incpci(int o)
{
regs.pc += o;
}
2015-09-09 21:49:41 +02:00
2017-12-04 15:49:40 +01:00
STATIC_INLINE uae_u32 get_iiword(int o)
{
return get_wordi(m68k_getpci() + (o));
}
2016-11-30 22:25:43 +01:00
STATIC_INLINE void m68k_do_bsri(uaecptr oldpc, uae_s32 offset)
{
m68k_areg(regs, 7) -= 4;
put_long(m68k_areg(regs, 7), oldpc);
m68k_incpci(offset);
}
STATIC_INLINE void m68k_do_rtsi(void)
{
uae_u32 newpc = get_long(m68k_areg(regs, 7));
m68k_setpci(newpc);
m68k_areg(regs, 7) += 4;
}
2016-11-30 22:25:43 +01:00
/* common access */
2015-05-13 18:47:23 +00:00
2016-11-30 22:25:43 +01:00
STATIC_INLINE void m68k_incpc_normal(int o)
2015-05-13 18:47:23 +00:00
{
2017-12-04 15:49:40 +01:00
if (m68k_pc_indirect > 0)
2016-11-30 22:25:43 +01:00
m68k_incpci(o);
else
m68k_incpc(o);
2015-05-13 18:47:23 +00:00
}
2016-11-30 22:25:43 +01:00
STATIC_INLINE void m68k_setpc_normal(uaecptr pc)
2015-05-13 18:47:23 +00:00
{
2017-12-04 15:49:40 +01:00
if (m68k_pc_indirect > 0) {
2016-11-30 22:25:43 +01:00
regs.pc_p = regs.pc_oldp = 0;
m68k_setpci(pc);
2017-12-04 15:49:40 +01:00
} else {
2016-11-30 22:25:43 +01:00
m68k_setpc(pc);
}
2015-09-09 21:49:41 +02:00
}
2015-05-13 18:47:23 +00:00
2017-12-04 15:49:40 +01:00
extern void check_t0_trace(void);
2016-11-30 22:25:43 +01:00
#define x_do_cycles(c) do_cycles(c)
extern void m68k_setstopped (void);
extern void m68k_resumestopped (void);
2016-11-30 22:25:43 +01:00
#define get_disp_ea_020(base,idx) _get_disp_ea_020(base)
extern uae_u32 REGPARAM3 _get_disp_ea_020 (uae_u32 base) 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-11-30 22:25:43 +01:00
extern void set_cpu_caches (bool flush);
2018-01-20 18:14:12 +01:00
extern void flush_cpu_caches(bool flush);
extern void flush_cpu_caches_040(uae_u16 opcode);
2016-11-30 22:25:43 +01:00
extern void REGPARAM3 MakeSR (void) REGPARAM;
extern void REGPARAM3 MakeFromSR (void) REGPARAM;
2017-12-04 15:49:40 +01:00
extern void REGPARAM3 MakeFromSR_T0(void) REGPARAM;
2016-11-30 22:25:43 +01:00
extern void REGPARAM3 Exception (int) REGPARAM;
2017-12-04 15:49:40 +01:00
extern void REGPARAM3 Exception_cpu(int) REGPARAM;
extern void NMI (void);
2015-09-09 21:49:41 +02:00
extern void doint (void);
extern void dump_counts (void);
2015-05-13 18:47:23 +00:00
extern int m68k_move2c (int, uae_u32 *);
extern int m68k_movec2 (int, uae_u32 *);
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);
extern int getDivu68kCycles(uae_u32 dividend, uae_u16 divisor);
extern int getDivs68kCycles(uae_s32 dividend, uae_s16 divisor);
2017-12-04 15:49:40 +01:00
extern void divbyzero_special (bool issigned, uae_s32 dst);
2018-01-20 18:14:12 +01:00
extern void setdivuoverflowflags(uae_u32 dividend, uae_u16 divisor);
extern void setdivsoverflowflags(uae_s32 dividend, uae_s16 divisor);
extern void protect_roms (bool);
2017-12-04 15:49:40 +01:00
extern bool is_hardreset(void);
2015-10-11 14:23:51 +02:00
STATIC_INLINE int bitset_count16(uae_u16 data)
{
2016-11-30 22:25:43 +01:00
unsigned int const MASK1 = 0x5555;
unsigned int const MASK2 = 0x3333;
unsigned int const MASK4 = 0x0f0f;
unsigned int const MASK6 = 0x003f;
2016-11-30 22:25:43 +01:00
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)) & MASK6;
2016-11-30 22:25:43 +01:00
return z;
}
2016-11-30 22:25:43 +01:00
extern void mmu_op (uae_u32, uae_u32);
2017-12-04 15:49:40 +01:00
extern bool mmu_op30 (uaecptr, uae_u32, uae_u16, uaecptr);
2015-05-13 18:47:23 +00:00
2016-11-30 22:25:43 +01:00
extern void fpuop_arithmetic(uae_u32, uae_u16);
extern void fpuop_dbcc(uae_u32, uae_u16);
extern void fpuop_scc(uae_u32, uae_u16);
extern void fpuop_trapcc(uae_u32, uaecptr, uae_u16);
extern void fpuop_bcc(uae_u32, uaecptr, uae_u32);
extern void fpuop_save(uae_u32);
extern void fpuop_restore(uae_u32);
extern void fpu_reset (void);
2016-11-30 22:25:43 +01:00
extern int fpp_cond(int condition);
2015-05-13 18:47:23 +00:00
2017-12-04 15:49:40 +01:00
extern void exception3_read(uae_u32 opcode, uaecptr addr);
extern void exception3_write(uae_u32 opcode, uaecptr addr);
extern void exception3_notinstruction(uae_u32 opcode, uaecptr addr);
extern void exception3i (uae_u32 opcode, uaecptr addr);
2016-11-30 22:25:43 +01:00
extern void exception3b (uae_u32 opcode, uaecptr addr, bool w, bool i, uaecptr pc);
2017-12-04 15:49:40 +01:00
extern void exception2 (uaecptr addr, bool read, int size, uae_u32 fc);
2015-05-13 18:47:23 +00:00
extern void cpureset (void);
2016-11-30 22:25:43 +01:00
extern void cpu_halt (int id);
2018-01-20 18:14:12 +01:00
extern int cpu_sleep_millis(int ms);
2015-05-13 18:47:23 +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
/* 68040 */
2015-05-13 18:47:23 +00:00
extern const struct cputbl op_smalltbl_1_ff[];
2017-12-04 15:49:40 +01:00
extern const struct cputbl op_smalltbl_41_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[];
2017-12-04 15:49:40 +01:00
extern const struct cputbl op_smalltbl_42_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[];
2017-12-04 15:49:40 +01:00
extern const struct cputbl op_smalltbl_43_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[];
2017-12-04 15:49:40 +01:00
extern const struct cputbl op_smalltbl_44_ff[];
2016-11-30 22:25:43 +01:00
extern const struct cputbl op_smalltbl_11_ff[]; // prefetch
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[];
2017-12-04 15:49:40 +01:00
extern const struct cputbl op_smalltbl_45_ff[];
2016-11-30 22:25:43 +01:00
extern const struct cputbl op_smalltbl_12_ff[]; // prefetch
2015-05-13 18:47:23 +00:00
extern cpuop_func *cpufunctbl[65536] ASM_SYM_FOR_FUNC ("cpufunctbl");
#ifdef JIT
2017-12-04 15:49:40 +01:00
extern void flush_icache(int);
extern void flush_icache_hard(int);
2015-05-13 18:47:23 +00:00
extern void compemu_reset(void);
#else
2017-12-04 15:49:40 +01:00
#define flush_icache(int) do {} while (0)
#define flush_icache_hard(int) do {} while (0)
2015-05-13 18:47:23 +00:00
#endif
2017-12-04 15:49:40 +01:00
bool check_prefs_changed_comp (bool);
2015-09-09 21:49:41 +02:00
extern int movec_illg (int regno);
2016-11-30 22:25:43 +01:00
2017-12-04 15:49:40 +01:00
#define CPU_HALT_BUS_ERROR_DOUBLE_FAULT 1
#define CPU_HALT_DOUBLE_FAULT 2
#define CPU_HALT_OPCODE_FETCH_FROM_NON_EXISTING_ADDRESS 3
#define CPU_HALT_FAKE_DMA 6
#define CPU_HALT_AUTOCONFIG_CONFLICT 7
#define CPU_HALT_SSP_IN_NON_EXISTING_ADDRESS 10
#define CPU_HALT_INVALID_START_ADDRESS 11
#endif /* UAE_NEWCPU_H */