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