|
|
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;
1.1.1.17! root 175:
! 176: //fprintf ( stderr , "refill pc %x o %d old %x\n" , currpc,offs,regs.prefetch_pc );
1.1.1.5 root 177: #ifdef UNALIGNED_PROFITABLE
1.1.1.15 root 178: if ( t - regs.prefetch_pc == 2 ) /* keep 1 word and read 1 new word */
179: {
180: r = regs.prefetch;
181: r <<= 16;
182: r |= get_word (t+2);
183: }
184: else
185: {
186: /* [NP] FIXME : when we refill with 4 bytes, we should not read one long */
187: /* but 2 words, else some bus errors are not detected if the address overlaps */
188: /* on a bus error region (eg : get_long(t=213ffffe) doesn't give a bus error, */
189: /* but it should. This should be better handled in memory.c */
190: // r = get_long (t); /* read 2 new words */
191: r = get_word (t);
192: r <<= 16;
193: r |= get_word (t+2);
194: }
1.1.1.5 root 195: regs.prefetch = r;
196: #else
1.1.1.15 root 197: if ( t - regs.prefetch_pc == 2 ) /* keep 1 word and read 1 new word */
198: {
199: r = do_get_mem_word (((uae_u8 *)®s.prefetch) + 2);
200: r <<= 16;
201: r |= get_word (t+2);
202: }
203: else
204: {
205: /* [NP] FIXME : when we refill with 4 bytes, we should not read one long */
206: /* but 2 words, else some bus errors are not detected if the address overlaps */
207: /* on a bus error region (eg : get_long(t=213ffffe) doesn't give a bus error, */
208: /* but it should. This should be better handled in memory.c */
209: // r = get_long (t); /* read 2 new words */
210: r = get_word (t);
211: r <<= 16;
212: r |= get_word (t+2);
213: }
1.1.1.5 root 214: do_put_mem_long (®s.prefetch, r);
215: #endif
1.1.1.15 root 216: //fprintf (stderr,"PC %x PREFPC %x T %x R %x\n", currpc, regs.prefetch_pc, t, r);
1.1.1.5 root 217: regs.prefetch_pc = t;
218: }
1.1 root 219:
1.1.1.5 root 220: STATIC_INLINE uae_u32 get_ibyte_prefetch (uae_s32 o)
221: {
222: uae_u32 currpc = m68k_getpc ();
223: uae_u32 addr = currpc + o + 1;
224: uae_u32 offs = addr - regs.prefetch_pc;
225: uae_u32 v;
226: if (offs > 3) {
227: refill_prefetch (currpc, o + 1);
228: offs = addr - regs.prefetch_pc;
229: }
230: v = do_get_mem_byte (((uae_u8 *)®s.prefetch) + offs);
231: if (offs >= 2)
1.1.1.6 root 232: refill_prefetch (currpc, 2);
1.1.1.5 root 233: /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
234: return v;
1.1 root 235: }
236: STATIC_INLINE uae_u32 get_iword_prefetch (uae_s32 o)
237: {
1.1.1.5 root 238: uae_u32 currpc = m68k_getpc ();
239: uae_u32 addr = currpc + o;
240: uae_u32 offs = addr - regs.prefetch_pc;
241: uae_u32 v;
1.1.1.15 root 242: //fprintf (stderr,"get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v);
1.1.1.5 root 243: if (offs > 3) {
244: refill_prefetch (currpc, o);
245: offs = addr - regs.prefetch_pc;
246: }
1.1.1.8 root 247: v = do_get_mem_word (((uae_u8 *)®s.prefetch) + offs);
1.1.1.5 root 248: if (offs >= 2)
1.1.1.6 root 249: refill_prefetch (currpc, 2);
1.1.1.15 root 250: //fprintf (stderr,"get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v);
1.1.1.5 root 251: /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
252: return v;
1.1 root 253: }
254: STATIC_INLINE uae_u32 get_ilong_prefetch (uae_s32 o)
255: {
1.1.1.5 root 256: uae_u32 v = get_iword_prefetch (o);
257: v <<= 16;
258: v |= get_iword_prefetch (o + 2);
259: return v;
1.1 root 260: }
261:
262: #define m68k_incpc(o) (regs.pc_p += (o))
263:
264: STATIC_INLINE void fill_prefetch_0 (void)
265: {
266: }
267:
268: #define fill_prefetch_2 fill_prefetch_0
269:
270: /* These are only used by the 68020/68881 code, and therefore don't
271: * need to handle prefetch. */
272: STATIC_INLINE uae_u32 next_ibyte (void)
273: {
274: uae_u32 r = get_ibyte (0);
275: m68k_incpc (2);
276: return r;
277: }
278:
279: STATIC_INLINE uae_u32 next_iword (void)
280: {
281: uae_u32 r = get_iword (0);
282: m68k_incpc (2);
283: return r;
284: }
285:
286: STATIC_INLINE uae_u32 next_ilong (void)
287: {
288: uae_u32 r = get_ilong (0);
289: m68k_incpc (4);
290: return r;
291: }
292:
293: #define m68k_setpc_bcc m68k_setpc
294: #define m68k_setpc_rte m68k_setpc
295:
296: STATIC_INLINE void m68k_setstopped (int stop)
297: {
298: regs.stopped = stop;
1.1.1.5 root 299: /* A traced STOP instruction drops through immediately without
300: actually stopping. */
301: if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
1.1 root 302: regs.spcflags |= SPCFLAG_STOP;
303: }
304:
1.1.1.6 root 305: /* m68k_do_rts, m68k_do_bsr and m68k_do_jsr were originally defined in
306: * compiler.h, but since that header file has been removed from Hatari,
307: * they are now defined here: */
308: STATIC_INLINE void m68k_do_rts(void)
309: {
310: m68k_setpc(get_long(m68k_areg(regs, 7)));
311: m68k_areg(regs, 7) += 4;
312: }
313:
314: STATIC_INLINE void m68k_do_bsr(uaecptr oldpc, uae_s32 offset)
315: {
316: m68k_areg(regs, 7) -= 4;
317: put_long(m68k_areg(regs, 7), oldpc);
318: m68k_incpc(offset);
319: }
320:
321: STATIC_INLINE void m68k_do_jsr(uaecptr oldpc, uaecptr dest)
322: {
323: m68k_areg(regs, 7) -= 4;
324: put_long(m68k_areg(regs, 7), oldpc);
325: m68k_setpc(dest);
326: }
327:
328:
1.1 root 329: extern uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp);
330: extern uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp);
331:
332: extern uae_s32 ShowEA (FILE *, int reg, amodes mode, wordsizes size, char *buf);
333:
334: extern void MakeSR (void);
335: extern void MakeFromSR (void);
1.1.1.11 root 336: extern void Exception (int, uaecptr, int);
1.1 root 337: extern void dump_counts (void);
338: extern int m68k_move2c (int, uae_u32 *);
339: extern int m68k_movec2 (int, uae_u32 *);
340: extern void m68k_divl (uae_u32, uae_u32, uae_u16, uaecptr);
341: extern void m68k_mull (uae_u32, uae_u32, uae_u16);
1.1.1.4 root 342: extern void build_cpufunctbl(void);
1.1 root 343: extern void init_m68k (void);
344: extern void m68k_go (int);
345: extern void m68k_dumpstate (FILE *, uaecptr *);
346: extern void m68k_disasm (FILE *, uaecptr, uaecptr *, int);
347: extern void m68k_reset (void);
348:
349: extern void mmu_op (uae_u32, uae_u16);
350:
351: extern void fpp_opp (uae_u32, uae_u16);
352: extern void fdbcc_opp (uae_u32, uae_u16);
353: extern void fscc_opp (uae_u32, uae_u16);
354: extern void ftrapcc_opp (uae_u32,uaecptr);
355: extern void fbcc_opp (uae_u32, uaecptr, uae_u32);
356: extern void fsave_opp (uae_u32);
357: extern void frestore_opp (uae_u32);
358:
1.1.1.10 root 359: extern int getDivu68kCycles (uae_u32 dividend, uae_u16 divisor);
360: extern int getDivs68kCycles (uae_s32 dividend, uae_s16 divisor);
1.1.1.2 root 361:
1.1 root 362: /* Opcode of faulting instruction */
363: extern uae_u16 last_op_for_exception_3;
364: /* PC at fault time */
365: extern uaecptr last_addr_for_exception_3;
366: /* Address that generated the exception */
367: extern uaecptr last_fault_for_exception_3;
1.1.1.16 root 368: /* read (0) or write (1) access */
369: extern int last_writeaccess_for_exception_3;
370: /* instruction (1) or data (0) access */
371: extern int last_instructionaccess_for_exception_3;
1.1 root 372:
373: #define CPU_OP_NAME(a) op ## a
374:
375: /* 68040 */
1.1.1.9 root 376: extern const struct cputbl op_smalltbl_0_ff[];
1.1 root 377: /* 68020 + 68881 */
1.1.1.9 root 378: extern const struct cputbl op_smalltbl_1_ff[];
1.1 root 379: /* 68020 */
1.1.1.9 root 380: extern const struct cputbl op_smalltbl_2_ff[];
1.1 root 381: /* 68010 */
1.1.1.9 root 382: extern const struct cputbl op_smalltbl_3_ff[];
1.1 root 383: /* 68000 */
1.1.1.9 root 384: extern const struct cputbl op_smalltbl_4_ff[];
1.1 root 385: /* 68000 slow but compatible. */
1.1.1.9 root 386: extern const struct cputbl op_smalltbl_5_ff[];
1.1 root 387:
1.1.1.2 root 388: extern cpuop_func *cpufunctbl[65536];
1.1 root 389:
1.1.1.10 root 390: extern uae_u32 caar, cacr;
391:
392: /* Family of the latest instruction executed (to check for pairing) */
393: extern int OpcodeFamily; /* see instrmnem in readcpu.h */
1.1.1.7 root 394:
1.1.1.17! root 395: /* How many cycles to add to the current instruction in case a "misaligned" bus access is made */
1.1.1.13 root 396: /* (used when addressing mode is d8(an,ix)) */
397: extern int BusCyclePenalty;
398:
1.1.1.4 root 399: #endif /* UAE_NEWCPU_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.