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

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