#include <kern/misc_protos.h>
#include <kern/assert.h>
#include <kern/thread.h>
#include <kern/counters.h>
#include <kern/etimer.h>
#include <kern/pms.h>
#include <ppc/misc_protos.h>
#include <ppc/trap.h>
#include <ppc/proc_reg.h>
#include <ppc/exception.h>
#include <ppc/savearea.h>
#include <ppc/vmachmon.h>
#include <ppc/machine_cpu.h>
#include <pexpert/pexpert.h>
#include <sys/kdebug.h>
perfCallback perfIntHook;
#if CONFIG_DTRACE
#if (DEVELOPMENT || DEBUG )
#include <mach/sdt.h>
#endif
extern vm_offset_t dtrace_get_cpu_int_stack_top(void);
vm_offset_t dtrace_get_cpu_int_stack_top(void)
{
return getPerProc()->intstack_top_ss;
}
perfCallback tempDTraceIntHook;
#endif
void unresolved_kernel_trap(int trapno,
struct savearea *ssp,
unsigned int dsisr,
addr64_t dar,
const char *message);
unsigned int isync_mfdec(void);
struct savearea * interrupt(
int type,
struct savearea *ssp,
unsigned int dsisr,
unsigned int dar)
{
int current_cpu;
struct per_proc_info *proc_info;
uint64_t now;
thread_t thread;
disable_preemption();
if(perfIntHook) {
if(perfIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp;
}
#if CONFIG_DTRACE
if(tempDTraceIntHook) {
if(tempDTraceIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp;
}
#endif
#if 0
{
extern void fctx_text(void);
fctx_test();
}
#endif
current_cpu = cpu_number();
proc_info = getPerProc();
switch (type) {
case T_DECREMENTER:
KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0) | DBG_FUNC_NONE,
isync_mfdec(), (unsigned int)ssp->save_srr0, 0, 0, 0);
now = mach_absolute_time();
if(now >= proc_info->pms.pmsPop) {
pmsStep(1);
now = mach_absolute_time();
}
thread = current_thread();
if(thread->machine.qactTimer != 0) {
if (thread->machine.qactTimer <= now) {
thread->machine.qactTimer = 0;
if((unsigned int)thread->machine.vmmControl & 0xFFFFFFFE) {
vmm_timer_pop(thread);
}
}
}
etimer_intr(USER_MODE(ssp->save_srr1), ssp->save_srr0);
break;
case T_INTERRUPT:
counter(c_incoming_interrupts++);
KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_START,
current_cpu, (unsigned int)ssp->save_srr0, 0, 0, 0);
#if CONFIG_DTRACE && (DEVELOPMENT || DEBUG )
DTRACE_INT5(interrupt__start, void *, proc_info->interrupt_nub, int, proc_info->interrupt_source,
void *, proc_info->interrupt_target, IOInterruptHandler, proc_info->interrupt_handler,
void *, proc_info->interrupt_refCon);
#endif
proc_info->interrupt_handler(
proc_info->interrupt_target,
proc_info->interrupt_refCon,
proc_info->interrupt_nub,
proc_info->interrupt_source);
#if CONFIG_DTRACE && (DEVELOPMENT || DEBUG )
DTRACE_INT5(interrupt__complete, void *, proc_info->interrupt_nub, int, proc_info->interrupt_source,
void *, proc_info->interrupt_target, IOInterruptHandler, proc_info->interrupt_handler,
void *, proc_info->interrupt_refCon);
#endif
KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_END,
0, 0, 0, 0, 0);
break;
case T_SIGP:
cpu_signal_handler();
break;
case T_SHUTDOWN:
cpu_doshutdown();
panic("returning from cpu_doshutdown()\n");
break;
default:
if (!Call_Debugger(type, ssp))
unresolved_kernel_trap(type, ssp, dsisr, dar, NULL);
break;
}
enable_preemption();
return ssp;
}