--- hatari/src/uae-cpu/newcpu.c 2019/04/01 07:10:24 1.1.1.5 +++ hatari/src/uae-cpu/newcpu.c 2019/04/01 07:10:42 1.1.1.6 @@ -7,7 +7,10 @@ * * Adaptation to Hatari by Thomas Huth * + * This file is distributed under the GNU Public License, version 2 or at + * your option any later version. Read the file gpl.txt for details. */ +static char rcsid[] = "Hatari $Id: newcpu.c,v 1.1.1.6 2019/04/01 07:10:42 root Exp $"; #include "sysdeps.h" #include "hatari-glue.h" @@ -23,7 +26,6 @@ #include "../includes/debugui.h" - struct flag_struct regflags; int lastInstructionCycles; /* how many cycles last instruction took to execute */ @@ -48,6 +50,9 @@ int fpp_movem_next[256]; cpuop_func *cpufunctbl[65536]; +static uae_u32 busAddressErrPC = 0; /* Needed to store the right PC when bus-/address error occurs */ + + #define COUNT_INSTRS 0 #if COUNT_INSTRS @@ -102,20 +107,11 @@ void dump_counts (void) int broken_in; -static __inline__ unsigned int cft_map (unsigned int f) -{ -#ifndef HAVE_GET_WORD_UNSWAPPED - return f; -#else - return ((f >> 8) & 255) | ((f & 255) << 8); -#endif -} - static unsigned long op_illg_1 (uae_u32 opcode) REGPARAM; static unsigned long REGPARAM2 op_illg_1 (uae_u32 opcode) { - op_illg (cft_map (opcode)); + op_illg (opcode); return 4; } @@ -135,10 +131,10 @@ void build_cpufunctbl(void) cpu_level, cpu_compatible, address_space_24); for (opcode = 0; opcode < 65536; opcode++) - cpufunctbl[cft_map(opcode)] = op_illg_1; + cpufunctbl[opcode] = op_illg_1; for (i = 0; tbl[i].handler != NULL; i++) { if (! tbl[i].specific) - cpufunctbl[cft_map (tbl[i].opcode)] = tbl[i].handler; + cpufunctbl[tbl[i].opcode] = tbl[i].handler; } for (opcode = 0; opcode < 65536; opcode++) { cpuop_func *f; @@ -147,23 +143,23 @@ void build_cpufunctbl(void) continue; if (table68k[opcode].handler != -1) { - f = cpufunctbl[cft_map (table68k[opcode].handler)]; + f = cpufunctbl[table68k[opcode].handler]; if (f == op_illg_1) abort(); - cpufunctbl[cft_map(opcode)] = f; + cpufunctbl[opcode] = f; } } for (i = 0; tbl[i].handler != NULL; i++) { if (tbl[i].specific) - cpufunctbl[cft_map(tbl[i].opcode)] = tbl[i].handler; + cpufunctbl[tbl[i].opcode] = tbl[i].handler; } - /* Hataris illegal opcodes: */ - cpufunctbl[cft_map(GEMDOS_OPCODE)] = OpCode_GemDos; - cpufunctbl[cft_map(RUNOLDGEMDOS_OPCODE)] = OpCode_OldGemDos; - cpufunctbl[cft_map(CONDRV_OPCODE)] = OpCode_ConnectedDrive; - cpufunctbl[cft_map(TIMERD_OPCODE)] = OpCode_TimerD; - cpufunctbl[cft_map(VDI_OPCODE)] = OpCode_VDI; + /* Hatari's illegal opcodes: */ + cpufunctbl[GEMDOS_OPCODE] = OpCode_GemDos; + cpufunctbl[RUNOLDGEMDOS_OPCODE] = OpCode_OldGemDos; + cpufunctbl[CONDRV_OPCODE] = OpCode_ConnectedDrive; + cpufunctbl[TIMERD_OPCODE] = OpCode_TimerD; + cpufunctbl[VDI_OPCODE] = OpCode_VDI; } @@ -669,7 +665,9 @@ void MakeFromSR (void) if (regs.t1 || regs.t0) set_special (SPCFLAG_TRACE); else - unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE); + /* Keep SPCFLAG_DOTRACE, we still want a trace exception for + SR-modifying instructions (including STOP). */ + unset_special (SPCFLAG_TRACE); } @@ -680,35 +678,15 @@ void Exception(int nr, uaecptr oldpc) /*if( nr>=2 && nr<10 ) fprintf(stderr,"Exception (-> %i bombs)!\n",nr);*/ /* Intercept exceptions... - FIXME: Find a better way to do this! */ - if(bUseVDIRes) + if(bUseVDIRes && nr == 0x22) /* Trap 2 - intercept VDI call */ { - if(nr == 0x22) /* Trap 2 - intercept VDI call */ + if(!VDI()) { - if( !VDI() ) - { - /* Set 'PC' as address of 'VDI_OPCODE' illegal instruction - * This will call OpCode_VDI after completion of Trap call! - * Use to modify return structure from VDI */ - /*if (bUseVDIRes)*/ - { - VDI_OldPC = currpc; - currpc = CART_VDI_OPCODE_ADDR; - } - } - } - else if(nr == 0x0a) /* Line A */ - { - if((get_word(currpc)&0x0fff) == 0x0ff) /* 0xA0FF opcode? */ - { - /* we use this to get pointer to Line-A structure details - * (to fix for extended VDI res) */ - LineABase = regs.regs[0]; /* D0 */ - FontBase = regs.regs[9]; /* A1 */ - VDI_LineA(); - m68k_setpc(currpc + 2); - fill_prefetch_0(); - return; - } + /* Set 'PC' as address of 'VDI_OPCODE' illegal instruction + * This will call OpCode_VDI after completion of Trap call! + * Use to modify return structure from VDI */ + VDI_OldPC = currpc; + currpc = CART_VDI_OPCODE_ADDR; } } @@ -791,6 +769,11 @@ void Exception(int nr, uaecptr oldpc) fill_prefetch_0 (); regs.t1 = regs.t0 = regs.m = 0; unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE); + + /* Store a backup of the PC after bus-/address error: */ + if(nr==2 || nr==3) { + busAddressErrPC = regs.pc; + } } static void Interrupt(int nr) @@ -804,7 +787,7 @@ static void Interrupt(int nr) set_special (SPCFLAG_INT); } -static uae_u32 caar, cacr, itt0, itt1, dtt0, dtt1, tc, mmusr; +static uae_u32 caar, cacr, itt0, itt1, dtt0, dtt1, tc, mmusr, urp, srp; int m68k_move2c (int regno, uae_u32 *regp) { @@ -831,6 +814,9 @@ int m68k_move2c (int regno, uae_u32 *reg case 0x802: caar = *regp & 0xfc; break; case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg(regs, 7) = regs.msp; break; case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg(regs, 7) = regs.isp; break; + case 0x805: mmusr = *regp; break; + case 0x806: urp = *regp; break; + case 0x807: srp = *regp; break; default: op_illg (0x4E7B); return 0; @@ -863,6 +849,8 @@ int m68k_movec2 (int regno, uae_u32 *reg case 0x803: *regp = regs.m == 1 ? m68k_areg(regs, 7) : regs.msp; break; case 0x804: *regp = regs.m == 0 ? m68k_areg(regs, 7) : regs.isp; break; case 0x805: *regp = mmusr; break; + case 0x806: *regp = urp; break; + case 0x807: *regp = srp; break; default: op_illg (0x4E7A); return 0; @@ -1122,6 +1110,7 @@ void m68k_mull (uae_u32 opcode, uae_u32 } #endif } + static char* ccnames[] = { "T ","F ","HI","LS","CC","CS","NE","EQ", "VC","VS","PL","MI","GE","LT","GT","LE" }; @@ -1130,7 +1119,7 @@ void m68k_reset (void) { m68k_areg(regs, 7) = get_long(0); m68k_setpc(get_long(4)); - fill_prefetch_0 (); + refill_prefetch (m68k_getpc (), 0); regs.s = 1; regs.m = 0; regs.stopped = 0; @@ -1150,66 +1139,26 @@ void m68k_reset (void) unsigned long REGPARAM2 op_illg (uae_u32 opcode) { uaecptr pc = m68k_getpc (); -/* - if (cloanto_rom && (opcode & 0xF100) == 0x7100) { - m68k_dreg (regs, (opcode >> 9) & 7) = (uae_s8)(opcode & 0xFF); - m68k_incpc (2); - fill_prefetch_0 (); - return 4; - } -*/ + compiler_flush_jsr_stack (); - if (opcode == 0x4E7B && get_long (0x10) == 0 ) - { + if (opcode == 0x4E7B && get_long (0x10) == 0 ) { write_log ("This program requires a 68020 CPU!\n"); broken_in = 1; set_special (SPCFLAG_BRK); bQuitProgram = 1; - } -/* - if (opcode == 0xFF0D) { - if ((pc & 0xF80000) == 0xF80000) { - // This is from the dummy Kickstart replacement - uae_u16 arg = get_iword (2); - m68k_incpc (4); - ersatz_perform (arg); - fill_prefetch_0 (); - return 4; - } else if ((pc & 0xF80000) == 0xF00000) { - // User-mode STOP replacement - m68k_setstopped (1); - return 4; - } - } -*/ -/* - if ((opcode & 0xF000) == 0xA000 && (pc & 0xF80000) == 0xF00000) { - // Calltrap. - m68k_incpc(2); - call_calltrap (opcode & 0xFFF); - fill_prefetch_0 (); - return 4; } -*/ - if ((opcode & 0xF000) == 0xF000) - { + + if ((opcode & 0xF000) == 0xF000) { Exception(0xB,0); return 4; - } - if ((opcode & 0xF000) == 0xA000) - { -/* - if ((pc & 0xF80000) == 0xF00000) { - // Calltrap. - call_calltrap (opcode & 0xFFF); - } -*/ + } + if ((opcode & 0xF000) == 0xA000) { Exception(0xA,0); return 4; - } + } #if 0 - write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); + write_log ("Illegal instruction: %04x at %08lx\n", opcode, (long)pc); #endif Exception (4,0); return 4; @@ -1274,32 +1223,32 @@ static int do_specialties (void) Exception (9,last_trace_ad); } while (regs.spcflags & SPCFLAG_STOP) { - do_cycles (4); + do_cycles (8); if (regs.intmask>5) { /* We still have to care about events when IPL==7 ! */ Main_EventHandler(); if(bQuitProgram) unset_special(SPCFLAG_STOP); } if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) { - /*int intr = intlev ();*/ + int intr = intlev (); unset_special (SPCFLAG_INT | SPCFLAG_DOINT); - /*if (intr != -1 && intr > regs.intmask) { + if (intr != -1 && intr > regs.intmask) { Interrupt (intr); regs.stopped = 0; unset_special (SPCFLAG_STOP); - }*/ + } } } if (regs.spcflags & SPCFLAG_TRACE) do_trace (); if (regs.spcflags & SPCFLAG_DOINT) { - /*int intr = intlev ();*/ + int intr = intlev (); unset_special (SPCFLAG_DOINT); - /*if (intr != -1 && intr > regs.intmask) { + if (intr != -1 && intr > regs.intmask) { Interrupt (intr); regs.stopped = 0; - }*/ + } } if (regs.spcflags & SPCFLAG_INT) { unset_special (SPCFLAG_INT); @@ -1346,7 +1295,16 @@ static void m68k_run_1 (void) instrcount[opcode]++; #endif - cycles = (*cpufunctbl[cft_map(opcode)])(opcode); + cycles = (*cpufunctbl[opcode])(opcode); + + /* Unfortunately needed at the moment: */ + /* Check if we had an bus/address error and correct the PC then... */ + if(busAddressErrPC) { + /*write_log("Fixed PC to $%x instead of $%x after bus-/address error!\n", + busAddressErrPC, m68k_getpc());*/ + m68k_setpc(busAddressErrPC); + busAddressErrPC = 0; + } #ifdef DEBUG_PREFETCH if (memcmp (saved_bytes, oldpcp, 20) != 0) { @@ -1370,11 +1328,7 @@ static void m68k_run_2 (void) { while(!bQuitProgram) { int cycles; -#ifdef HAVE_GET_WORD_UNSWAPPED - uae_u32 opcode = do_get_mem_word_unswapped (regs.pc_p); -#else uae_u32 opcode = get_iword (0); -#endif /*m68k_dumpstate(stderr, NULL);*/ /*m68k_disasm(stderr, m68k_getpc (), NULL, 1);*/ @@ -1388,7 +1342,16 @@ static void m68k_run_2 (void) instrcount[opcode]++; #endif - cycles = (*cpufunctbl[cft_map(opcode)])(opcode); + cycles = (*cpufunctbl[opcode])(opcode); + + /* Unfortunately needed at the moment: */ + /* Check if we had an bus/address error and correct the PC then... */ + if(busAddressErrPC) { + /*write_log("Fixed PC to $%x instead of $%x after bus-/address error!\n", + busAddressErrPC, m68k_getpc());*/ + m68k_setpc(busAddressErrPC); + busAddressErrPC = 0; + } do_cycles (cycles); if (regs.spcflags) { @@ -1427,7 +1390,7 @@ static void m68k_verify (uaecptr addr, u last_op_for_exception_3 = opcode; m68kpc_offset = 2; - if (cpufunctbl[cft_map(opcode)] == op_illg_1) { + if (cpufunctbl[opcode] == op_illg_1) { opcode = 0x4AFC; } dp = table68k + opcode; @@ -1462,7 +1425,7 @@ void m68k_disasm (FILE *f, uaecptr addr, } opcode = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; - if (cpufunctbl[cft_map(opcode)] == op_illg_1) { + if (cpufunctbl[opcode] == op_illg_1) { opcode = 0x4AFC; } dp = table68k + opcode;