2020-01-11 20:48:56 +00:00
|
|
|
/** @file Handling of low-level PPC exceptions. */
|
|
|
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include "ppcemu.h"
|
|
|
|
|
|
|
|
jmp_buf exc_env; /* Global exception environment. */
|
|
|
|
|
|
|
|
[[noreturn]] void ppc_exception_handler(Except_Type exception_type,
|
|
|
|
uint32_t srr1_bits)
|
|
|
|
{
|
|
|
|
grab_exception = true;
|
2020-01-15 03:50:01 +00:00
|
|
|
#ifdef PROFILER
|
|
|
|
exceptions_performed++;
|
|
|
|
#endif
|
2020-01-11 20:48:56 +00:00
|
|
|
bb_kind = BB_end_kind::BB_EXCEPTION;
|
|
|
|
|
|
|
|
switch(exception_type) {
|
|
|
|
case Except_Type::EXC_SYSTEM_RESET:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 0xFFFFFFFC;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0100;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_MACHINE_CHECK:
|
|
|
|
if (!(ppc_state.ppc_msr & 0x1000)) {
|
|
|
|
/* TODO: handle internal checkstop */
|
|
|
|
}
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 0xFFFFFFFC;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0200;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_DSI:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 0xFFFFFFFC;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0300;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_ISI:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_next_instruction_address;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0400;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_EXT_INT:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_next_instruction_address;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0500;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_ALIGNMENT:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 0xFFFFFFFC;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0600;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_PROGRAM:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 0xFFFFFFFC;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0700;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_NO_FPU:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = ppc_cur_instruction & 0xFFFFFFFC;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0800;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_DECR:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = (ppc_cur_instruction & 0xFFFFFFFC) + 4;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0900;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_SYSCALL:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = (ppc_cur_instruction & 0xFFFFFFFC) + 4;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0C00;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Except_Type::EXC_TRACE:
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR0] = (ppc_cur_instruction & 0xFFFFFFFC) + 4;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_next_instruction_address = 0x0D00;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//printf("Unknown exception occured: %X\n", exception_type);
|
|
|
|
//exit(-1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-28 03:39:23 +00:00
|
|
|
ppc_state.ppc_spr[SPR::SRR1] = (ppc_state.ppc_msr & 0x0000FF73) | srr1_bits;
|
2020-01-11 20:48:56 +00:00
|
|
|
ppc_state.ppc_msr &= 0xFFFB1041;
|
|
|
|
/* copy MSR[ILE] to MSR[LE] */
|
|
|
|
ppc_state.ppc_msr = (ppc_state.ppc_msr & 0xFFFFFFFE) |
|
|
|
|
((ppc_state.ppc_msr >> 16) & 1);
|
|
|
|
|
|
|
|
if (ppc_state.ppc_msr & 0x40) {
|
|
|
|
ppc_next_instruction_address |= 0xFFF00000;
|
|
|
|
}
|
|
|
|
|
|
|
|
longjmp(exc_env, 2); /* return to the main execution loop. */
|
|
|
|
}
|