1.1 --- a/src/musashi/m68kcpu.h Wed Apr 16 02:07:24 2014 -0600 1.2 +++ b/src/musashi/m68kcpu.h Wed Apr 16 02:20:43 2014 -0600 1.3 @@ -28,10 +28,9 @@ 1.4 1.5 #include "m68k.h" 1.6 #include <limits.h> 1.7 +#include <string.h> 1.8 1.9 -#if M68K_EMULATE_ADDRESS_ERROR 1.10 #include <setjmp.h> 1.11 -#endif /* M68K_EMULATE_ADDRESS_ERROR */ 1.12 1.13 /* ======================================================================== */ 1.14 /* ==================== ARCHITECTURE-DEPENDANT DEFINES ==================== */ 1.15 @@ -287,6 +286,7 @@ 1.16 #define CPU_TYPE m68ki_cpu.cpu_type 1.17 1.18 #define REG_DA m68ki_cpu.dar /* easy access to data and address regs */ 1.19 +#define REG_DA_SAVE m68ki_cpu.dar_save 1.20 #define REG_D m68ki_cpu.dar 1.21 #define REG_A (m68ki_cpu.dar+8) 1.22 #define REG_PPC m68ki_cpu.ppc 1.23 @@ -751,6 +751,8 @@ 1.24 { 1.25 uint cpu_type; /* CPU Type: 68000, 68010, 68EC020, or 68020 */ 1.26 uint dar[16]; /* Data and Address Registers */ 1.27 + uint dar_save[16]; /* Saved Data and Address Registers (pushed onto the 1.28 + stack when a bus error occurs)*/ 1.29 uint ppc; /* Previous program counter */ 1.30 uint pc; /* Program Counter */ 1.31 uint sp[7]; /* User, Interrupt, and Master Stack Pointers */ 1.32 @@ -1689,20 +1691,31 @@ 1.33 USE_CYCLES(CYC_EXCEPTION[EXCEPTION_PRIVILEGE_VIOLATION] - CYC_INSTRUCTION[REG_IR]); 1.34 } 1.35 1.36 +extern jmp_buf m68ki_bus_error_jmp_buf; 1.37 +extern jmp_buf m68ki_bus_error_return_jmp_buf; 1.38 + 1.39 +#define m68ki_check_bus_error_trap() setjmp(m68ki_bus_error_jmp_buf) 1.40 + 1.41 /* Exception for bus error */ 1.42 INLINE void m68ki_exception_bus_error(void) 1.43 { 1.44 + int i; 1.45 BUS_ERROR_OCCURRED = 1; 1.46 /* Use up some clock cycles and undo the instruction's cycles */ 1.47 USE_CYCLES(CYC_EXCEPTION[EXCEPTION_BUS_ERROR] - CYC_INSTRUCTION[REG_IR]); 1.48 + 1.49 + for (i = 15; i >= 0; i--){ 1.50 + REG_DA[i] = REG_DA_SAVE[i]; 1.51 + } 1.52 + 1.53 + uint sr = m68ki_init_exception(); 1.54 + m68ki_stack_frame_1000(REG_PPC, sr, EXCEPTION_BUS_ERROR); 1.55 + 1.56 + m68ki_jump_vector(EXCEPTION_BUS_ERROR); 1.57 + longjmp(m68ki_bus_error_jmp_buf, 1); 1.58 } 1.59 1.60 -INLINE void m68ki_jump_bus_error_vector(void) 1.61 -{ 1.62 - uint sr = m68ki_init_exception(); 1.63 - m68ki_stack_frame_1000(REG_PPC, sr, EXCEPTION_BUS_ERROR); 1.64 - m68ki_jump_vector(EXCEPTION_BUS_ERROR); 1.65 -} 1.66 +extern int cpu_log_enabled; 1.67 1.68 /* Exception for A-Line instructions */ 1.69 INLINE void m68ki_exception_1010(void)