]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/interrupt.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / osfmk / ppc / interrupt.c
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * @APPLE_FREE_COPYRIGHT@
27 */
28 #include <kern/misc_protos.h>
29 #include <kern/assert.h>
30 #include <kern/thread.h>
31 #include <kern/counters.h>
32 #include <kern/etimer.h>
33 #include <kern/pms.h>
34 #include <ppc/misc_protos.h>
35 #include <ppc/trap.h>
36 #include <ppc/proc_reg.h>
37 #include <ppc/exception.h>
38 #include <ppc/savearea.h>
39 #include <pexpert/pexpert.h>
40 #include <sys/kdebug.h>
41
42 perfCallback perfIntHook = 0; /* Pointer to CHUD trap hook routine */
43
44 void unresolved_kernel_trap(int trapno,
45 struct savearea *ssp,
46 unsigned int dsisr,
47 addr64_t dar,
48 const char *message);
49
50 struct savearea * interrupt(
51 int type,
52 struct savearea *ssp,
53 unsigned int dsisr,
54 unsigned int dar)
55 {
56 int current_cpu;
57 struct per_proc_info *proc_info;
58 uint64_t now;
59 thread_t thread;
60
61 disable_preemption();
62
63 if(perfIntHook) { /* Is there a hook? */
64 if(perfIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp; /* If it succeeds, we are done... */
65 }
66
67 #if 0
68 {
69 extern void fctx_text(void);
70 fctx_test();
71 }
72 #endif
73
74
75 current_cpu = cpu_number();
76 proc_info = getPerProc();
77
78 switch (type) {
79
80 case T_DECREMENTER:
81 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0) | DBG_FUNC_NONE,
82 isync_mfdec(), (unsigned int)ssp->save_srr0, 0, 0, 0);
83
84 #if 0
85 if (pcsample_enable) {
86 if (find_user_regs(current_thread()))
87 add_pcsamples (user_pc(current_thread()));
88 }
89 #endif
90
91 now = mach_absolute_time(); /* Find out what time it is */
92
93 if(now >= proc_info->pms.pmsPop) { /* Is it time for power management state change? */
94 pmsStep(1); /* Yes, advance step */
95 now = mach_absolute_time(); /* Get the time again since we ran a bit */
96 }
97
98 thread = current_thread(); /* Find ourselves */
99 if(thread->machine.qactTimer != 0) { /* Is the timer set? */
100 if (thread->machine.qactTimer <= now) { /* It is set, has it popped? */
101 thread->machine.qactTimer = 0; /* Clear single shot timer */
102 if((unsigned int)thread->machine.vmmControl & 0xFFFFFFFE) { /* Are there any virtual machines? */
103 vmm_timer_pop(thread); /* Yes, check out them out... */
104 }
105 }
106 }
107
108 etimer_intr(USER_MODE(ssp->save_srr1), ssp->save_srr0); /* Handle event timer */
109 break;
110
111 case T_INTERRUPT:
112 /* Call the platform interrupt routine */
113 counter_always(c_incoming_interrupts++);
114
115 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_START,
116 current_cpu, (unsigned int)ssp->save_srr0, 0, 0, 0);
117
118 proc_info->interrupt_handler(
119 proc_info->interrupt_target,
120 proc_info->interrupt_refCon,
121 proc_info->interrupt_nub,
122 proc_info->interrupt_source);
123
124 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_END,
125 0, 0, 0, 0, 0);
126
127 break;
128
129 case T_SIGP:
130 /* Did the other processor signal us? */
131 cpu_signal_handler();
132 break;
133
134 case T_SHUTDOWN:
135 cpu_doshutdown();
136 panic("returning from cpu_doshutdown()\n");
137 break;
138
139
140 default:
141 if (!Call_Debugger(type, ssp))
142 unresolved_kernel_trap(type, ssp, dsisr, dar, NULL);
143 break;
144 }
145
146 enable_preemption();
147 return ssp;
148 }