--- hatari/src/uae-cpu/newcpu.h 2019/04/01 07:09:30 1.1.1.2 +++ hatari/src/uae-cpu/newcpu.h 2019/04/01 07:11:37 1.1.1.7 @@ -1,33 +1,35 @@ /* * UAE - The Un*x Amiga Emulator - CPU core - * + * * MC68000 emulation * * Copyright 1995 Bernd Schmidt * * Adaptation to Hatari by Thomas Huth * + * This file is distributed under the GNU Public License, version 2 or at + * your option any later version. Read the file gpl.txt for details. */ -#ifndef UAENEWCPU -#define UAENEWCPU +#ifndef UAE_NEWCPU_H +#define UAE_NEWCPU_H #include "readcpu.h" #include "m68k.h" -/* custom chip support */ +/* Special flags */ #define SPCFLAG_STOP 2 -/*#define SPCFLAG_COPPER 4*/ +#define SPCFLAG_BUSERROR 4 #define SPCFLAG_INT 8 -#define SPCFLAG_BRK 16 -#define SPCFLAG_EXTRA_CYCLES 32 -#define SPCFLAG_TRACE 64 -#define SPCFLAG_DOTRACE 128 -#define SPCFLAG_DOINT 256 -/*#define SPCFLAG_BLTNASTY 512*/ -#define SPCFLAG_EXEC 1024 -#define SPCFLAG_MODE_CHANGE 8192 +#define SPCFLAG_BRK 0x10 +#define SPCFLAG_EXTRA_CYCLES 0x20 +#define SPCFLAG_TRACE 0x40 +#define SPCFLAG_DOTRACE 0x80 +#define SPCFLAG_DOINT 0x100 +#define SPCFLAG_MFP 0x200 +#define SPCFLAG_EXEC 0x400 +#define SPCFLAG_MODE_CHANGE 0x800 #ifndef SET_CFLG @@ -65,7 +67,6 @@ extern int fpp_movem_index1[256]; extern int fpp_movem_index2[256]; extern int fpp_movem_next[256]; -extern int broken_in; typedef unsigned long cpuop_func (uae_u32) REGPARAM; @@ -79,6 +80,17 @@ extern unsigned long op_illg (uae_u32) R typedef char flagtype; +/* 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; +#else +typedef double fptype; +#endif + extern struct regstruct { uae_u32 regs[16]; @@ -98,16 +110,15 @@ extern struct regstruct uae_u32 vbr,sfc,dfc; - double fp[8]; + fptype fp[8]; + fptype fp_result; + uae_u32 fpcr,fpsr,fpiar; + uae_u32 fpsr_highbyte; uae_u32 spcflags; - /* Fellow sources say this is 4 longwords. That's impossible. It needs - * to be at least a longword. The HRM has some cryptic comment about two - * instructions being on the same longword boundary. - * The way this is implemented now seems like a good compromise. - */ + uae_u32 prefetch_pc; uae_u32 prefetch; } regs, lastint_regs; @@ -124,58 +135,91 @@ STATIC_INLINE void unset_special (uae_u3 #define m68k_dreg(r,num) ((r).regs[(num)]) #define m68k_areg(r,num) (((r).regs + 8)[(num)]) -#define get_ibyte(o) do_get_mem_byte((uae_u8 *)(regs.pc_p + (o) + 1)) -#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))) -STATIC_INLINE uae_u32 get_ibyte_prefetch (uae_s32 o) +STATIC_INLINE void m68k_setpc (uaecptr newpc) { - if (o > 3 || o < 0) - return do_get_mem_byte((uae_u8 *)(regs.pc_p + o + 1)); - - return do_get_mem_byte((uae_u8 *)(((uae_u8 *)®s.prefetch) + o + 1)); + regs.pc_p = regs.pc_oldp = get_real_address (newpc); + regs.pc = newpc; } -STATIC_INLINE uae_u32 get_iword_prefetch (uae_s32 o) -{ - if (o > 3 || o < 0) - return do_get_mem_word((uae_u16 *)(regs.pc_p + o)); - return do_get_mem_word((uae_u16 *)(((uae_u8 *)®s.prefetch) + o)); +STATIC_INLINE uaecptr m68k_getpc (void) +{ + return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp); } -STATIC_INLINE uae_u32 get_ilong_prefetch (uae_s32 o) + +STATIC_INLINE uaecptr m68k_getpc_p (uae_u8 *p) { - if (o > 3 || o < 0) - return do_get_mem_long((uae_u32 *)(regs.pc_p + o)); - if (o == 0) - return do_get_mem_long(®s.prefetch); - return (do_get_mem_word (((uae_u16 *)®s.prefetch) + 1) << 16) | do_get_mem_word ((uae_u16 *)(regs.pc_p + 4)); + return regs.pc + ((char *)p - (char *)regs.pc_oldp); } -#define m68k_incpc(o) (regs.pc_p += (o)) +#define get_ibyte(o) do_get_mem_byte((uae_u8 *)(regs.pc_p + (o) + 1)) +#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))) -STATIC_INLINE void fill_prefetch_0 (void) +STATIC_INLINE void refill_prefetch (uae_u32 currpc, uae_u32 offs) { + uae_u32 t = (currpc + offs) & ~1; + uae_s32 pc_p_offs = t - currpc; + uae_u8 *ptr = regs.pc_p + pc_p_offs; uae_u32 r; #ifdef UNALIGNED_PROFITABLE - r = *(uae_u32 *)regs.pc_p; + r = *(uae_u32 *)ptr; regs.prefetch = r; #else - r = do_get_mem_long ((uae_u32 *)regs.pc_p); + r = do_get_mem_long ((uae_u32 *)ptr); do_put_mem_long (®s.prefetch, r); #endif + /* printf ("PC %lx T %lx PCPOFFS %d R %lx\n", currpc, t, pc_p_offs, r); */ + regs.prefetch_pc = t; } -#if 0 -STATIC_INLINE void fill_prefetch_2 (void) +STATIC_INLINE uae_u32 get_ibyte_prefetch (uae_s32 o) { - uae_u32 r = do_get_mem_long (®s.prefetch) << 16; - uae_u32 r2 = do_get_mem_word (((uae_u16 *)regs.pc_p) + 1); - r |= r2; - do_put_mem_long (®s.prefetch, r); + uae_u32 currpc = m68k_getpc (); + uae_u32 addr = currpc + o + 1; + uae_u32 offs = addr - regs.prefetch_pc; + uae_u32 v; + if (offs > 3) { + refill_prefetch (currpc, o + 1); + offs = addr - regs.prefetch_pc; + } + v = do_get_mem_byte (((uae_u8 *)®s.prefetch) + offs); + if (offs >= 2) + refill_prefetch (currpc, 2); + /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */ + return v; } -#else +STATIC_INLINE uae_u32 get_iword_prefetch (uae_s32 o) +{ + uae_u32 currpc = m68k_getpc (); + uae_u32 addr = currpc + o; + uae_u32 offs = addr - regs.prefetch_pc; + uae_u32 v; + if (offs > 3) { + refill_prefetch (currpc, o); + offs = addr - regs.prefetch_pc; + } + v = do_get_mem_word ((uae_u16 *)(((uae_u8 *)®s.prefetch) + offs)); + if (offs >= 2) + refill_prefetch (currpc, 2); + /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */ + return v; +} +STATIC_INLINE uae_u32 get_ilong_prefetch (uae_s32 o) +{ + uae_u32 v = get_iword_prefetch (o); + v <<= 16; + v |= get_iword_prefetch (o + 2); + return v; +} + +#define m68k_incpc(o) (regs.pc_p += (o)) + +STATIC_INLINE void fill_prefetch_0 (void) +{ +} + #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. */ @@ -200,43 +244,42 @@ STATIC_INLINE uae_u32 next_ilong (void) return r; } -#if !defined USE_COMPILER -STATIC_INLINE void m68k_setpc (uaecptr newpc) +#define m68k_setpc_bcc m68k_setpc +#define m68k_setpc_rte m68k_setpc + +STATIC_INLINE void m68k_setstopped (int stop) { - regs.pc_p = regs.pc_oldp = (uae_u8 *)get_real_address(newpc); - regs.pc = newpc; + regs.stopped = stop; + /* A traced STOP instruction drops through immediately without + actually stopping. */ + if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0) + regs.spcflags |= SPCFLAG_STOP; } -#else -extern void m68k_setpc (uaecptr newpc); -#endif -STATIC_INLINE uaecptr m68k_getpc (void) +/* m68k_do_rts, m68k_do_bsr and m68k_do_jsr were originally defined in + * compiler.h, but since that header file has been removed from Hatari, + * they are now defined here: */ +STATIC_INLINE void m68k_do_rts(void) { - return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp); + m68k_setpc(get_long(m68k_areg(regs, 7))); + m68k_areg(regs, 7) += 4; } -STATIC_INLINE uaecptr m68k_getpc_p (uae_u8 *p) +STATIC_INLINE void m68k_do_bsr(uaecptr oldpc, uae_s32 offset) { - return regs.pc + ((char *)p - (char *)regs.pc_oldp); + m68k_areg(regs, 7) -= 4; + put_long(m68k_areg(regs, 7), oldpc); + m68k_incpc(offset); } -#ifdef USE_COMPILER -extern void m68k_setpc_fast (uaecptr newpc); -extern void m68k_setpc_bcc (uaecptr newpc); -extern void m68k_setpc_rte (uaecptr newpc); -#else -#define m68k_setpc_fast m68k_setpc -#define m68k_setpc_bcc m68k_setpc -#define m68k_setpc_rte m68k_setpc -#endif - -STATIC_INLINE void m68k_setstopped (int stop) +STATIC_INLINE void m68k_do_jsr(uaecptr oldpc, uaecptr dest) { - regs.stopped = stop; - if (stop) - regs.spcflags |= SPCFLAG_STOP; + m68k_areg(regs, 7) -= 4; + put_long(m68k_areg(regs, 7), oldpc); + m68k_setpc(dest); } + extern uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp); extern uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp); @@ -250,6 +293,7 @@ extern int m68k_move2c (int, uae_u32 *); extern int m68k_movec2 (int, uae_u32 *); extern void m68k_divl (uae_u32, uae_u32, uae_u16, uaecptr); extern void m68k_mull (uae_u32, uae_u32, uae_u16); +extern void build_cpufunctbl(void); extern void init_m68k (void); extern void m68k_go (int); extern void m68k_dumpstate (FILE *, uaecptr *); @@ -266,8 +310,6 @@ extern void fbcc_opp (uae_u32, uaecptr, extern void fsave_opp (uae_u32); extern void frestore_opp (uae_u32); -extern int quit_program; -extern int lastInstructionCycles; /* Opcode of faulting instruction */ extern uae_u16 last_op_for_exception_3; @@ -293,4 +335,6 @@ extern struct cputbl op_smalltbl_5_ff[]; extern cpuop_func *cpufunctbl[65536]; -#endif /* ifndef UAENEWCPU */ +extern uae_u32 reg_caar, reg_cacr; + +#endif /* UAE_NEWCPU_H */