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

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