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

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