|
|
1.1 root 1: /*
1.1.1.2 root 2: * UAE - The Un*x Amiga Emulator - CPU core
1.1.1.6 root 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.14 root 10: * This file is distributed under the GNU General Public License, version 2
11: * or at 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"
1.1.1.10 root 19: #include "memory.h"
1.1 root 20:
21:
1.1.1.11 root 22: /* Possible exceptions sources for M68000_Exception() and Exception() */
1.1.1.13 root 23: #define M68000_EXC_SRC_CPU 1 /* Direct CPU exception */
24: #define M68000_EXC_SRC_AUTOVEC 2 /* Auto-vector exception (e.g. VBL) */
25: #define M68000_EXC_SRC_INT_MFP 3 /* MFP interrupt exception */
26: #define M68000_EXC_SRC_INT_DSP 4 /* DSP interrupt exception */
1.1.1.11 root 27:
28:
1.1.1.7 root 29: /* Special flags */
1.1.1.12 root 30: #define SPCFLAG_DEBUGGER 1
1.1 root 31: #define SPCFLAG_STOP 2
1.1.1.6 root 32: #define SPCFLAG_BUSERROR 4
1.1 root 33: #define SPCFLAG_INT 8
1.1.1.6 root 34: #define SPCFLAG_BRK 0x10
35: #define SPCFLAG_EXTRA_CYCLES 0x20
36: #define SPCFLAG_TRACE 0x40
37: #define SPCFLAG_DOTRACE 0x80
38: #define SPCFLAG_DOINT 0x100
1.1.1.7 root 39: #define SPCFLAG_MFP 0x200
1.1.1.6 root 40: #define SPCFLAG_EXEC 0x400
41: #define SPCFLAG_MODE_CHANGE 0x800
1.1.1.14 root 42: #define SPCFLAG_DSP 0x1000
1.1 root 43:
1.1.1.7 root 44:
1.1 root 45: #ifndef SET_CFLG
46:
47: #define SET_CFLG(x) (CFLG = (x))
48: #define SET_NFLG(x) (NFLG = (x))
49: #define SET_VFLG(x) (VFLG = (x))
50: #define SET_ZFLG(x) (ZFLG = (x))
51: #define SET_XFLG(x) (XFLG = (x))
52:
53: #define GET_CFLG CFLG
54: #define GET_NFLG NFLG
55: #define GET_VFLG VFLG
56: #define GET_ZFLG ZFLG
57: #define GET_XFLG XFLG
58:
59: #define CLEAR_CZNV do { \
60: SET_CFLG (0); \
61: SET_ZFLG (0); \
62: SET_NFLG (0); \
63: SET_VFLG (0); \
64: } while (0)
65:
66: #define COPY_CARRY (SET_XFLG (GET_CFLG))
67: #endif
68:
1.1.1.9 root 69: extern const int areg_byteinc[];
70: extern const int imm8_table[];
1.1 root 71:
72: extern int movem_index1[256];
73: extern int movem_index2[256];
74: extern int movem_next[256];
75:
76: extern int fpp_movem_index1[256];
77: extern int fpp_movem_index2[256];
78: extern int fpp_movem_next[256];
79:
80:
81: typedef unsigned long cpuop_func (uae_u32) REGPARAM;
82:
83: struct cputbl {
84: cpuop_func *handler;
85: int specific;
86: uae_u16 opcode;
87: };
88:
89: extern unsigned long op_illg (uae_u32) REGPARAM;
90:
91: typedef char flagtype;
92:
1.1.1.5 root 93: /* You can set this to long double to be more accurate. However, the
94: resulting alignment issues will cost a lot of performance in some
95: apps */
96: #define USE_LONG_DOUBLE 0
97:
98: #if USE_LONG_DOUBLE
99: typedef long double fptype;
100: #else
101: typedef double fptype;
102: #endif
103:
1.1 root 104: extern struct regstruct
105: {
106: uae_u32 regs[16];
107: uaecptr usp,isp,msp;
108: uae_u16 sr;
109: flagtype t1;
110: flagtype t0;
111: flagtype s;
112: flagtype m;
113: flagtype x;
114: flagtype stopped;
115: int intmask;
116:
117: uae_u32 pc;
118: uae_u8 *pc_p;
119: uae_u8 *pc_oldp;
1.1.1.16! root 120: uae_u16 opcode;
! 121: uae_u32 instruction_pc;
1.1 root 122:
123: uae_u32 vbr,sfc,dfc;
124:
1.1.1.5 root 125: fptype fp[8];
126: fptype fp_result;
127:
1.1 root 128: uae_u32 fpcr,fpsr,fpiar;
1.1.1.5 root 129: uae_u32 fpsr_highbyte;
1.1 root 130:
131: uae_u32 spcflags;
132:
1.1.1.5 root 133: uae_u32 prefetch_pc;
1.1 root 134: uae_u32 prefetch;
135: } regs, lastint_regs;
136:
137: STATIC_INLINE void set_special (uae_u32 x)
138: {
139: regs.spcflags |= x;
140: }
141:
142: STATIC_INLINE void unset_special (uae_u32 x)
143: {
144: regs.spcflags &= ~x;
145: }
146:
147: #define m68k_dreg(r,num) ((r).regs[(num)])
148: #define m68k_areg(r,num) (((r).regs + 8)[(num)])
149:
1.1.1.6 root 150:
1.1.1.5 root 151: STATIC_INLINE void m68k_setpc (uaecptr newpc)
152: {
153: regs.pc_p = regs.pc_oldp = get_real_address (newpc);
154: regs.pc = newpc;
155: }
156:
157: STATIC_INLINE uaecptr m68k_getpc (void)
158: {
159: return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp);
160: }
161:
162: STATIC_INLINE uaecptr m68k_getpc_p (uae_u8 *p)
163: {
164: return regs.pc + ((char *)p - (char *)regs.pc_oldp);
165: }
166:
1.1.1.8 root 167: #define get_ibyte(o) do_get_mem_byte(regs.pc_p + (o) + 1)
168: #define get_iword(o) do_get_mem_word(regs.pc_p + (o))
169: #define get_ilong(o) do_get_mem_long(regs.pc_p + (o))
1.1 root 170:
1.1.1.5 root 171: STATIC_INLINE void refill_prefetch (uae_u32 currpc, uae_u32 offs)
1.1 root 172: {
1.1.1.6 root 173: uae_u32 t = (currpc + offs) & ~1;
1.1.1.5 root 174: uae_u32 r;
175: #ifdef UNALIGNED_PROFITABLE
1.1.1.15 root 176: if ( t - regs.prefetch_pc == 2 ) /* keep 1 word and read 1 new word */
177: {
178: r = regs.prefetch;
179: r <<= 16;
180: r |= get_word (t+2);
181: }
182: else
183: {
184: /* [NP] FIXME : when we refill with 4 bytes, we should not read one long */
185: /* but 2 words, else some bus errors are not detected if the address overlaps */
186: /* on a bus error region (eg : get_long(t=213ffffe) doesn't give a bus error, */
187: /* but it should. This should be better handled in memory.c */
188: // r = get_long (t); /* read 2 new words */
189: r = get_word (t);
190: r <<= 16;
191: r |= get_word (t+2);
192: }
1.1.1.5 root 193: regs.prefetch = r;
194: #else
1.1.1.15 root 195: if ( t - regs.prefetch_pc == 2 ) /* keep 1 word and read 1 new word */
196: {
197: r = do_get_mem_word (((uae_u8 *)®s.prefetch) + 2);
198: r <<= 16;
199: r |= get_word (t+2);
200: }
201: else
202: {
203: /* [NP] FIXME : when we refill with 4 bytes, we should not read one long */
204: /* but 2 words, else some bus errors are not detected if the address overlaps */
205: /* on a bus error region (eg : get_long(t=213ffffe) doesn't give a bus error, */
206: /* but it should. This should be better handled in memory.c */
207: // r = get_long (t); /* read 2 new words */
208: r = get_word (t);
209: r <<= 16;
210: r |= get_word (t+2);
211: }
1.1.1.5 root 212: do_put_mem_long (®s.prefetch, r);
213: #endif
1.1.1.15 root 214: //fprintf (stderr,"PC %x PREFPC %x T %x R %x\n", currpc, regs.prefetch_pc, t, r);
1.1.1.5 root 215: regs.prefetch_pc = t;
216: }
1.1 root 217:
1.1.1.5 root 218: STATIC_INLINE uae_u32 get_ibyte_prefetch (uae_s32 o)
219: {
220: uae_u32 currpc = m68k_getpc ();
221: uae_u32 addr = currpc + o + 1;
222: uae_u32 offs = addr - regs.prefetch_pc;
223: uae_u32 v;
224: if (offs > 3) {
225: refill_prefetch (currpc, o + 1);
226: offs = addr - regs.prefetch_pc;
227: }
228: v = do_get_mem_byte (((uae_u8 *)®s.prefetch) + offs);
229: if (offs >= 2)
1.1.1.6 root 230: refill_prefetch (currpc, 2);
1.1.1.5 root 231: /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
232: return v;
1.1 root 233: }
234: STATIC_INLINE uae_u32 get_iword_prefetch (uae_s32 o)
235: {
1.1.1.5 root 236: uae_u32 currpc = m68k_getpc ();
237: uae_u32 addr = currpc + o;
238: uae_u32 offs = addr - regs.prefetch_pc;
239: uae_u32 v;
1.1.1.15 root 240: //fprintf (stderr,"get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v);
1.1.1.5 root 241: if (offs > 3) {
242: refill_prefetch (currpc, o);
243: offs = addr - regs.prefetch_pc;
244: }
1.1.1.8 root 245: v = do_get_mem_word (((uae_u8 *)®s.prefetch) + offs);
1.1.1.5 root 246: if (offs >= 2)
1.1.1.6 root 247: refill_prefetch (currpc, 2);
1.1.1.15 root 248: //fprintf (stderr,"get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v);
1.1.1.5 root 249: /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
250: return v;
1.1 root 251: }
252: STATIC_INLINE uae_u32 get_ilong_prefetch (uae_s32 o)
253: {
1.1.1.5 root 254: uae_u32 v = get_iword_prefetch (o);
255: v <<= 16;
256: v |= get_iword_prefetch (o + 2);
257: return v;
1.1 root 258: }
259:
260: #define m68k_incpc(o) (regs.pc_p += (o))
261:
262: STATIC_INLINE void fill_prefetch_0 (void)
263: {
264: }
265:
266: #define fill_prefetch_2 fill_prefetch_0
267:
268: /* These are only used by the 68020/68881 code, and therefore don't
269: * need to handle prefetch. */
270: STATIC_INLINE uae_u32 next_ibyte (void)
271: {
272: uae_u32 r = get_ibyte (0);
273: m68k_incpc (2);
274: return r;
275: }
276:
277: STATIC_INLINE uae_u32 next_iword (void)
278: {
279: uae_u32 r = get_iword (0);
280: m68k_incpc (2);
281: return r;
282: }
283:
284: STATIC_INLINE uae_u32 next_ilong (void)
285: {
286: uae_u32 r = get_ilong (0);
287: m68k_incpc (4);
288: return r;
289: }
290:
291: #define m68k_setpc_bcc m68k_setpc
292: #define m68k_setpc_rte m68k_setpc
293:
294: STATIC_INLINE void m68k_setstopped (int stop)
295: {
296: regs.stopped = stop;
1.1.1.5 root 297: /* A traced STOP instruction drops through immediately without
298: actually stopping. */
299: if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
1.1 root 300: regs.spcflags |= SPCFLAG_STOP;
301: }
302:
1.1.1.6 root 303: /* m68k_do_rts, m68k_do_bsr and m68k_do_jsr were originally defined in
304: * compiler.h, but since that header file has been removed from Hatari,
305: * they are now defined here: */
306: STATIC_INLINE void m68k_do_rts(void)
307: {
308: m68k_setpc(get_long(m68k_areg(regs, 7)));
309: m68k_areg(regs, 7) += 4;
310: }
311:
312: STATIC_INLINE void m68k_do_bsr(uaecptr oldpc, uae_s32 offset)
313: {
314: m68k_areg(regs, 7) -= 4;
315: put_long(m68k_areg(regs, 7), oldpc);
316: m68k_incpc(offset);
317: }
318:
319: STATIC_INLINE void m68k_do_jsr(uaecptr oldpc, uaecptr dest)
320: {
321: m68k_areg(regs, 7) -= 4;
322: put_long(m68k_areg(regs, 7), oldpc);
323: m68k_setpc(dest);
324: }
325:
326:
1.1 root 327: extern uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp);
328: extern uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp);
329:
330: extern uae_s32 ShowEA (FILE *, int reg, amodes mode, wordsizes size, char *buf);
331:
332: extern void MakeSR (void);
333: extern void MakeFromSR (void);
1.1.1.11 root 334: extern void Exception (int, uaecptr, int);
1.1 root 335: extern void dump_counts (void);
336: extern int m68k_move2c (int, uae_u32 *);
337: extern int m68k_movec2 (int, uae_u32 *);
338: extern void m68k_divl (uae_u32, uae_u32, uae_u16, uaecptr);
339: extern void m68k_mull (uae_u32, uae_u32, uae_u16);
1.1.1.4 root 340: extern void build_cpufunctbl(void);
1.1 root 341: extern void init_m68k (void);
342: extern void m68k_go (int);
343: extern void m68k_dumpstate (FILE *, uaecptr *);
344: extern void m68k_disasm (FILE *, uaecptr, uaecptr *, int);
345: extern void m68k_reset (void);
346:
347: extern void mmu_op (uae_u32, uae_u16);
348:
349: extern void fpp_opp (uae_u32, uae_u16);
350: extern void fdbcc_opp (uae_u32, uae_u16);
351: extern void fscc_opp (uae_u32, uae_u16);
352: extern void ftrapcc_opp (uae_u32,uaecptr);
353: extern void fbcc_opp (uae_u32, uaecptr, uae_u32);
354: extern void fsave_opp (uae_u32);
355: extern void frestore_opp (uae_u32);
356:
1.1.1.10 root 357: extern int getDivu68kCycles (uae_u32 dividend, uae_u16 divisor);
358: extern int getDivs68kCycles (uae_s32 dividend, uae_s16 divisor);
1.1.1.2 root 359:
1.1 root 360: /* Opcode of faulting instruction */
361: extern uae_u16 last_op_for_exception_3;
362: /* PC at fault time */
363: extern uaecptr last_addr_for_exception_3;
364: /* Address that generated the exception */
365: extern uaecptr last_fault_for_exception_3;
1.1.1.16! root 366: /* read (0) or write (1) access */
! 367: extern int last_writeaccess_for_exception_3;
! 368: /* instruction (1) or data (0) access */
! 369: extern int last_instructionaccess_for_exception_3;
1.1 root 370:
371: #define CPU_OP_NAME(a) op ## a
372:
373: /* 68040 */
1.1.1.9 root 374: extern const struct cputbl op_smalltbl_0_ff[];
1.1 root 375: /* 68020 + 68881 */
1.1.1.9 root 376: extern const struct cputbl op_smalltbl_1_ff[];
1.1 root 377: /* 68020 */
1.1.1.9 root 378: extern const struct cputbl op_smalltbl_2_ff[];
1.1 root 379: /* 68010 */
1.1.1.9 root 380: extern const struct cputbl op_smalltbl_3_ff[];
1.1 root 381: /* 68000 */
1.1.1.9 root 382: extern const struct cputbl op_smalltbl_4_ff[];
1.1 root 383: /* 68000 slow but compatible. */
1.1.1.9 root 384: extern const struct cputbl op_smalltbl_5_ff[];
1.1 root 385:
1.1.1.2 root 386: extern cpuop_func *cpufunctbl[65536];
1.1 root 387:
1.1.1.10 root 388: extern uae_u32 caar, cacr;
389:
390: /* Family of the latest instruction executed (to check for pairing) */
391: extern int OpcodeFamily; /* see instrmnem in readcpu.h */
1.1.1.7 root 392:
1.1.1.13 root 393: /* How many cycles to add to the current instruction in case a "misaligned" bus acces is made */
394: /* (used when addressing mode is d8(an,ix)) */
395: extern int BusCyclePenalty;
396:
1.1.1.4 root 397: #endif /* UAE_NEWCPU_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.