src/musashi/m68kcpu.h

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