Annotation of hatari/src/uae-cpu/newcpu.h, revision 1.1.1.13

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.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"
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       root       42: 
1.1.1.7   root       43: 
1.1       root       44: #ifndef SET_CFLG
                     45: 
                     46: #define SET_CFLG(x) (CFLG = (x))
                     47: #define SET_NFLG(x) (NFLG = (x))
                     48: #define SET_VFLG(x) (VFLG = (x))
                     49: #define SET_ZFLG(x) (ZFLG = (x))
                     50: #define SET_XFLG(x) (XFLG = (x))
                     51: 
                     52: #define GET_CFLG CFLG
                     53: #define GET_NFLG NFLG
                     54: #define GET_VFLG VFLG
                     55: #define GET_ZFLG ZFLG
                     56: #define GET_XFLG XFLG
                     57: 
                     58: #define CLEAR_CZNV do { \
                     59:  SET_CFLG (0); \
                     60:  SET_ZFLG (0); \
                     61:  SET_NFLG (0); \
                     62:  SET_VFLG (0); \
                     63: } while (0)
                     64: 
                     65: #define COPY_CARRY (SET_XFLG (GET_CFLG))
                     66: #endif
                     67: 
1.1.1.9   root       68: extern const int areg_byteinc[];
                     69: extern const int imm8_table[];
1.1       root       70: 
                     71: extern int movem_index1[256];
                     72: extern int movem_index2[256];
                     73: extern int movem_next[256];
                     74: 
                     75: extern int fpp_movem_index1[256];
                     76: extern int fpp_movem_index2[256];
                     77: extern int fpp_movem_next[256];
                     78: 
                     79: 
                     80: typedef unsigned long cpuop_func (uae_u32) REGPARAM;
                     81: 
                     82: struct cputbl {
                     83:     cpuop_func *handler;
                     84:     int specific;
                     85:     uae_u16 opcode;
                     86: };
                     87: 
                     88: extern unsigned long op_illg (uae_u32) REGPARAM;
                     89: 
                     90: typedef char flagtype;
                     91: 
1.1.1.5   root       92: /* You can set this to long double to be more accurate. However, the
                     93:    resulting alignment issues will cost a lot of performance in some
                     94:    apps */
                     95: #define USE_LONG_DOUBLE 0
                     96: 
                     97: #if USE_LONG_DOUBLE
                     98: typedef long double fptype;
                     99: #else
                    100: typedef double fptype;
                    101: #endif
                    102: 
1.1       root      103: extern struct regstruct
                    104: {
                    105:     uae_u32 regs[16];
                    106:     uaecptr  usp,isp,msp;
                    107:     uae_u16 sr;
                    108:     flagtype t1;
                    109:     flagtype t0;
                    110:     flagtype s;
                    111:     flagtype m;
                    112:     flagtype x;
                    113:     flagtype stopped;
                    114:     int intmask;
                    115: 
                    116:     uae_u32 pc;
                    117:     uae_u8 *pc_p;
                    118:     uae_u8 *pc_oldp;
                    119: 
                    120:     uae_u32 vbr,sfc,dfc;
                    121: 
1.1.1.5   root      122:     fptype fp[8];
                    123:     fptype fp_result;
                    124: 
1.1       root      125:     uae_u32 fpcr,fpsr,fpiar;
1.1.1.5   root      126:     uae_u32 fpsr_highbyte;
1.1       root      127: 
                    128:     uae_u32 spcflags;
                    129: 
1.1.1.5   root      130:     uae_u32 prefetch_pc;
1.1       root      131:     uae_u32 prefetch;
                    132: } regs, lastint_regs;
                    133: 
                    134: STATIC_INLINE void set_special (uae_u32 x)
                    135: {
                    136:     regs.spcflags |= x;
                    137: }
                    138: 
                    139: STATIC_INLINE void unset_special (uae_u32 x)
                    140: {
                    141:     regs.spcflags &= ~x;
                    142: }
                    143: 
                    144: #define m68k_dreg(r,num) ((r).regs[(num)])
                    145: #define m68k_areg(r,num) (((r).regs + 8)[(num)])
                    146: 
1.1.1.6   root      147: 
1.1.1.5   root      148: STATIC_INLINE void m68k_setpc (uaecptr newpc)
                    149: {
                    150:     regs.pc_p = regs.pc_oldp = get_real_address (newpc);
                    151:     regs.pc = newpc;
                    152: }
                    153: 
                    154: STATIC_INLINE uaecptr m68k_getpc (void)
                    155: {
                    156:     return regs.pc + ((char *)regs.pc_p - (char *)regs.pc_oldp);
                    157: }
                    158: 
                    159: STATIC_INLINE uaecptr m68k_getpc_p (uae_u8 *p)
                    160: {
                    161:     return regs.pc + ((char *)p - (char *)regs.pc_oldp);
                    162: }
                    163: 
1.1.1.8   root      164: #define get_ibyte(o) do_get_mem_byte(regs.pc_p + (o) + 1)
                    165: #define get_iword(o) do_get_mem_word(regs.pc_p + (o))
                    166: #define get_ilong(o) do_get_mem_long(regs.pc_p + (o))
1.1       root      167: 
1.1.1.5   root      168: STATIC_INLINE void refill_prefetch (uae_u32 currpc, uae_u32 offs)
1.1       root      169: {
1.1.1.6   root      170:     uae_u32 t = (currpc + offs) & ~1;
1.1.1.5   root      171:     uae_s32 pc_p_offs = t - currpc;
                    172:     uae_u8 *ptr = regs.pc_p + pc_p_offs;
                    173:     uae_u32 r;
                    174: #ifdef UNALIGNED_PROFITABLE
                    175:     r = *(uae_u32 *)ptr;
                    176:     regs.prefetch = r;
                    177: #else
1.1.1.8   root      178:     r = do_get_mem_long (ptr);
1.1.1.5   root      179:     do_put_mem_long (&regs.prefetch, r);
                    180: #endif
                    181:     /* printf ("PC %lx T %lx PCPOFFS %d R %lx\n", currpc, t, pc_p_offs, r); */
                    182:     regs.prefetch_pc = t;
                    183: }
1.1       root      184: 
1.1.1.5   root      185: STATIC_INLINE uae_u32 get_ibyte_prefetch (uae_s32 o)
                    186: {
                    187:     uae_u32 currpc = m68k_getpc ();
                    188:     uae_u32 addr = currpc + o + 1;
                    189:     uae_u32 offs = addr - regs.prefetch_pc;
                    190:     uae_u32 v;
                    191:     if (offs > 3) {
                    192:        refill_prefetch (currpc, o + 1);
                    193:        offs = addr - regs.prefetch_pc;
                    194:     }
                    195:     v = do_get_mem_byte (((uae_u8 *)&regs.prefetch) + offs);
                    196:     if (offs >= 2)
1.1.1.6   root      197:        refill_prefetch (currpc, 2);
1.1.1.5   root      198:     /* printf ("get_ibyte PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
                    199:     return v;
1.1       root      200: }
                    201: STATIC_INLINE uae_u32 get_iword_prefetch (uae_s32 o)
                    202: {
1.1.1.5   root      203:     uae_u32 currpc = m68k_getpc ();
                    204:     uae_u32 addr = currpc + o;
                    205:     uae_u32 offs = addr - regs.prefetch_pc;
                    206:     uae_u32 v;
                    207:     if (offs > 3) {
                    208:        refill_prefetch (currpc, o);
                    209:        offs = addr - regs.prefetch_pc;
                    210:     }
1.1.1.8   root      211:     v = do_get_mem_word (((uae_u8 *)&regs.prefetch) + offs);
1.1.1.5   root      212:     if (offs >= 2)
1.1.1.6   root      213:        refill_prefetch (currpc, 2);
1.1.1.5   root      214:     /* printf ("get_iword PC %lx ADDR %lx OFFS %lx V %lx\n", currpc, addr, offs, v); */
                    215:     return v;
1.1       root      216: }
                    217: STATIC_INLINE uae_u32 get_ilong_prefetch (uae_s32 o)
                    218: {
1.1.1.5   root      219:     uae_u32 v = get_iword_prefetch (o);
                    220:     v <<= 16;
                    221:     v |= get_iword_prefetch (o + 2);
                    222:     return v;
1.1       root      223: }
                    224: 
                    225: #define m68k_incpc(o) (regs.pc_p += (o))
                    226: 
                    227: STATIC_INLINE void fill_prefetch_0 (void)
                    228: {
                    229: }
                    230: 
                    231: #define fill_prefetch_2 fill_prefetch_0
                    232: 
                    233: /* These are only used by the 68020/68881 code, and therefore don't
                    234:  * need to handle prefetch.  */
                    235: STATIC_INLINE uae_u32 next_ibyte (void)
                    236: {
                    237:     uae_u32 r = get_ibyte (0);
                    238:     m68k_incpc (2);
                    239:     return r;
                    240: }
                    241: 
                    242: STATIC_INLINE uae_u32 next_iword (void)
                    243: {
                    244:     uae_u32 r = get_iword (0);
                    245:     m68k_incpc (2);
                    246:     return r;
                    247: }
                    248: 
                    249: STATIC_INLINE uae_u32 next_ilong (void)
                    250: {
                    251:     uae_u32 r = get_ilong (0);
                    252:     m68k_incpc (4);
                    253:     return r;
                    254: }
                    255: 
                    256: #define m68k_setpc_bcc  m68k_setpc
                    257: #define m68k_setpc_rte  m68k_setpc
                    258: 
                    259: STATIC_INLINE void m68k_setstopped (int stop)
                    260: {
                    261:     regs.stopped = stop;
1.1.1.5   root      262:     /* A traced STOP instruction drops through immediately without
                    263:        actually stopping.  */
                    264:     if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
1.1       root      265:        regs.spcflags |= SPCFLAG_STOP;
                    266: }
                    267: 
1.1.1.6   root      268: /* m68k_do_rts, m68k_do_bsr and m68k_do_jsr were originally defined in
                    269:  * compiler.h, but since that header file has been removed from Hatari,
                    270:  * they are now defined here: */
                    271: STATIC_INLINE void m68k_do_rts(void)
                    272: {
                    273:     m68k_setpc(get_long(m68k_areg(regs, 7)));
                    274:     m68k_areg(regs, 7) += 4;
                    275: }
                    276: 
                    277: STATIC_INLINE void m68k_do_bsr(uaecptr oldpc, uae_s32 offset)
                    278: {
                    279:     m68k_areg(regs, 7) -= 4;
                    280:     put_long(m68k_areg(regs, 7), oldpc);
                    281:     m68k_incpc(offset);
                    282: }
                    283: 
                    284: STATIC_INLINE void m68k_do_jsr(uaecptr oldpc, uaecptr dest)
                    285: {
                    286:     m68k_areg(regs, 7) -= 4;
                    287:     put_long(m68k_areg(regs, 7), oldpc);
                    288:     m68k_setpc(dest);
                    289: }
                    290: 
                    291: 
1.1       root      292: extern uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp);
                    293: extern uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp);
                    294: 
                    295: extern uae_s32 ShowEA (FILE *, int reg, amodes mode, wordsizes size, char *buf);
                    296: 
                    297: extern void MakeSR (void);
                    298: extern void MakeFromSR (void);
1.1.1.11  root      299: extern void Exception (int, uaecptr, int);
1.1       root      300: extern void dump_counts (void);
                    301: extern int m68k_move2c (int, uae_u32 *);
                    302: extern int m68k_movec2 (int, uae_u32 *);
                    303: extern void m68k_divl (uae_u32, uae_u32, uae_u16, uaecptr);
                    304: extern void m68k_mull (uae_u32, uae_u32, uae_u16);
1.1.1.4   root      305: extern void build_cpufunctbl(void);
1.1       root      306: extern void init_m68k (void);
                    307: extern void m68k_go (int);
                    308: extern void m68k_dumpstate (FILE *, uaecptr *);
                    309: extern void m68k_disasm (FILE *, uaecptr, uaecptr *, int);
                    310: extern void m68k_reset (void);
                    311: 
                    312: extern void mmu_op (uae_u32, uae_u16);
                    313: 
                    314: extern void fpp_opp (uae_u32, uae_u16);
                    315: extern void fdbcc_opp (uae_u32, uae_u16);
                    316: extern void fscc_opp (uae_u32, uae_u16);
                    317: extern void ftrapcc_opp (uae_u32,uaecptr);
                    318: extern void fbcc_opp (uae_u32, uaecptr, uae_u32);
                    319: extern void fsave_opp (uae_u32);
                    320: extern void frestore_opp (uae_u32);
                    321: 
1.1.1.10  root      322: extern int getDivu68kCycles (uae_u32 dividend, uae_u16 divisor);
                    323: extern int getDivs68kCycles (uae_s32 dividend, uae_s16 divisor);
1.1.1.2   root      324: 
1.1       root      325: /* Opcode of faulting instruction */
                    326: extern uae_u16 last_op_for_exception_3;
                    327: /* PC at fault time */
                    328: extern uaecptr last_addr_for_exception_3;
                    329: /* Address that generated the exception */
                    330: extern uaecptr last_fault_for_exception_3;
                    331: 
                    332: #define CPU_OP_NAME(a) op ## a
                    333: 
                    334: /* 68040 */
1.1.1.9   root      335: extern const struct cputbl op_smalltbl_0_ff[];
1.1       root      336: /* 68020 + 68881 */
1.1.1.9   root      337: extern const struct cputbl op_smalltbl_1_ff[];
1.1       root      338: /* 68020 */
1.1.1.9   root      339: extern const struct cputbl op_smalltbl_2_ff[];
1.1       root      340: /* 68010 */
1.1.1.9   root      341: extern const struct cputbl op_smalltbl_3_ff[];
1.1       root      342: /* 68000 */
1.1.1.9   root      343: extern const struct cputbl op_smalltbl_4_ff[];
1.1       root      344: /* 68000 slow but compatible.  */
1.1.1.9   root      345: extern const struct cputbl op_smalltbl_5_ff[];
1.1       root      346: 
1.1.1.2   root      347: extern cpuop_func *cpufunctbl[65536];
1.1       root      348: 
1.1.1.10  root      349: extern uae_u32 caar, cacr;
                    350: 
                    351: /* Family of the latest instruction executed (to check for pairing) */
                    352: extern int OpcodeFamily;                       /* see instrmnem in readcpu.h */
1.1.1.7   root      353: 
1.1.1.13! root      354: /* How many cycles to add to the current instruction in case a "misaligned" bus acces is made */
        !           355: /* (used when addressing mode is d8(an,ix)) */
        !           356: extern int BusCyclePenalty;
        !           357: 
1.1.1.4   root      358: #endif /* UAE_NEWCPU_H */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.