/* ======================================================================== */
/* ================================ INCLUDES ============================== */
/* ======================================================================== */
-
-extern void m68040_fpu_op0(void);
-extern void m68040_fpu_op1(void);
-extern void m68851_mmu_ops();
+struct m68ki_cpu_core;
+extern void m68040_fpu_op0(struct m68ki_cpu_core *state);
+extern void m68040_fpu_op1(struct m68ki_cpu_core *state);
+extern void m68851_mmu_ops(struct m68ki_cpu_core *state);
extern unsigned char m68ki_cycles[][0x10000];
extern void m68ki_build_opcode_table(void);
return 0;
}
-void m68k_set_reg(m68k_register_t regnum, unsigned int value)
+void m68k_set_reg(void *context, m68k_register_t regnum, unsigned int value)
{
+ m68ki_cpu_core* state = context != NULL ?(m68ki_cpu_core*)context : &m68ki_cpu;
switch(regnum)
{
case M68K_REG_D0: REG_D[0] = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_A5: REG_A[5] = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_A6: REG_A[6] = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_A7: REG_A[7] = MASK_OUT_ABOVE_32(value); return;
- case M68K_REG_PC: m68ki_jump(MASK_OUT_ABOVE_32(value)); return;
- case M68K_REG_SR: m68ki_set_sr_noint_nosp(value); return;
+ case M68K_REG_PC:
+ m68ki_jump(state, MASK_OUT_ABOVE_32(value)); return;
+ case M68K_REG_SR:
+ m68ki_set_sr_noint_nosp(state, value); return;
case M68K_REG_SP: REG_SP = MASK_OUT_ABOVE_32(value); return;
case M68K_REG_USP: if(FLAG_S)
REG_USP = MASK_OUT_ABOVE_32(value);
m68ki_initial_cycles = num_cycles;
/* See if interrupts came in */
- m68ki_check_interrupts();
+ m68ki_check_interrupts(state);
/* Make sure we're not stopped */
if(!CPU_STOPPED)
/* Main loop. Keep going until we run out of clock cycles */
do
{
- /* Set tracing accodring to T1. (T0 is done inside instruction) */
+ /* Set tracing according to T1. (T0 is done inside instruction) */
m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */
/* Set the address space for reads */
#endif
/* Read an instruction and call its handler */
- REG_IR = m68ki_read_imm_16();
- m68ki_instruction_jump_table[REG_IR](&m68ki_cpu);
+ REG_IR = m68ki_read_imm_16(state);
+ m68ki_instruction_jump_table[REG_IR](state);
USE_CYCLES(CYC_INSTRUCTION[REG_IR]);
/* Trace m68k_exception, if necessary */
}
/* Trigger a Bus Error exception */
-void m68k_pulse_bus_error(void)
+void m68k_pulse_bus_error(m68ki_cpu_core *state)
{
- m68ki_exception_bus_error();
+ m68ki_exception_bus_error(state);
}
/* Pulse the RESET line on the CPU */
/* Reset VBR */
REG_VBR = 0;
/* Go to supervisor mode */
- m68ki_set_sm_flag(SFLAG_SET | MFLAG_CLEAR);
+ m68ki_set_sm_flag(state, SFLAG_SET | MFLAG_CLEAR);
/* Invalidate the prefetch queue */
#if M68K_EMULATE_PREFETCH
#endif /* M68K_EMULATE_PREFETCH */
/* Read the initial stack pointer and program counter */
- m68ki_jump(0);
- REG_SP = m68ki_read_imm_32();
- REG_PC = m68ki_read_imm_32();
- m68ki_jump(REG_PC);
+ m68ki_jump(state, 0);
+ REG_SP = m68ki_read_imm_32(state);
+ REG_PC = m68ki_read_imm_32(state);
+ m68ki_jump(state, REG_PC);
CPU_RUN_MODE = RUN_MODE_NORMAL;
RESET_CYCLES = CYC_EXCEPTION[EXCEPTION_RESET];
/* flush the MMU's cache */
- pmmu_atc_flush();
+ pmmu_atc_flush(state);
if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
{
#if M68K_SEPARATE_READS
/* Read data immediately following the PC */
-inline unsigned int m68k_read_immediate_16(unsigned int address) {
+inline unsigned int m68k_read_immediate_16(m68ki_cpu_core *state, unsigned int address) {
#if M68K_EMULATE_PREFETCH == OPT_ON
for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
return m68k_read_memory_16(address);
}
-inline unsigned int m68k_read_immediate_32(unsigned int address) {
+inline unsigned int m68k_read_immediate_32(m68ki_cpu_core *state, unsigned int address) {
#if M68K_EMULATE_PREFETCH == OPT_ON
for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
}
/* Read data relative to the PC */
-inline unsigned int m68k_read_pcrelative_8(unsigned int address) {
+inline unsigned int m68k_read_pcrelative_8(m68ki_cpu_core *state, unsigned int address) {
for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
return m68ki_cpu.read_data[i][address - m68ki_cpu.read_addr[i]];
return m68k_read_memory_8(address);
}
-inline unsigned int m68k_read_pcrelative_16(unsigned int address) {
+inline unsigned int m68k_read_pcrelative_16(m68ki_cpu_core *state, unsigned int address) {
for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
return be16toh(((unsigned short *)(m68ki_cpu.read_data[i] + (address - m68ki_cpu.read_addr[i])))[0]);
return m68k_read_memory_16(address);
}
-inline unsigned int m68k_read_pcrelative_32(unsigned int address) {
+inline unsigned int m68k_read_pcrelative_32(m68ki_cpu_core *state, unsigned int address) {
for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
if(address >= m68ki_cpu.read_addr[i] && address < m68ki_cpu.read_upper[i]) {
return be32toh(((unsigned int *)(m68ki_cpu.read_data[i] + (address - m68ki_cpu.read_addr[i])))[0]);
#endif
-uint m68ki_read_imm6_addr_slowpath(uint32_t pc, address_translation_cache *cache)
+uint m68ki_read_imm16_addr_slowpath(m68ki_cpu_core *state, uint32_t pc, address_translation_cache *cache)
{
uint32_t address = ADDRESS_68K(pc);
uint32_t pc_address_diff = pc - address;
uint result;
if(REG_PC != CPU_PREF_ADDR)
{
- CPU_PREF_DATA = m68ki_ic_readimm16(REG_PC);
+ CPU_PREF_DATA = m68ki_ic_readimm16(state, REG_PC);
CPU_PREF_ADDR = m68ki_cpu.mmu_tmp_buserror_occurred ? ((uint32)~0) : REG_PC;
}
result = MASK_OUT_ABOVE_16(CPU_PREF_DATA);
REG_PC += 2;
if (!m68ki_cpu.mmu_tmp_buserror_occurred) {
// prefetch only if no bus error occurred in opcode fetch
- CPU_PREF_DATA = m68ki_ic_readimm16(REG_PC);
+ CPU_PREF_DATA = m68ki_ic_readimm16(state, REG_PC);
CPU_PREF_ADDR = m68ki_cpu.mmu_tmp_buserror_occurred ? ((uint32)~0) : REG_PC;
// ignore bus error on prefetch
m68ki_cpu.mmu_tmp_buserror_occurred = 0;