--- hatari/src/uae-cpu/newcpu.h 2019/04/01 07:10:41 1.1.1.5 +++ hatari/src/uae-cpu/newcpu.h 2019/04/09 08:57:03 1.1.1.17 @@ -1,14 +1,14 @@ /* * 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. + * This file is distributed under the GNU General Public License, version 2 + * or at your option any later version. Read the file gpl.txt for details. */ #ifndef UAE_NEWCPU_H @@ -16,20 +16,30 @@ #include "readcpu.h" #include "m68k.h" +#include "memory.h" + +/* Possible exceptions sources for M68000_Exception() and Exception() */ +#define M68000_EXC_SRC_CPU 1 /* Direct CPU exception */ +#define M68000_EXC_SRC_AUTOVEC 2 /* Auto-vector exception (e.g. VBL) */ +#define M68000_EXC_SRC_INT_MFP 3 /* MFP interrupt exception */ +#define M68000_EXC_SRC_INT_DSP 4 /* DSP interrupt exception */ -/* custom chip support */ + +/* Special flags */ +#define SPCFLAG_DEBUGGER 1 #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 +#define SPCFLAG_DSP 0x1000 #ifndef SET_CFLG @@ -56,8 +66,8 @@ #define COPY_CARRY (SET_XFLG (GET_CFLG)) #endif -extern int areg_byteinc[]; -extern int imm8_table[]; +extern const int areg_byteinc[]; +extern const int imm8_table[]; extern int movem_index1[256]; extern int movem_index2[256]; @@ -67,7 +77,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; @@ -108,6 +117,8 @@ extern struct regstruct uae_u32 pc; uae_u8 *pc_p; uae_u8 *pc_oldp; + uae_u16 opcode; + uae_u32 instruction_pc; uae_u32 vbr,sfc,dfc; @@ -136,15 +147,12 @@ STATIC_INLINE void unset_special (uae_u3 #define m68k_dreg(r,num) ((r).regs[(num)]) #define m68k_areg(r,num) (((r).regs + 8)[(num)]) -#if !defined USE_COMPILER + STATIC_INLINE void m68k_setpc (uaecptr newpc) { regs.pc_p = regs.pc_oldp = get_real_address (newpc); regs.pc = newpc; } -#else -extern void m68k_setpc (uaecptr newpc); -#endif STATIC_INLINE uaecptr m68k_getpc (void) { @@ -156,24 +164,56 @@ STATIC_INLINE uaecptr m68k_getpc_p (uae_ return regs.pc + ((char *)p - (char *)regs.pc_oldp); } -#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))) +#define get_ibyte(o) do_get_mem_byte(regs.pc_p + (o) + 1) +#define get_iword(o) do_get_mem_word(regs.pc_p + (o)) +#define get_ilong(o) do_get_mem_long(regs.pc_p + (o)) STATIC_INLINE void refill_prefetch (uae_u32 currpc, uae_u32 offs) { - uae_u32 t = (currpc + offs) & ~3; - uae_s32 pc_p_offs = t - currpc; - uae_u8 *ptr = regs.pc_p + pc_p_offs; + uae_u32 t = (currpc + offs) & ~1; uae_u32 r; + +//fprintf ( stderr , "refill pc %x o %d old %x\n" , currpc,offs,regs.prefetch_pc ); #ifdef UNALIGNED_PROFITABLE - r = *(uae_u32 *)ptr; + if ( t - regs.prefetch_pc == 2 ) /* keep 1 word and read 1 new word */ + { + r = regs.prefetch; + r <<= 16; + r |= get_word (t+2); + } + else + { + /* [NP] FIXME : when we refill with 4 bytes, we should not read one long */ + /* but 2 words, else some bus errors are not detected if the address overlaps */ + /* on a bus error region (eg : get_long(t=213ffffe) doesn't give a bus error, */ + /* but it should. This should be better handled in memory.c */ +// r = get_long (t); /* read 2 new words */ + r = get_word (t); + r <<= 16; + r |= get_word (t+2); + } regs.prefetch = r; #else - r = do_get_mem_long ((uae_u32 *)ptr); + if ( t - regs.prefetch_pc == 2 ) /* keep 1 word and read 1 new word */ + { + r = do_get_mem_word (((uae_u8 *)®s.prefetch) + 2); + r <<= 16; + r |= get_word (t+2); + } + else + { + /* [NP] FIXME : when we refill with 4 bytes, we should not read one long */ + /* but 2 words, else some bus errors are not detected if the address overlaps */ + /* on a bus error region (eg : get_long(t=213ffffe) doesn't give a bus error, */ + /* but it should. This should be better handled in memory.c */ +// r = get_long (t); /* read 2 new words */ + r = get_word (t); + r <<= 16; + r |= get_word (t+2); + } do_put_mem_long (®s.prefetch, r); #endif - /* printf ("PC %lx T %lx PCPOFFS %d R %lx\n", currpc, t, pc_p_offs, r); */ +//fprintf (stderr,"PC %x PREFPC %x T %x R %x\n", currpc, regs.prefetch_pc, t, r); regs.prefetch_pc = t; } @@ -189,7 +229,7 @@ STATIC_INLINE uae_u32 get_ibyte_prefetch } v = do_get_mem_byte (((uae_u8 *)®s.prefetch) + offs); if (offs >= 2) - refill_prefetch (currpc, 4); + refill_prefetch (currpc, 2); /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */ return v; } @@ -199,13 +239,15 @@ STATIC_INLINE uae_u32 get_iword_prefetch uae_u32 addr = currpc + o; uae_u32 offs = addr - regs.prefetch_pc; uae_u32 v; +//fprintf (stderr,"get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, 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)); + v = do_get_mem_word (((uae_u8 *)®s.prefetch) + offs); if (offs >= 2) - refill_prefetch (currpc, 4); + refill_prefetch (currpc, 2); +//fprintf (stderr,"get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */ return v; } @@ -248,15 +290,8 @@ STATIC_INLINE uae_u32 next_ilong (void) return r; } -#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) { @@ -267,6 +302,30 @@ STATIC_INLINE void m68k_setstopped (int regs.spcflags |= SPCFLAG_STOP; } +/* 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) +{ + m68k_setpc(get_long(m68k_areg(regs, 7))); + m68k_areg(regs, 7) += 4; +} + +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_jsr(uaecptr oldpc, uaecptr dest) +{ + 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); @@ -274,7 +333,7 @@ extern uae_s32 ShowEA (FILE *, int reg, extern void MakeSR (void); extern void MakeFromSR (void); -extern void Exception (int, uaecptr); +extern void Exception (int, uaecptr, int); extern void dump_counts (void); extern int m68k_move2c (int, uae_u32 *); extern int m68k_movec2 (int, uae_u32 *); @@ -297,7 +356,8 @@ extern void fbcc_opp (uae_u32, uaecptr, extern void fsave_opp (uae_u32); extern void frestore_opp (uae_u32); -extern int lastInstructionCycles; +extern int getDivu68kCycles (uae_u32 dividend, uae_u16 divisor); +extern int getDivs68kCycles (uae_s32 dividend, uae_s16 divisor); /* Opcode of faulting instruction */ extern uae_u16 last_op_for_exception_3; @@ -305,22 +365,35 @@ extern uae_u16 last_op_for_exception_3; extern uaecptr last_addr_for_exception_3; /* Address that generated the exception */ extern uaecptr last_fault_for_exception_3; +/* read (0) or write (1) access */ +extern int last_writeaccess_for_exception_3; +/* instruction (1) or data (0) access */ +extern int last_instructionaccess_for_exception_3; #define CPU_OP_NAME(a) op ## a /* 68040 */ -extern struct cputbl op_smalltbl_0_ff[]; +extern const struct cputbl op_smalltbl_0_ff[]; /* 68020 + 68881 */ -extern struct cputbl op_smalltbl_1_ff[]; +extern const struct cputbl op_smalltbl_1_ff[]; /* 68020 */ -extern struct cputbl op_smalltbl_2_ff[]; +extern const struct cputbl op_smalltbl_2_ff[]; /* 68010 */ -extern struct cputbl op_smalltbl_3_ff[]; +extern const struct cputbl op_smalltbl_3_ff[]; /* 68000 */ -extern struct cputbl op_smalltbl_4_ff[]; +extern const struct cputbl op_smalltbl_4_ff[]; /* 68000 slow but compatible. */ -extern struct cputbl op_smalltbl_5_ff[]; +extern const struct cputbl op_smalltbl_5_ff[]; extern cpuop_func *cpufunctbl[65536]; +extern uae_u32 caar, cacr; + +/* Family of the latest instruction executed (to check for pairing) */ +extern int OpcodeFamily; /* see instrmnem in readcpu.h */ + +/* How many cycles to add to the current instruction in case a "misaligned" bus access is made */ +/* (used when addressing mode is d8(an,ix)) */ +extern int BusCyclePenalty; + #endif /* UAE_NEWCPU_H */