|
|
1.1 root 1: /*
1.1.1.2 root 2: * UAE - The Un*x Amiga Emulator - CPU core
3: *
1.1 root 4: * MC68000 emulation
5: *
6: * Copyright 1995 Bernd Schmidt
1.1.1.2 root 7: *
8: * Adaptation to Hatari by Thomas Huth
9: *
1.1.1.5 ! root 10: * This file is distributed under the GNU Public License, version 2 or at
! 11: * your option any later version. Read the file gpl.txt for details.
1.1 root 12: */
13:
1.1.1.4 root 14: #ifndef UAE_NEWCPU_H
15: #define UAE_NEWCPU_H
1.1 root 16:
17: #include "readcpu.h"
18: #include "m68k.h"
19:
20:
21: /* custom chip support */
22: #define SPCFLAG_STOP 2
23: /*#define SPCFLAG_COPPER 4*/
24: #define SPCFLAG_INT 8
25: #define SPCFLAG_BRK 16
26: #define SPCFLAG_EXTRA_CYCLES 32
27: #define SPCFLAG_TRACE 64
28: #define SPCFLAG_DOTRACE 128
29: #define SPCFLAG_DOINT 256
30: /*#define SPCFLAG_BLTNASTY 512*/
31: #define SPCFLAG_EXEC 1024
32: #define SPCFLAG_MODE_CHANGE 8192
33:
34:
35: #ifndef SET_CFLG
36:
37: #define SET_CFLG(x) (CFLG = (x))
38: #define SET_NFLG(x) (NFLG = (x))
39: #define SET_VFLG(x) (VFLG = (x))
40: #define SET_ZFLG(x) (ZFLG = (x))
41: #define SET_XFLG(x) (XFLG = (x))
42:
43: #define GET_CFLG CFLG
44: #define GET_NFLG NFLG
45: #define GET_VFLG VFLG
46: #define GET_ZFLG ZFLG
47: #define GET_XFLG XFLG
48:
49: #define CLEAR_CZNV do { \
50: SET_CFLG (0); \
51: SET_ZFLG (0); \
52: SET_NFLG (0); \
53: SET_VFLG (0); \
54: } while (0)
55:
56: #define COPY_CARRY (SET_XFLG (GET_CFLG))
57: #endif
58:
59: extern int areg_byteinc[];
60: extern int imm8_table[];
61:
62: extern int movem_index1[256];
63: extern int movem_index2[256];
64: extern int movem_next[256];
65:
66: extern int fpp_movem_index1[256];
67: extern int fpp_movem_index2[256];
68: extern int fpp_movem_next[256];
69:
70: extern int broken_in;
71:
72: typedef unsigned long cpuop_func (uae_u32) REGPARAM;
73:
74: struct cputbl {
75: cpuop_func *handler;
76: int specific;
77: uae_u16 opcode;
78: };
79:
80: extern unsigned long op_illg (uae_u32) REGPARAM;
81:
82: typedef char flagtype;
83:
1.1.1.5 ! root 84: /* You can set this to long double to be more accurate. However, the
! 85: resulting alignment issues will cost a lot of performance in some
! 86: apps */
! 87: #define USE_LONG_DOUBLE 0
! 88:
! 89: #if USE_LONG_DOUBLE
! 90: typedef long double fptype;
! 91: #else
! 92: typedef double fptype;
! 93: #endif
! 94:
1.1 root 95: extern struct regstruct
96: {
97: uae_u32 regs[16];
98: uaecptr usp,isp,msp;
99: uae_u16 sr;
100: flagtype t1;
101: flagtype t0;
102: flagtype s;
103: flagtype m;
104: flagtype x;
105: flagtype stopped;
106: int intmask;
107:
108: uae_u32 pc;
109: uae_u8 *pc_p;
110: uae_u8 *pc_oldp;
111:
112: uae_u32 vbr,sfc,dfc;
113:
1.1.1.5 ! root 114: fptype fp[8];
! 115: fptype fp_result;
! 116:
1.1 root 117: uae_u32 fpcr,fpsr,fpiar;
1.1.1.5 ! root 118: uae_u32 fpsr_highbyte;
1.1 root 119:
120: uae_u32 spcflags;
121:
1.1.1.5 ! root 122: uae_u32 prefetch_pc;
1.1 root 123: uae_u32 prefetch;
124: } regs, lastint_regs;
125:
126: STATIC_INLINE void set_special (uae_u32 x)
127: {
128: regs.spcflags |= x;
129: }
130:
131: STATIC_INLINE void unset_special (uae_u32 x)
132: {
133: regs.spcflags &= ~x;
134: }
135:
136: #define m68k_dreg(r,num) ((r).regs[(num)])
137: #define m68k_areg(r,num) (((r).regs + 8)[(num)])
138:
1.1.1.5 ! root 139: #if !defined USE_COMPILER
! 140: STATIC_INLINE void m68k_setpc (uaecptr newpc)
! 141: {
! 142: regs.pc_p = regs.pc_oldp = get_real_address (newpc);
! 143: regs.pc = newpc;
! 144: }
! 145: #else
! 146: extern void m68k_setpc (uaecptr newpc);
! 147: #endif
! 148:
! 149: STATIC_INLINE uaecptr m68k_getpc (void)
! 150: {
! 151: return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp);
! 152: }
! 153:
! 154: STATIC_INLINE uaecptr m68k_getpc_p (uae_u8 *p)
! 155: {
! 156: return regs.pc + ((char *)p - (char *)regs.pc_oldp);
! 157: }
! 158:
1.1 root 159: #define get_ibyte(o) do_get_mem_byte((uae_u8 *)(regs.pc_p + (o) + 1))
160: #define get_iword(o) do_get_mem_word((uae_u16 *)(regs.pc_p + (o)))
161: #define get_ilong(o) do_get_mem_long((uae_u32 *)(regs.pc_p + (o)))
162:
1.1.1.5 ! root 163: STATIC_INLINE void refill_prefetch (uae_u32 currpc, uae_u32 offs)
1.1 root 164: {
1.1.1.5 ! root 165: uae_u32 t = (currpc + offs) & ~3;
! 166: uae_s32 pc_p_offs = t - currpc;
! 167: uae_u8 *ptr = regs.pc_p + pc_p_offs;
! 168: uae_u32 r;
! 169: #ifdef UNALIGNED_PROFITABLE
! 170: r = *(uae_u32 *)ptr;
! 171: regs.prefetch = r;
! 172: #else
! 173: r = do_get_mem_long ((uae_u32 *)ptr);
! 174: do_put_mem_long (®s.prefetch, r);
! 175: #endif
! 176: /* printf ("PC %lx T %lx PCPOFFS %d R %lx\n", currpc, t, pc_p_offs, r); */
! 177: regs.prefetch_pc = t;
! 178: }
1.1 root 179:
1.1.1.5 ! root 180: STATIC_INLINE uae_u32 get_ibyte_prefetch (uae_s32 o)
! 181: {
! 182: uae_u32 currpc = m68k_getpc ();
! 183: uae_u32 addr = currpc + o + 1;
! 184: uae_u32 offs = addr - regs.prefetch_pc;
! 185: uae_u32 v;
! 186: if (offs > 3) {
! 187: refill_prefetch (currpc, o + 1);
! 188: offs = addr - regs.prefetch_pc;
! 189: }
! 190: v = do_get_mem_byte (((uae_u8 *)®s.prefetch) + offs);
! 191: if (offs >= 2)
! 192: refill_prefetch (currpc, 4);
! 193: /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
! 194: return v;
1.1 root 195: }
196: STATIC_INLINE uae_u32 get_iword_prefetch (uae_s32 o)
197: {
1.1.1.5 ! root 198: uae_u32 currpc = m68k_getpc ();
! 199: uae_u32 addr = currpc + o;
! 200: uae_u32 offs = addr - regs.prefetch_pc;
! 201: uae_u32 v;
! 202: if (offs > 3) {
! 203: refill_prefetch (currpc, o);
! 204: offs = addr - regs.prefetch_pc;
! 205: }
! 206: v = do_get_mem_word ((uae_u16 *)(((uae_u8 *)®s.prefetch) + offs));
! 207: if (offs >= 2)
! 208: refill_prefetch (currpc, 4);
! 209: /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
! 210: return v;
1.1 root 211: }
212: STATIC_INLINE uae_u32 get_ilong_prefetch (uae_s32 o)
213: {
1.1.1.5 ! root 214: uae_u32 v = get_iword_prefetch (o);
! 215: v <<= 16;
! 216: v |= get_iword_prefetch (o + 2);
! 217: return v;
1.1 root 218: }
219:
220: #define m68k_incpc(o) (regs.pc_p += (o))
221:
222: STATIC_INLINE void fill_prefetch_0 (void)
223: {
224: }
225:
226: #define fill_prefetch_2 fill_prefetch_0
227:
228: /* These are only used by the 68020/68881 code, and therefore don't
229: * need to handle prefetch. */
230: STATIC_INLINE uae_u32 next_ibyte (void)
231: {
232: uae_u32 r = get_ibyte (0);
233: m68k_incpc (2);
234: return r;
235: }
236:
237: STATIC_INLINE uae_u32 next_iword (void)
238: {
239: uae_u32 r = get_iword (0);
240: m68k_incpc (2);
241: return r;
242: }
243:
244: STATIC_INLINE uae_u32 next_ilong (void)
245: {
246: uae_u32 r = get_ilong (0);
247: m68k_incpc (4);
248: return r;
249: }
250:
251: #ifdef USE_COMPILER
252: extern void m68k_setpc_fast (uaecptr newpc);
253: extern void m68k_setpc_bcc (uaecptr newpc);
254: extern void m68k_setpc_rte (uaecptr newpc);
255: #else
256: #define m68k_setpc_fast m68k_setpc
257: #define m68k_setpc_bcc m68k_setpc
258: #define m68k_setpc_rte m68k_setpc
259: #endif
260:
261: STATIC_INLINE void m68k_setstopped (int stop)
262: {
263: regs.stopped = stop;
1.1.1.5 ! root 264: /* A traced STOP instruction drops through immediately without
! 265: actually stopping. */
! 266: if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
1.1 root 267: regs.spcflags |= SPCFLAG_STOP;
268: }
269:
270: extern uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp);
271: extern uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp);
272:
273: extern uae_s32 ShowEA (FILE *, int reg, amodes mode, wordsizes size, char *buf);
274:
275: extern void MakeSR (void);
276: extern void MakeFromSR (void);
277: extern void Exception (int, uaecptr);
278: extern void dump_counts (void);
279: extern int m68k_move2c (int, uae_u32 *);
280: extern int m68k_movec2 (int, uae_u32 *);
281: extern void m68k_divl (uae_u32, uae_u32, uae_u16, uaecptr);
282: extern void m68k_mull (uae_u32, uae_u32, uae_u16);
1.1.1.4 root 283: extern void build_cpufunctbl(void);
1.1 root 284: extern void init_m68k (void);
285: extern void m68k_go (int);
286: extern void m68k_dumpstate (FILE *, uaecptr *);
287: extern void m68k_disasm (FILE *, uaecptr, uaecptr *, int);
288: extern void m68k_reset (void);
289:
290: extern void mmu_op (uae_u32, uae_u16);
291:
292: extern void fpp_opp (uae_u32, uae_u16);
293: extern void fdbcc_opp (uae_u32, uae_u16);
294: extern void fscc_opp (uae_u32, uae_u16);
295: extern void ftrapcc_opp (uae_u32,uaecptr);
296: extern void fbcc_opp (uae_u32, uaecptr, uae_u32);
297: extern void fsave_opp (uae_u32);
298: extern void frestore_opp (uae_u32);
299:
1.1.1.2 root 300: extern int lastInstructionCycles;
301:
1.1 root 302: /* Opcode of faulting instruction */
303: extern uae_u16 last_op_for_exception_3;
304: /* PC at fault time */
305: extern uaecptr last_addr_for_exception_3;
306: /* Address that generated the exception */
307: extern uaecptr last_fault_for_exception_3;
308:
309: #define CPU_OP_NAME(a) op ## a
310:
311: /* 68040 */
312: extern struct cputbl op_smalltbl_0_ff[];
313: /* 68020 + 68881 */
314: extern struct cputbl op_smalltbl_1_ff[];
315: /* 68020 */
316: extern struct cputbl op_smalltbl_2_ff[];
317: /* 68010 */
318: extern struct cputbl op_smalltbl_3_ff[];
319: /* 68000 */
320: extern struct cputbl op_smalltbl_4_ff[];
321: /* 68000 slow but compatible. */
322: extern struct cputbl op_smalltbl_5_ff[];
323:
1.1.1.2 root 324: extern cpuop_func *cpufunctbl[65536];
1.1 root 325:
1.1.1.4 root 326: #endif /* UAE_NEWCPU_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.