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