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