2018-04-16 01:23:12 +00:00
|
|
|
/*
|
2019-09-02 19:40:01 +00:00
|
|
|
* newcpu.h - CPU emulation
|
2018-04-16 01:23:12 +00:00
|
|
|
*
|
2019-09-02 19:40:01 +00:00
|
|
|
* Copyright (c) 2009 ARAnyM dev team (see AUTHORS)
|
|
|
|
*
|
|
|
|
* Inspired by Christian Bauer's Basilisk II
|
2018-04-16 01:23:12 +00:00
|
|
|
*
|
2019-09-02 19:40:01 +00:00
|
|
|
* This file is part of the ARAnyM project which builds a new and powerful
|
|
|
|
* TOS/FreeMiNT compatible virtual machine running on almost any hardware.
|
2018-04-16 01:23:12 +00:00
|
|
|
*
|
2019-09-02 19:40:01 +00:00
|
|
|
* ARAnyM is free software; you can redistribute it and/or modify
|
2018-04-16 01:23:12 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2019-09-02 19:40:01 +00:00
|
|
|
* ARAnyM is distributed in the hope that it will be useful,
|
2018-04-16 01:23:12 +00:00
|
|
|
* 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
|
2019-09-02 19:40:01 +00:00
|
|
|
* along with ARAnyM; if not, write to the Free Software
|
2018-04-16 01:23:12 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2019-09-02 19:40:01 +00:00
|
|
|
/*
|
|
|
|
* UAE - The Un*x Amiga Emulator
|
|
|
|
*
|
|
|
|
* MC68000 emulation
|
|
|
|
*
|
|
|
|
* Copyright 1995 Bernd Schmidt
|
|
|
|
*/
|
2018-04-15 22:33:50 +00:00
|
|
|
|
2018-04-16 01:23:12 +00:00
|
|
|
#ifndef NEWCPU_H
|
|
|
|
#define NEWCPU_H
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
#include "sysdeps.h"
|
|
|
|
#include "registers.h"
|
2018-04-23 01:39:37 +00:00
|
|
|
#include "spcflags.h"
|
2019-09-02 19:40:01 +00:00
|
|
|
#include "m68k.h"
|
|
|
|
#include "memory.h"
|
2018-04-16 01:23:12 +00:00
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
# include <csetjmp>
|
2018-04-16 01:23:12 +00:00
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
extern struct fixup {
|
|
|
|
int flag;
|
|
|
|
uae_u32 reg;
|
|
|
|
uaecptr value;
|
|
|
|
}fixup;
|
2002-09-17 16:05:39 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
extern int areg_byteinc[];
|
|
|
|
extern int imm8_table[];
|
|
|
|
|
|
|
|
extern int movem_index1[256];
|
|
|
|
extern int movem_index2[256];
|
|
|
|
extern int movem_next[256];
|
|
|
|
|
2018-04-15 22:33:50 +00:00
|
|
|
extern int broken_in;
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2018-04-16 01:23:12 +00:00
|
|
|
#ifdef X86_ASSEMBLY
|
|
|
|
/* This hack seems to force all register saves (pushl %reg) to be moved to the
|
|
|
|
begining of the function, thus making it possible to cpuopti to remove them
|
|
|
|
since m68k_run_1 will save those registers before calling the instruction
|
|
|
|
handler */
|
|
|
|
# define cpuop_tag(tag) __asm__ __volatile__ ( "#cpuop_" tag )
|
|
|
|
#else
|
|
|
|
# define cpuop_tag(tag) ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define cpuop_begin() do { cpuop_tag("begin"); } while (0)
|
2019-09-02 19:40:01 +00:00
|
|
|
#define cpuop_end() do { cpuop_tag("end"); } while (0)
|
2018-04-16 01:23:12 +00:00
|
|
|
|
2002-11-02 18:13:29 +00:00
|
|
|
typedef void REGPARAM2 cpuop_func (uae_u32) REGPARAM;
|
2019-09-02 19:40:01 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
struct cputbl {
|
|
|
|
cpuop_func *handler;
|
2018-04-16 01:23:12 +00:00
|
|
|
uae_u16 specific;
|
1999-10-03 14:16:26 +00:00
|
|
|
uae_u16 opcode;
|
|
|
|
};
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
extern cpuop_func *cpufunctbl[65536];
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
#ifdef USE_JIT
|
2018-04-16 01:23:12 +00:00
|
|
|
typedef void compop_func (uae_u32) REGPARAM;
|
|
|
|
|
|
|
|
struct comptbl {
|
|
|
|
compop_func *handler;
|
2019-09-02 19:40:01 +00:00
|
|
|
uae_u32 opcode;
|
|
|
|
uae_u32 specific;
|
2018-04-16 01:23:12 +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
|
|
|
|
};
|
|
|
|
#endif
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2018-04-16 01:23:12 +00:00
|
|
|
extern void REGPARAM2 op_illg (uae_u32) REGPARAM;
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
#define m68k_dreg(r,num) ((r).regs[(num)])
|
|
|
|
#define m68k_areg(r,num) (((r).regs + 8)[(num)])
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
#ifdef FULLMMU
|
|
|
|
static ALWAYS_INLINE uae_u8 get_ibyte(uae_u32 o)
|
|
|
|
{
|
|
|
|
return mmu_get_byte(m68k_getpc() + o + 1, 0, sz_byte);
|
|
|
|
}
|
|
|
|
static ALWAYS_INLINE uae_u16 get_iword(uae_u32 o)
|
|
|
|
{
|
|
|
|
return mmu_get_word(m68k_getpc() + o, 0, sz_word);
|
|
|
|
}
|
|
|
|
static ALWAYS_INLINE uae_u32 get_ilong(uae_u32 o)
|
|
|
|
{
|
|
|
|
uaecptr addr = m68k_getpc() + o;
|
|
|
|
|
|
|
|
if (unlikely(is_unaligned(addr, 4)))
|
|
|
|
return mmu_get_long_unaligned(addr, 0);
|
|
|
|
return mmu_get_long(addr, 0, sz_long);
|
|
|
|
}
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
#else
|
2019-09-02 19:40:01 +00:00
|
|
|
#define get_ibyte(o) do_get_mem_byte((uae_u8 *)(get_real_address(m68k_getpc(), 0, sz_byte) + (o) + 1))
|
|
|
|
#define get_iword(o) do_get_mem_word((uae_u16 *)(get_real_address(m68k_getpc(), 0, sz_word) + (o)))
|
|
|
|
#define get_ilong(o) do_get_mem_long((uae_u32 *)(get_real_address(m68k_getpc(), 0, sz_long) + (o)))
|
1999-10-03 14:16:26 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
#if 0
|
|
|
|
static inline uae_u32 get_ibyte_prefetch (uae_s32 o)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
if (o > 3 || o < 0)
|
2019-09-02 19:40:01 +00:00
|
|
|
return do_get_mem_byte((uae_u8 *)(do_get_real_address(regs.pcp, false, false) + o + 1));
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
return do_get_mem_byte((uae_u8 *)(((uae_u8 *)®s.prefetch) + o + 1));
|
|
|
|
}
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline uae_u32 get_iword_prefetch (uae_s32 o)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
if (o > 3 || o < 0)
|
2019-09-02 19:40:01 +00:00
|
|
|
return do_get_mem_word((uae_u16 *)(do_get_real_address(regs.pcp, false, false) + o));
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
return do_get_mem_word((uae_u16 *)(((uae_u8 *)®s.prefetch) + o));
|
|
|
|
}
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline uae_u32 get_ilong_prefetch (uae_s32 o)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
if (o > 3 || o < 0)
|
2019-09-02 19:40:01 +00:00
|
|
|
return do_get_mem_long((uae_u32 *)(do_get_real_address(regs.pcp, false, false) + o));
|
1999-10-03 14:16:26 +00:00
|
|
|
if (o == 0)
|
|
|
|
return do_get_mem_long(®s.prefetch);
|
2019-09-02 19:40:01 +00:00
|
|
|
return (do_get_mem_word (((uae_u16 *)®s.prefetch) + 1) << 16) | do_get_mem_word ((uae_u16 *)(do_get_real_address(regs.pcp, false, false) + 4));
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
2018-04-16 01:23:12 +00:00
|
|
|
#endif
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
#ifdef FULLMMU
|
|
|
|
#define m68k_incpc(o) (regs.pc += (o))
|
|
|
|
#else
|
|
|
|
#define m68k_incpc(o) (regs.pc_p += (o))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void fill_prefetch_0 (void)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
2018-04-16 01:23:12 +00:00
|
|
|
#if USE_PREFETCH_BUFFER
|
1999-10-03 14:16:26 +00:00
|
|
|
uae_u32 r;
|
|
|
|
#ifdef UNALIGNED_PROFITABLE
|
2019-09-02 19:40:01 +00:00
|
|
|
r = *(uae_u32 *)do_get_real_address(m68k_getpc(), false, false);
|
1999-10-03 14:16:26 +00:00
|
|
|
regs.prefetch = r;
|
|
|
|
#else
|
2019-09-02 19:40:01 +00:00
|
|
|
r = do_get_mem_long ((uae_u32 *)do_get_real_address(m68k_getpc(), false, false));
|
1999-10-03 14:16:26 +00:00
|
|
|
do_put_mem_long (®s.prefetch, r);
|
|
|
|
#endif
|
2018-04-16 01:23:12 +00:00
|
|
|
#endif
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline void fill_prefetch_2 (void)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
uae_u32 r = do_get_mem_long (®s.prefetch) << 16;
|
2019-09-02 19:40:01 +00:00
|
|
|
uae_u32 r2 = do_get_mem_word (((uae_u16 *)do_get_real_address(regs.pcp, false, false)) + 1);
|
1999-10-03 14:16:26 +00:00
|
|
|
r |= r2;
|
|
|
|
do_put_mem_long (®s.prefetch, r);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define fill_prefetch_2 fill_prefetch_0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* These are only used by the 68020/68881 code, and therefore don't
|
|
|
|
* need to handle prefetch. */
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline uae_u32 next_ibyte (void)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
uae_u32 r = get_ibyte (0);
|
|
|
|
m68k_incpc (2);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline uae_u32 next_iword (void)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
uae_u32 r = get_iword (0);
|
|
|
|
m68k_incpc (2);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline uae_u32 next_ilong (void)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
uae_u32 r = get_ilong (0);
|
|
|
|
m68k_incpc (4);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline void m68k_setpc (uaecptr newpc)
|
|
|
|
{
|
|
|
|
#ifndef FULLMMU
|
|
|
|
regs.pc_p = regs.pc_oldp = get_real_address(newpc, 0, sz_word);
|
|
|
|
#endif
|
|
|
|
regs.fault_pc = regs.pc = newpc;
|
|
|
|
}
|
|
|
|
|
2018-04-16 01:23:12 +00:00
|
|
|
#define m68k_setpc_fast m68k_setpc
|
|
|
|
#define m68k_setpc_bcc m68k_setpc
|
|
|
|
#define m68k_setpc_rte m68k_setpc
|
1999-10-03 14:16:26 +00:00
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline void m68k_do_rts(void)
|
2001-03-20 17:35:46 +00:00
|
|
|
{
|
2019-09-02 19:40:01 +00:00
|
|
|
m68k_setpc(get_long(m68k_areg(regs, 7)));
|
|
|
|
m68k_areg(regs, 7) += 4;
|
2001-03-20 17:35:46 +00:00
|
|
|
}
|
2018-04-16 01:23:12 +00:00
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline void m68k_do_bsr(uaecptr oldpc, uae_s32 offset)
|
2001-03-20 17:35:46 +00:00
|
|
|
{
|
2019-09-02 19:40:01 +00:00
|
|
|
put_long(m68k_areg(regs, 7) - 4, oldpc);
|
|
|
|
m68k_areg(regs, 7) -= 4;
|
|
|
|
m68k_incpc(offset);
|
2001-03-20 17:35:46 +00:00
|
|
|
}
|
2018-04-16 01:23:12 +00:00
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline void m68k_do_jsr(uaecptr oldpc, uaecptr dest)
|
2001-03-20 17:35:46 +00:00
|
|
|
{
|
2019-09-02 19:40:01 +00:00
|
|
|
put_long(m68k_areg(regs, 7) - 4, oldpc);
|
|
|
|
m68k_areg(regs, 7) -= 4;
|
|
|
|
m68k_setpc(dest);
|
2001-03-20 17:35:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
static inline void m68k_setstopped (int stop)
|
1999-10-03 14:16:26 +00:00
|
|
|
{
|
|
|
|
regs.stopped = stop;
|
2018-04-16 01:23:12 +00:00
|
|
|
/* A traced STOP instruction drops through immediately without
|
|
|
|
actually stopping. */
|
2019-09-02 19:40:01 +00:00
|
|
|
if (stop && !( SPCFLAGS_TEST( SPCFLAG_DOTRACE )))
|
|
|
|
SPCFLAGS_SET( SPCFLAG_STOP );
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
#ifdef FULLMMU
|
|
|
|
# define GET_OPCODE (get_iword (0))
|
|
|
|
#elif defined ARAM_PAGE_CHECK
|
|
|
|
# ifdef HAVE_GET_WORD_UNSWAPPED
|
|
|
|
# define GET_OPCODE (do_get_mem_word_unswapped((uae_u16*)(pc + pc_offset)));
|
|
|
|
# else
|
|
|
|
# define GET_OPCODE (do_get_mem_word((uae_u16*)(pc + pc_offset)));
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_GET_WORD_UNSWAPPED
|
|
|
|
# define GET_OPCODE (do_get_mem_word_unswapped ((uae_u16*)get_real_address(m68k_getpc(), 0, sz_word)))
|
|
|
|
# else
|
|
|
|
# define GET_OPCODE (get_iword (0))
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern REGPARAM uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp);
|
|
|
|
extern REGPARAM uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp);
|
|
|
|
extern REGPARAM uae_u32 get_bitfield(uae_u32 src, uae_u32 bdata[2], uae_s32 offset, int width);
|
|
|
|
extern REGPARAM void put_bitfield(uae_u32 dst, uae_u32 bdata[2], uae_u32 val, uae_s32 offset, int width);
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern void MakeSR (void);
|
|
|
|
extern void MakeFromSR (void);
|
|
|
|
extern void Exception (int, uaecptr);
|
2020-01-12 15:50:04 +00:00
|
|
|
extern void ex_rte(void);
|
1999-10-03 14:16:26 +00:00
|
|
|
extern void dump_counts (void);
|
2018-04-16 01:23:12 +00:00
|
|
|
extern int m68k_move2c (int, uae_u32 *);
|
|
|
|
extern int m68k_movec2 (int, uae_u32 *);
|
1999-10-03 14:16:26 +00:00
|
|
|
extern void m68k_divl (uae_u32, uae_u32, uae_u16, uaecptr);
|
|
|
|
extern void m68k_mull (uae_u32, uae_u32, uae_u16);
|
2018-04-16 01:23:12 +00:00
|
|
|
extern void m68k_emulop (uae_u32);
|
|
|
|
extern void m68k_emulop_return (void);
|
2019-09-02 19:40:01 +00:00
|
|
|
extern void m68k_natfeat_id(void);
|
|
|
|
extern void m68k_natfeat_call(void);
|
1999-10-03 14:16:26 +00:00
|
|
|
extern void init_m68k (void);
|
2018-04-16 01:23:12 +00:00
|
|
|
extern void exit_m68k (void);
|
2019-09-02 19:40:01 +00:00
|
|
|
extern void m68k_dumpstate (FILE *, uaecptr *);
|
|
|
|
extern void m68k_disasm (FILE *, uaecptr, uaecptr *, int);
|
|
|
|
extern void newm68k_disasm(FILE *, uaecptr, uaecptr *, unsigned int);
|
|
|
|
extern void showDisasm(uaecptr);
|
1999-10-03 14:16:26 +00:00
|
|
|
extern void m68k_reset (void);
|
|
|
|
extern void m68k_enter_debugger(void);
|
2018-04-16 01:23:12 +00:00
|
|
|
extern int m68k_do_specialties(void);
|
2019-09-02 19:40:01 +00:00
|
|
|
extern void m68k_instr_set(void);
|
|
|
|
uae_u32 linea68000(uae_u16 opcode);
|
2018-04-15 22:33:50 +00:00
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
/* Opcode of faulting instruction */
|
|
|
|
extern uae_u16 last_op_for_exception_3;
|
|
|
|
/* PC at fault time */
|
|
|
|
extern uaecptr last_addr_for_exception_3;
|
|
|
|
/* Address that generated the exception */
|
|
|
|
extern uaecptr last_fault_for_exception_3;
|
|
|
|
|
|
|
|
#define CPU_OP_NAME(a) op ## a
|
|
|
|
|
2019-09-02 19:40:01 +00:00
|
|
|
/* 68040+ 68881 */
|
|
|
|
extern const struct cputbl op_smalltbl_0_ff[];
|
|
|
|
extern const struct cputbl op_smalltbl_0_nf[];
|
|
|
|
|
|
|
|
#ifdef FLIGHT_RECORDER
|
|
|
|
extern void m68k_record_step(uaecptr, int);
|
2018-04-16 01:23:12 +00:00
|
|
|
#endif
|
2019-09-02 19:40:01 +00:00
|
|
|
|
2018-04-16 01:23:12 +00:00
|
|
|
extern void m68k_do_execute(void);
|
|
|
|
extern void m68k_execute(void);
|
2019-09-02 19:40:01 +00:00
|
|
|
#ifdef USE_JIT
|
2018-04-16 01:23:12 +00:00
|
|
|
extern void m68k_compile_execute(void);
|
2019-09-02 19:40:01 +00:00
|
|
|
extern void m68k_do_compile_execute(void);
|
2018-04-16 01:23:12 +00:00
|
|
|
#endif
|
2022-03-16 04:40:14 +00:00
|
|
|
extern void cpu_do_check_ticks(void);
|
2018-04-16 01:23:12 +00:00
|
|
|
#ifdef USE_CPU_EMUL_SERVICES
|
|
|
|
extern int32 emulated_ticks;
|
|
|
|
|
|
|
|
static inline void cpu_check_ticks(void)
|
|
|
|
{
|
|
|
|
if (--emulated_ticks <= 0)
|
|
|
|
cpu_do_check_ticks();
|
|
|
|
}
|
|
|
|
#else
|
2022-03-16 04:40:14 +00:00
|
|
|
extern uint16 emulated_ticks;
|
|
|
|
static inline void cpu_check_ticks(void)
|
|
|
|
{
|
|
|
|
if (!++emulated_ticks)
|
|
|
|
cpu_do_check_ticks();
|
|
|
|
}
|
2018-04-16 01:23:12 +00:00
|
|
|
#endif
|
2019-09-02 19:40:01 +00:00
|
|
|
|
|
|
|
cpuop_func op_illg_1;
|
|
|
|
|
2018-04-16 01:23:12 +00:00
|
|
|
#endif /* NEWCPU_H */
|