Annotation of hatari/src/m68000.c, revision 1.1.1.18

1.1       root        1: /*
1.1.1.6   root        2:   Hatari - m68000.c
1.1       root        3: 
1.1.1.6   root        4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: 
                      7:   These routines originally (in WinSTon) handled exceptions as well as some
1.1.1.5   root        8:   few OpCode's such as Line-F and Line-A. In Hatari it has mainly become a
                      9:   wrapper between the WinSTon sources and the UAE CPU code.
1.1       root       10: */
1.1.1.12  root       11: 
                     12: /* 2007/03/xx  [NP]    Possibility to add several wait states for the same instruction in              */
                     13: /*                     M68000_WaitState (e.g. clr.b $fa1b.w in Decade Demo Menu).                      */
                     14: /* 2007/04/14  [NP]    Add support for instruction pairing in M68000_AddCycles, using OpcodeFamily and */
                     15: /*                     LastOpcodeFamily (No Cooper Loader, Oh Crickey ... Hidden Screen).              */
                     16: /* 2007/04/24  [NP]    Add pairing for BCLR/Bcc.                                                       */
                     17: /* 2007/09/29  [NP]    Use the new int.c and INT_CONVERT_TO_INTERNAL.                                  */
                     18: /* 2007/11/26  [NP]    We set BusErrorPC in m68k_run_1 instead of M68000_BusError, else the BusErrorPC */
                     19: /*                     will not point to the opcode that generated the bus error.                      */
                     20: /*                     In M68000_BusError, if we have 'move.l $0,$24', we need to generate a bus error */
                     21: /*                     for the read, not for the write that should occur after (TransBeauce 2 Demo).   */
                     22: /* 2008/01/07  [NP]    Function 'M68000_InitPairing' and 'PairingArray' as a lookup table for fast     */
                     23: /*                     determination of valid pairing combinations (replace lots of 'if' tests in      */
                     24: /*                     m68000.h).                                                                      */
                     25: /* 2008/01/25  [NP]    Add pairing for LSR/MOVE (and all other bit shifting instr) (Anomaly Demo Intro)*/
                     26: /* 2008/02/02  [NP]    Add pairing for CMP/Bcc (Level 16 Fullscreen (1988)).                           */
                     27: /* 2008/02/08  [NP]    Add pairing for LSL/LEA (and all other bit shifting instr) (TVI 2 - The Year    */
                     28: /*                     After Demo).                                                                    */
                     29: /* 2008/02/11  [NP]    Add pairing for MULS/MOVEA (Delirious Demo IV Loader).                          */
                     30: /* 2008/01/25  [NP]    Add pairing for LSR/MOVEA (and all other bit shifting instr) (Decade Demo Reset)*/
1.1.1.13  root       31: /* 2008/02/16  [NP]    Add pairing for MULS/DIVS (fixes e605 demo part 3).                             */
1.1.1.12  root       32: /* 2008/03/08  [NP]    In M68000_Exception, we need to know if the exception was triggered by an MFP   */
                     33: /*                     interrupt or by a video interrupt. In the case MFP vector base was changed in   */
                     34: /*                     fffa17 to an other value than the default $40, testing exceptionNr is not enough*/
                     35: /*                     to correctly process the exception. For example, if vector base is set to $10   */
                     36: /*                     then MFP Timer A will call vector stored at address $74, which would be wrongly */
                     37: /*                     interpreted as a level 5 int (which doesn't exist on Atari and will cause an    */
1.1.1.13  root       38: /*                     assert to fail in intlevel()). We use InterruptSource to correctly recognize the*/
1.1.1.12  root       39: /*                     MFP interrupts (fix 'Toki' end part fullscreen which sets vector base to $10).  */
1.1.1.13  root       40: /* 2008/04/14  [NP]    Add pairing for BTST/Bcc (eg btst #7,d0 + bne.s label  (with branch taken)).    */
                     41: /* 2008/04/15  [NP]    As tested on a real STF :                                                       */
                     42: /*                             - MUL/DIV can pair (but DIV/MUL can't)                                  */
                     43: /*                                     (eg mulu d0,d0 + divs d1,d1 with d0=0 and d1=1)                 */
                     44: /*                             - MUL/MOVE can pair, but not DIV/MOVE                                   */
                     45: /*                             - EXG/MOVE can pair (eg exg d3,d4 + move.l 0(a3,d1.w),a4)               */
                     46: /*                             - MOVE/DBcc can't pair                                                  */
                     47: /* 2008/04/16  [NP]    Functions 'M68000_InitPairing_BitShift' to ease code maintenance.               */
                     48: /*                     Tested on STF : add pairing between bit shift instr and ADD/SUB/OR/AND/EOR/NOT  */
                     49: /*                     CLR/NEG (certainly some more possible, haven't tested everything)               */
                     50: /*                     (fixes lsr.w #4,d4 + add.b $f0(a4,d4),d7 used in Zoolook part of ULM New Year). */
                     51: /* 2008/07/08  [NP]    Add pairing between bit shift instr and ADDX/SUBX/ABCD/SBCD (fixes lsl.l #1,d0  */
                     52: /*                     + abcd d1,d1 used in Dragonnels - Rainbow Wall).                                */
                     53: /* 2008/10/05  [NP]    Pass the 'ExceptionSource' parameter to Exception() in uae-cpu/newcpu.c         */
1.1.1.16  root       54: /* 2010/05/07  [NP]    Add pairing for ADD/MOVE ; such pairing should only be possible when combined   */
                     55: /*                     with d8(an,ix) address mode (eg: add.l (a5,d1.w),d0 + move.b 7(a5,d1.w),d5)     */
                     56: /*                     (fixes Sommarhack 2010 Invitation by DHS).                                      */
1.1.1.17  root       57: /* 2010/11/07  [NP]    Add pairing between bit shift instr and JMP (fixes lsl.w #2,d0 + jmp 2(pc,d0)   */
                     58: /*                     used in Fullparts by Hemoroids).                                                */
1.1.1.18! root       59: /* 2011/12/11  [NP]    Add pairing between MUL and JSR (fixes muls #52,d2 + jsr 0(a1,d2.w) used in     */
        !            60: /*                     Lemmings Compilation 40's Intro).                                                */
1.1.1.12  root       61: 
                     62: 
1.1.1.14  root       63: const char M68000_fileid[] = "Hatari m68000.c : " __DATE__ " " __TIME__;
1.1       root       64: 
                     65: #include "main.h"
1.1.1.12  root       66: #include "configuration.h"
1.1       root       67: #include "gemdos.h"
1.1.1.6   root       68: #include "hatari-glue.h"
1.1.1.16  root       69: #include "cycInt.h"
1.1       root       70: #include "m68000.h"
                     71: #include "memorySnapShot.h"
                     72: #include "mfp.h"
1.1.1.12  root       73: #include "options.h"
                     74: #include "savestate.h"
1.1       root       75: #include "stMemory.h"
                     76: #include "tos.h"
                     77: 
                     78: 
1.1.1.12  root       79: Uint32 BusErrorAddress;         /* Stores the offending address for bus-/address errors */
                     80: Uint32 BusErrorPC;              /* Value of the PC when bus error occurs */
1.1.1.13  root       81: bool bBusErrorReadWrite;        /* 0 for write error, 1 for read error */
1.1.1.12  root       82: int nCpuFreqShift;              /* Used to emulate higher CPU frequencies: 0=8MHz, 1=16MHz, 2=32Mhz */
                     83: int nWaitStateCycles;           /* Used to emulate the wait state cycles of certain IO registers */
1.1.1.14  root       84: int BusMode = BUS_MODE_CPU;    /* Used to tell which part is owning the bus (cpu, blitter, ...) */
1.1.1.12  root       85: 
1.1.1.16  root       86: int LastOpcodeFamily = i_NOP;  /* see the enum in readcpu.h i_XXX */
                     87: int LastInstrCycles = 0;       /* number of cycles for previous instr. (not rounded to 4) */
                     88: int Pairing = 0;               /* set to 1 if the latest 2 intr paired */
1.1.1.12  root       89: char PairingArray[ MAX_OPCODE_FAMILY ][ MAX_OPCODE_FAMILY ];
                     90: 
                     91: 
                     92: /* to convert the enum from OpcodeFamily to a readable value for pairing's debug */
                     93: const char *OpcodeName[] = { "ILLG",
                     94:        "OR","AND","EOR","ORSR","ANDSR","EORSR",
                     95:        "SUB","SUBA","SUBX","SBCD",
                     96:        "ADD","ADDA","ADDX","ABCD",
                     97:        "NEG","NEGX","NBCD","CLR","NOT","TST",
                     98:        "BTST","BCHG","BCLR","BSET",
                     99:        "CMP","CMPM","CMPA",
                    100:        "MVPRM","MVPMR","MOVE","MOVEA","MVSR2","MV2SR",
                    101:        "SWAP","EXG","EXT","MVMEL","MVMLE",
                    102:        "TRAP","MVR2USP","MVUSP2R","RESET","NOP","STOP","RTE","RTD",
                    103:        "LINK","UNLK",
                    104:        "RTS","TRAPV","RTR",
                    105:        "JSR","JMP","BSR","Bcc",
                    106:        "LEA","PEA","DBcc","Scc",
                    107:        "DIVU","DIVS","MULU","MULS",
                    108:        "ASR","ASL","LSR","LSL","ROL","ROR","ROXL","ROXR",
                    109:        "ASRW","ASLW","LSRW","LSLW","ROLW","RORW","ROXLW","ROXRW",
                    110:        "CHK","CHK2",
                    111:        "MOVEC2","MOVE2C","CAS","CAS2","DIVL","MULL",
                    112:        "BFTST","BFEXTU","BFCHG","BFEXTS","BFCLR","BFFFO","BFSET","BFINS",
                    113:        "PACK","UNPK","TAS","BKPT","CALLM","RTM","TRAPcc","MOVES",
                    114:        "FPP","FDBcc","FScc","FTRAPcc","FBcc","FSAVE","FRESTORE",
                    115:        "CINVL","CINVP","CINVA","CPUSHL","CPUSHP","CPUSHA","MOVE16",
                    116:        "MMUOP"
                    117: };
1.1.1.8   root      118: 
1.1.1.12  root      119: 
                    120: /*-----------------------------------------------------------------------*/
                    121: /**
1.1.1.13  root      122:  * Add pairing between all the bit shifting instructions and a given Opcode
                    123:  */
                    124: 
                    125: static void M68000_InitPairing_BitShift ( int OpCode )
                    126: {
                    127:        PairingArray[  i_ASR ][ OpCode ] = 1; 
                    128:        PairingArray[  i_ASL ][ OpCode ] = 1; 
                    129:        PairingArray[  i_LSR ][ OpCode ] = 1; 
                    130:        PairingArray[  i_LSL ][ OpCode ] = 1; 
                    131:        PairingArray[  i_ROL ][ OpCode ] = 1; 
                    132:        PairingArray[  i_ROR ][ OpCode ] = 1; 
                    133:        PairingArray[ i_ROXR ][ OpCode ] = 1; 
                    134:        PairingArray[ i_ROXL ][ OpCode ] = 1; 
                    135: }
                    136: 
                    137: 
                    138: /**
1.1.1.12  root      139:  * Init the pairing matrix
                    140:  * Two instructions can pair if PairingArray[ LastOpcodeFamily ][ OpcodeFamily ] == 1
                    141:  */
1.1.1.16  root      142: static void M68000_InitPairing(void)
1.1.1.12  root      143: {
                    144:        /* First, clear the matrix (pairing is false) */
                    145:        memset(PairingArray , 0 , MAX_OPCODE_FAMILY * MAX_OPCODE_FAMILY);
                    146: 
                    147:        /* Set all valid pairing combinations to 1 */
                    148:        PairingArray[  i_EXG ][ i_DBcc ] = 1;
1.1.1.13  root      149:        PairingArray[  i_EXG ][ i_MOVE ] = 1;
                    150:        PairingArray[  i_EXG ][ i_MOVEA] = 1;
                    151: 
1.1.1.12  root      152:        PairingArray[ i_CMPA ][  i_Bcc ] = 1;
                    153:        PairingArray[  i_CMP ][  i_Bcc ] = 1;
1.1.1.13  root      154: 
                    155:        M68000_InitPairing_BitShift ( i_DBcc );
                    156:        M68000_InitPairing_BitShift ( i_MOVE );
                    157:        M68000_InitPairing_BitShift ( i_MOVEA );
                    158:        M68000_InitPairing_BitShift ( i_LEA );
1.1.1.17  root      159:        M68000_InitPairing_BitShift ( i_JMP );
1.1.1.13  root      160: 
1.1.1.12  root      161:        PairingArray[ i_MULU ][ i_MOVEA] = 1; 
                    162:        PairingArray[ i_MULS ][ i_MOVEA] = 1; 
                    163:        PairingArray[ i_MULU ][ i_MOVE ] = 1; 
                    164:        PairingArray[ i_MULS ][ i_MOVE ] = 1; 
1.1.1.13  root      165: 
                    166:        PairingArray[ i_MULU ][ i_DIVU ] = 1;
                    167:        PairingArray[ i_MULU ][ i_DIVS ] = 1;
                    168:        PairingArray[ i_MULS ][ i_DIVU ] = 1;
                    169:        PairingArray[ i_MULS ][ i_DIVS ] = 1;
                    170: 
1.1.1.18! root      171:        PairingArray[ i_MULU ][ i_JSR ] = 1;
        !           172:        PairingArray[ i_MULS ][ i_JSR ] = 1;
        !           173: 
1.1.1.13  root      174:        PairingArray[ i_BTST ][  i_Bcc ] = 1;
                    175: 
                    176:        M68000_InitPairing_BitShift ( i_ADD );
                    177:        M68000_InitPairing_BitShift ( i_SUB );
                    178:        M68000_InitPairing_BitShift ( i_OR );
                    179:        M68000_InitPairing_BitShift ( i_AND );
                    180:        M68000_InitPairing_BitShift ( i_EOR );
                    181:        M68000_InitPairing_BitShift ( i_NOT );
                    182:        M68000_InitPairing_BitShift ( i_CLR );
                    183:        M68000_InitPairing_BitShift ( i_NEG );
                    184:        M68000_InitPairing_BitShift ( i_ADDX );
                    185:        M68000_InitPairing_BitShift ( i_SUBX );
                    186:        M68000_InitPairing_BitShift ( i_ABCD );
                    187:        M68000_InitPairing_BitShift ( i_SBCD );
1.1.1.16  root      188: 
                    189:        PairingArray[ i_ADD ][ i_MOVE ] = 1;            /* when using xx(an,dn) addr mode */
                    190:        PairingArray[ i_SUB ][ i_MOVE ] = 1;
                    191: }
                    192: 
                    193: 
                    194: /**
                    195:  * One-time CPU initialization.
                    196:  */
                    197: void M68000_Init(void)
                    198: {
                    199:        /* Init UAE CPU core */
                    200:        Init680x0();
                    201: 
                    202:        /* Init the pairing matrix */
                    203:        M68000_InitPairing();
1.1.1.12  root      204: }
1.1       root      205: 
                    206: 
1.1.1.3   root      207: /*-----------------------------------------------------------------------*/
1.1.1.12  root      208: /**
                    209:  * Reset CPU 68000 variables
                    210:  */
1.1.1.13  root      211: void M68000_Reset(bool bCold)
1.1       root      212: {
1.1.1.12  root      213:        /* Clear registers */
                    214:        if (bCold)
                    215:        {
1.1.1.16  root      216:                memset(&regs, 0, sizeof(regs));
1.1.1.12  root      217:        }
                    218: 
                    219:        /* Now directly reset the UAE CPU core: */
1.1.1.17  root      220:        /* Laurent : for now, using parameter 0, but some other parameters can be used here (see newcpu.c) */
                    221: #if ENABLE_WINUAE_CPU
                    222:        m68k_reset(0);
                    223: #else
1.1.1.12  root      224:        m68k_reset();
1.1.1.17  root      225: #endif
1.1.1.14  root      226:        BusMode = BUS_MODE_CPU;
1.1.1.12  root      227: }
                    228: 
                    229: 
                    230: /*-----------------------------------------------------------------------*/
                    231: /**
1.1.1.16  root      232:  * Start 680x0 emulation
1.1.1.12  root      233:  */
                    234: void M68000_Start(void)
                    235: {
                    236:        /* Load initial memory snapshot */
                    237:        if (bLoadMemorySave)
                    238:        {
1.1.1.15  root      239:                MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, false);
1.1.1.12  root      240:        }
                    241:        else if (bLoadAutoSave)
                    242:        {
1.1.1.15  root      243:                MemorySnapShot_Restore(ConfigureParams.Memory.szAutoSaveFileName, false);
1.1.1.12  root      244:        }
1.1.1.7   root      245: 
1.1.1.15  root      246:        m68k_go(true);
1.1       root      247: }
                    248: 
1.1.1.3   root      249: 
                    250: /*-----------------------------------------------------------------------*/
1.1.1.12  root      251: /**
1.1.1.17  root      252:  * Check whether CPU settings have been changed.
1.1.1.12  root      253:  */
1.1.1.17  root      254: void M68000_CheckCpuSettings(void)
1.1.1.12  root      255: {
1.1.1.17  root      256:        if (ConfigureParams.System.nCpuFreq < 12)
                    257:        {
                    258:                ConfigureParams.System.nCpuFreq = 8;
                    259:                nCpuFreqShift = 0;
                    260:        }
                    261:        else if (ConfigureParams.System.nCpuFreq > 26)
                    262:        {
                    263:                ConfigureParams.System.nCpuFreq = 32;
                    264:                nCpuFreqShift = 2;
                    265:        }
                    266:        else
                    267:        {
                    268:                ConfigureParams.System.nCpuFreq = 16;
                    269:                nCpuFreqShift = 1;
                    270:        }
1.1.1.12  root      271:        changed_prefs.cpu_level = ConfigureParams.System.nCpuLevel;
                    272:        changed_prefs.cpu_compatible = ConfigureParams.System.bCompatibleCpu;
1.1.1.17  root      273: 
                    274: #if ENABLE_WINUAE_CPU
                    275:        switch (changed_prefs.cpu_level) {
                    276:                case 0 : changed_prefs.cpu_model = 68000; break;
                    277:                case 1 : changed_prefs.cpu_model = 68010; break;
                    278:                case 2 : changed_prefs.cpu_model = 68020; break;
                    279:                case 3 : changed_prefs.cpu_model = 68030; break;
                    280:                case 4 : changed_prefs.cpu_model = 68040; break;
                    281:                case 5 : changed_prefs.cpu_model = 68060; break;
                    282:                default: fprintf (stderr, "Init680x0() : Error, cpu_level unknown\n");
                    283:        }
                    284: 
                    285:        changed_prefs.address_space_24 = ConfigureParams.System.bAddressSpace24;
                    286:        changed_prefs.cpu_cycle_exact = ConfigureParams.System.bCycleExactCpu;
                    287:        changed_prefs.fpu_model = ConfigureParams.System.n_FPUType;
                    288:        changed_prefs.fpu_strict = ConfigureParams.System.bCompatibleFPU;
                    289:        changed_prefs.mmu_model = ConfigureParams.System.bMMU;
1.1.1.12  root      290: #endif
                    291:        if (table68k)
                    292:                check_prefs_changed_cpu();
                    293: }
                    294: 
                    295: 
                    296: /*-----------------------------------------------------------------------*/
                    297: /**
                    298:  * Save/Restore snapshot of CPU variables ('MemorySnapShot_Store' handles type)
                    299:  */
1.1.1.13  root      300: void M68000_MemorySnapShot_Capture(bool bSave)
1.1       root      301: {
1.1.1.12  root      302:        Uint32 savepc;
1.1.1.17  root      303: #if ENABLE_WINUAE_CPU
                    304:        int len;
                    305:        uae_u8 *chunk = 0;
                    306: #endif
1.1       root      307: 
1.1.1.12  root      308:        /* For the UAE CPU core: */
                    309:        MemorySnapShot_Store(&currprefs.address_space_24,
                    310:                             sizeof(currprefs.address_space_24));
                    311:        MemorySnapShot_Store(&regs.regs[0], sizeof(regs.regs));       /* D0-D7 A0-A6 */
                    312: 
                    313:        if (bSave)
                    314:        {
                    315:                savepc = M68000_GetPC();
                    316:                MemorySnapShot_Store(&savepc, sizeof(savepc));            /* PC */
                    317:        }
                    318:        else
                    319:        {
                    320:                MemorySnapShot_Store(&savepc, sizeof(savepc));            /* PC */
                    321:                regs.pc = savepc;
                    322: #ifdef UAE_NEWCPU_H
                    323:                regs.prefetch_pc = regs.pc + 128;
                    324: #endif
                    325:        }
1.1.1.8   root      326: 
1.1.1.12  root      327: #ifdef UAE_NEWCPU_H
                    328:        MemorySnapShot_Store(&regs.prefetch, sizeof(regs.prefetch));  /* prefetch */
                    329: #else
                    330:        uae_u32 prefetch_dummy;
                    331:        MemorySnapShot_Store(&prefetch_dummy, sizeof(prefetch_dummy));
                    332: #endif
                    333: 
                    334:        if (bSave)
                    335:        {
                    336:                MakeSR();
                    337:                if (regs.s)
                    338:                {
                    339:                        MemorySnapShot_Store(&regs.usp, sizeof(regs.usp));    /* USP */
                    340:                        MemorySnapShot_Store(&regs.regs[15], sizeof(regs.regs[15]));  /* ISP */
                    341:                }
                    342:                else
                    343:                {
                    344:                        MemorySnapShot_Store(&regs.regs[15], sizeof(regs.regs[15]));  /* USP */
                    345:                        MemorySnapShot_Store(&regs.isp, sizeof(regs.isp));    /* ISP */
                    346:                }
                    347:                MemorySnapShot_Store(&regs.sr, sizeof(regs.sr));          /* SR/CCR */
                    348:        }
                    349:        else
                    350:        {
                    351:                MemorySnapShot_Store(&regs.usp, sizeof(regs.usp));
                    352:                MemorySnapShot_Store(&regs.isp, sizeof(regs.isp));
                    353:                MemorySnapShot_Store(&regs.sr, sizeof(regs.sr));
                    354:        }
                    355:        MemorySnapShot_Store(&regs.stopped, sizeof(regs.stopped));
                    356:        MemorySnapShot_Store(&regs.dfc, sizeof(regs.dfc));            /* DFC */
                    357:        MemorySnapShot_Store(&regs.sfc, sizeof(regs.sfc));            /* SFC */
                    358:        MemorySnapShot_Store(&regs.vbr, sizeof(regs.vbr));            /* VBR */
1.1.1.17  root      359: #if ENABLE_WINUAE_CPU
                    360:        MemorySnapShot_Store(&regs.caar, sizeof(regs.caar));          /* CAAR */
                    361:        MemorySnapShot_Store(&regs.cacr, sizeof(regs.cacr));          /* CACR */
                    362: #else
1.1.1.12  root      363:        MemorySnapShot_Store(&caar, sizeof(caar));                    /* CAAR */
                    364:        MemorySnapShot_Store(&cacr, sizeof(cacr));                    /* CACR */
1.1.1.17  root      365: #endif
1.1.1.12  root      366:        MemorySnapShot_Store(&regs.msp, sizeof(regs.msp));            /* MSP */
                    367: 
                    368:        if (!bSave)
                    369:        {
                    370:                M68000_SetPC(regs.pc);
                    371:                /* MakeFromSR() must not swap stack pointer */
                    372:                regs.s = (regs.sr >> 13) & 1;
                    373:                MakeFromSR();
                    374:                /* set stack pointer */
                    375:                if (regs.s)
                    376:                        m68k_areg(regs, 7) = regs.isp;
                    377:                else
                    378:                        m68k_areg(regs, 7) = regs.usp;
                    379:        }
                    380: 
1.1.1.17  root      381: #if ENABLE_WINUAE_CPU
                    382:        if (bSave)
                    383:                save_fpu(&len,0);
                    384:        else
                    385:                restore_fpu(chunk);
                    386: #else
1.1.1.12  root      387:        if (bSave)
                    388:                save_fpu();
                    389:        else
                    390:                restore_fpu();
1.1.1.17  root      391: #endif
1.1       root      392: }
                    393: 
                    394: 
1.1.1.3   root      395: /*-----------------------------------------------------------------------*/
1.1.1.12  root      396: /**
                    397:  * BUSERROR - Access outside valid memory range.
1.1.1.17  root      398:  * Use bRead = 0 for write errors and bRead = 1 for read errors!
1.1.1.12  root      399:  */
1.1.1.17  root      400: void M68000_BusError(Uint32 addr, bool bRead)
1.1       root      401: {
1.1.1.12  root      402:        /* FIXME: In prefetch mode, m68k_getpc() seems already to point to the next instruction */
                    403:        // BusErrorPC = M68000_GetPC();         /* [NP] We set BusErrorPC in m68k_run_1 */
1.1.1.7   root      404: 
1.1.1.15  root      405:        /* Do not print message when TOS is testing for available HW or
                    406:         * when a program just checks for the floating point co-processor. */
                    407:        if ((BusErrorPC < TosAddress || BusErrorPC > TosAddress + TosSize)
                    408:            && addr != 0xfffa42)
1.1.1.12  root      409:        {
1.1.1.15  root      410:                /* Print bus error message */
1.1.1.17  root      411:                fprintf(stderr, "M68000 Bus Error %s at address $%x.\n",
                    412:                        bRead ? "reading" : "writing", addr);
1.1.1.12  root      413:        }
                    414: 
                    415:        if ((regs.spcflags & SPCFLAG_BUSERROR) == 0)    /* [NP] Check that the opcode has not already generated a read bus error */
                    416:        {
                    417:                BusErrorAddress = addr;                         /* Store for exception frame */
1.1.1.17  root      418:                bBusErrorReadWrite = bRead;
1.1.1.12  root      419:                M68000_SetSpecial(SPCFLAG_BUSERROR);            /* The exception will be done in newcpu.c */
                    420:        }
1.1       root      421: }
                    422: 
1.1.1.3   root      423: 
                    424: /*-----------------------------------------------------------------------*/
1.1.1.12  root      425: /**
                    426:  * Exception handler
                    427:  */
1.1.1.13  root      428: void M68000_Exception(Uint32 ExceptionVector , int ExceptionSource)
1.1.1.12  root      429: {
                    430:        int exceptionNr = ExceptionVector/4;
                    431: 
1.1.1.16  root      432:        if ((ExceptionSource == M68000_EXC_SRC_AUTOVEC)
                    433:                && (exceptionNr>24 && exceptionNr<32))  /* 68k autovector interrupt? */
1.1.1.12  root      434:        {
                    435:                /* Handle autovector interrupts the UAE's way
                    436:                 * (see intlev() and do_specialties() in UAE CPU core) */
                    437:                /* In our case, this part is only called for HBL and VBL interrupts */
                    438:                int intnr = exceptionNr - 24;
                    439:                pendingInterrupts |= (1 << intnr);
                    440:                M68000_SetSpecial(SPCFLAG_INT);
                    441:        }
1.1.1.13  root      442: 
                    443:        else                                                    /* MFP or direct CPU exceptions */
1.1.1.12  root      444:        {
                    445:                Uint16 SR;
                    446: 
                    447:                /* Was the CPU stopped, i.e. by a STOP instruction? */
                    448:                if (regs.spcflags & SPCFLAG_STOP)
                    449:                {
                    450:                        regs.stopped = 0;
                    451:                        M68000_UnsetSpecial(SPCFLAG_STOP);    /* All is go,go,go! */
                    452:                }
                    453: 
                    454:                /* 68k exceptions are handled by Exception() of the UAE CPU core */
1.1.1.17  root      455: #if ENABLE_WINUAE_CPU
                    456:                Exception(exceptionNr, m68k_getpc(), ExceptionSource);
                    457: #else
1.1.1.12  root      458: #ifdef UAE_NEWCPU_H
1.1.1.13  root      459:                Exception(exceptionNr, m68k_getpc(), ExceptionSource);
1.1.1.12  root      460: #else
                    461:                Exception(exceptionNr, &regs, m68k_getpc(&regs));
                    462: #endif
1.1.1.17  root      463: #endif
1.1.1.12  root      464:                SR = M68000_GetSR();
                    465: 
                    466:                /* Set Status Register so interrupt can ONLY be stopped by another interrupt
                    467:                 * of higher priority! */
1.1.1.16  root      468:                if (ExceptionSource == M68000_EXC_SRC_INT_MFP)
1.1.1.12  root      469:                {
                    470:                        Uint32 MFPBaseVector = (unsigned int)(MFP_VR&0xf0)<<2;
                    471:                        if ( (ExceptionVector>=MFPBaseVector) && (ExceptionVector<=(MFPBaseVector+0x3c)) )
                    472:                                SR = (SR&SR_CLEAR_IPL)|0x0600; /* MFP, level 6 */
                    473:                }
1.1.1.16  root      474:                else if (ExceptionSource == M68000_EXC_SRC_INT_DSP)
                    475:                {
                    476:                        SR = (SR&SR_CLEAR_IPL)|0x0600;     /* DSP, level 6 */
                    477:                }
1.1.1.12  root      478: 
                    479:                M68000_SetSR(SR);
                    480:        }
1.1       root      481: }
                    482: 
1.1.1.8   root      483: 
                    484: /*-----------------------------------------------------------------------*/
1.1.1.12  root      485: /**
                    486:  * There seem to be wait states when a program accesses certain hardware
                    487:  * registers on the ST. Use this function to simulate these wait states.
                    488:  * [NP] with some instructions like CLR, we have a read then a write at the
                    489:  * same location, so we may have 2 wait states (read and write) to add
                    490:  * (nWaitStateCycles should be reset to 0 after the cycles were added).
                    491:  */
1.1.1.11  root      492: void M68000_WaitState(int nCycles)
1.1.1.8   root      493: {
1.1.1.12  root      494:        M68000_SetSpecial(SPCFLAG_EXTRA_CYCLES);
1.1.1.11  root      495: 
1.1.1.12  root      496:        nWaitStateCycles += nCycles;    /* add all the wait states for this instruction */
1.1.1.8   root      497: }

unix.superglobalmegacorp.com

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