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

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.7 ! root       11: static char rcsid[] = "Hatari $Id: m68000.c,v 1.21 2003/04/28 17:48:56 thothy Exp $";
1.1       root       12: 
                     13: #include "main.h"
                     14: #include "bios.h"
                     15: #include "debug.h"
                     16: #include "decode.h"
                     17: #include "gemdos.h"
1.1.1.6   root       18: #include "hatari-glue.h"
1.1       root       19: #include "int.h"
                     20: #include "m68000.h"
                     21: #include "memorySnapShot.h"
                     22: #include "mfp.h"
                     23: #include "stMemory.h"
                     24: #include "tos.h"
                     25: #include "vdi.h"
                     26: #include "xbios.h"
                     27: 
                     28: 
                     29: unsigned long ExceptionVector;
                     30: short int PendingInterruptFlag;
                     31: void *PendingInterruptFunction;
                     32: short int PendingInterruptCount;
1.1.1.7 ! root       33: Uint32 BusAddressLocation;       /* Stores the offending address for bus-/address errors */
        !            34: Uint32 BusErrorPC;               /* Value of the PC when bus error occurs */
        !            35: Uint16 BusErrorOpcode;           /* Opcode of faulting instruction */
1.1       root       36: 
                     37: 
1.1.1.3   root       38: /*-----------------------------------------------------------------------*/
1.1       root       39: /*
                     40:   Reset CPU 68000 variables
                     41: */
                     42: void M68000_Reset(BOOL bCold)
                     43: {
                     44:   int i;
                     45: 
1.1.1.7 ! root       46:   /* Clear registers */
1.1.1.5   root       47:   if (bCold)
                     48:   {
1.1       root       49:     for(i=0; i<(16+1); i++)
                     50:       Regs[i] = 0;
                     51:   }
1.1.1.7 ! root       52: 
1.1.1.6   root       53:   PendingInterruptFlag = 0;     /* Clear pending flag */
1.1       root       54: 
1.1.1.4   root       55:   /* Now directly reset the UAE CPU core: */
                     56:   m68k_reset();
1.1       root       57: }
                     58: 
1.1.1.3   root       59: 
                     60: /*-----------------------------------------------------------------------*/
1.1       root       61: /*
                     62:   Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
                     63: */
                     64: void M68000_MemorySnapShot_Capture(BOOL bSave)
                     65: {
1.1.1.3   root       66:   /* Save/Restore details */
1.1.1.4   root       67:   /*MemorySnapShot_Store(&bDoTraceException,sizeof(bDoTraceException));*/
1.1       root       68: }
                     69: 
1.1.1.3   root       70: 
                     71: /*-----------------------------------------------------------------------*/
1.1       root       72: /*
                     73:   Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
                     74:   This is for 'decode.asm' variables - as cannot use 'decode.c' as will overwrite assembler .obj file!
                     75: */
                     76: void M68000_Decode_MemorySnapShot_Capture(BOOL bSave)
                     77: {
                     78:   int ID;
                     79: 
1.1.1.3   root       80:   /* Save/Restore details */
1.1       root       81:   MemorySnapShot_Store(Regs,sizeof(Regs));
                     82:   MemorySnapShot_Store(&STRamEnd,sizeof(STRamEnd));
1.1.1.7 ! root       83:   /*MemorySnapShot_Store(&STRamEnd_BusErr,sizeof(STRamEnd_BusErr));*/
1.1       root       84:   MemorySnapShot_Store(&PendingInterruptCount,sizeof(PendingInterruptCount));
                     85:   MemorySnapShot_Store(&PendingInterruptFlag,sizeof(PendingInterruptFlag));
1.1.1.5   root       86:   if (bSave)
                     87:   {
1.1.1.3   root       88:     /* Convert function to ID */
1.1       root       89:     ID = Int_HandlerFunctionToID(PendingInterruptFunction);
                     90:     MemorySnapShot_Store(&ID,sizeof(int));
                     91:   }
1.1.1.5   root       92:   else
                     93:   {
1.1.1.3   root       94:     /* Convert ID to function */
1.1       root       95:     MemorySnapShot_Store(&ID,sizeof(int));
                     96:     PendingInterruptFunction = Int_IDToHandlerFunction(ID);
                     97:   }
1.1.1.7 ! root       98:   /*MemorySnapShot_Store(&PC,sizeof(PC));*/
        !            99:   /*MemorySnapShot_Store(&SR,sizeof(SR));*/
1.1.1.4   root      100:   /*MemorySnapShot_Store(&bInSuperMode,sizeof(bInSuperMode));*/
1.1.1.2   root      101:   /*MemorySnapShot_Store(&Reg_SuperSP,sizeof(Reg_SuperSP));*//*FIXME*/
                    102:   /*MemorySnapShot_Store(&Reg_UserSP,sizeof(Reg_UserSP));*/
1.1.1.4   root      103:   /*MemorySnapShot_Store(&EmuCCode,sizeof(EmuCCode));*/
1.1.1.7 ! root      104:   MemorySnapShot_Store(&ExceptionVector,sizeof(ExceptionVector));
1.1       root      105: }
                    106: 
                    107: 
1.1.1.3   root      108: /*-----------------------------------------------------------------------*/
1.1       root      109: /*
                    110:   BUSERROR - Access outside valid memory range
                    111: */
                    112: void M68000_BusError(unsigned long addr)
                    113: {
1.1.1.7 ! root      114:   /* FIXME: In prefetch mode, m68k_getpc() seems already to point to the next instruction */
        !           115:   BusErrorPC = m68k_getpc();
        !           116: 
        !           117:   if(BusErrorPC < TosAddress || BusErrorPC > TosAddress + TosSize)
1.1.1.5   root      118:   {
1.1.1.7 ! root      119:     /* Print bus errors (except for TOS' hardware tests) */
1.1.1.5   root      120:     fprintf(stderr, "M68000_BusError at address $%lx\n", (long)addr);
                    121:   }
                    122: 
1.1.1.7 ! root      123:   BusAddressLocation = addr;        /* Store for exception frame */
        !           124:   BusErrorOpcode = get_word(BusErrorPC);
        !           125:   set_special(SPCFLAG_BUSERROR);    /* The exception will be done in newcpu.c */
1.1       root      126: }
                    127: 
1.1.1.3   root      128: 
                    129: /*-----------------------------------------------------------------------*/
1.1       root      130: /*
                    131:   ADDRESSERROR - Access incorrect memory boundary, eg byte offset for a word access
                    132: */
                    133: void M68000_AddressError(unsigned long addr)
                    134: {
1.1.1.3   root      135:   fprintf(stderr, "M68000_AddressError at address $%lx\n", (long)addr);
                    136:   BusAddressLocation=addr;              /* Store for exception frame */
                    137:   ExceptionVector=EXCEPTION_ADDRERROR;  /* Handler */
                    138:   M68000_Exception();                   /* Cause trap */
1.1       root      139: }
                    140: 
1.1.1.3   root      141: 
                    142: /*-----------------------------------------------------------------------*/
1.1       root      143: /*
                    144:   Exception handler
                    145: */
                    146: void M68000_Exception(void)
                    147: {
1.1.1.6   root      148:   int exceptionNr = ExceptionVector/4;
1.1.1.2   root      149: 
1.1.1.6   root      150:   if(exceptionNr>24 && exceptionNr<32)  /* 68k autovector interrupt? */
                    151:   {
                    152:     /* Handle autovector interrupts the UAE's way
                    153:      * (see intlev() and do_specialties() in UAE CPU core) */
                    154: #if 1
                    155:     if(requestedInterrupt != -1)
                    156:       fprintf(stderr,"Warning: Overriding interrupt %d with %d\n",
                    157:               requestedInterrupt, exceptionNr-24);
                    158: #endif
                    159:     requestedInterrupt = exceptionNr - 24;
                    160:     set_special(SPCFLAG_INT);
                    161:   }
                    162:   else
                    163:   {
                    164:     /* Was the CPU stopped, i.e. by a STOP instruction? */
                    165:     regs.stopped = 0;
                    166:     unset_special(SPCFLAG_STOP);        /* All is go,go,go! */
                    167: 
                    168:     /* 68k exceptions are handled by Exception() of the UAE CPU core */
                    169:     Exception(exceptionNr, m68k_getpc());
                    170: 
                    171:     MakeSR();
                    172:     /* Set Status Register so interrupt can ONLY be stopped by another interrupt
                    173:      * of higher priority! */
                    174: #if 0  /* VBL and HBL are handled in the UAE CPU core (see above). */
                    175:     if (ExceptionVector==EXCEPTION_VBLANK)
                    176:       SR = (SR&SR_CLEAR_IPL)|0x0400;  /* VBL, level 4 */
                    177:     else if (ExceptionVector==EXCEPTION_HBLANK)
                    178:       SR = (SR&SR_CLEAR_IPL)|0x0200;  /* HBL, level 2 */
                    179:     else
                    180: #endif
                    181:     {
                    182:       unsigned long MFPBaseVector = (unsigned int)(MFP_VR&0xf0)<<2;
                    183:       if ( (ExceptionVector>=MFPBaseVector) && (ExceptionVector<=(MFPBaseVector+0x34)) )
                    184:         SR = (SR&SR_CLEAR_IPL)|0x0600; /* MFP, level 6 */
                    185:     }
                    186:     MakeFromSR();
                    187:   }
1.1       root      188: }
                    189: 

unix.superglobalmegacorp.com

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