]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/interrupt.c
xnu-792.13.8.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_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 <kern/etimer.h>
41 #include <kern/pms.h>
42 #include <ppc/misc_protos.h>
43 #include <ppc/trap.h>
44 #include <ppc/proc_reg.h>
45 #include <ppc/exception.h>
46 #include <ppc/savearea.h>
47 #include <pexpert/pexpert.h>
48 #include <sys/kdebug.h>
49
50 perfCallback perfIntHook = 0; /* Pointer to CHUD trap hook routine */
51
52 void unresolved_kernel_trap(int trapno,
53 struct savearea *ssp,
54 unsigned int dsisr,
55 addr64_t dar,
56 const char *message);
57
58 struct savearea * interrupt(
59 int type,
60 struct savearea *ssp,
61 unsigned int dsisr,
62 unsigned int dar)
63 {
64 int current_cpu;
65 struct per_proc_info *proc_info;
66 uint64_t now;
67 thread_t thread;
68
69 disable_preemption();
70
71 if(perfIntHook) { /* Is there a hook? */
72 if(perfIntHook(type, ssp, dsisr, dar) == KERN_SUCCESS) return ssp; /* If it succeeds, we are done... */
73 }
74
75 #if 0
76 {
77 extern void fctx_text(void);
78 fctx_test();
79 }
80 #endif
81
82
83 current_cpu = cpu_number();
84 proc_info = getPerProc();
85
86 switch (type) {
87
88 case T_DECREMENTER:
89 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0) | DBG_FUNC_NONE,
90 isync_mfdec(), (unsigned int)ssp->save_srr0, 0, 0, 0);
91
92 #if 0
93 if (pcsample_enable) {
94 if (find_user_regs(current_thread()))
95 add_pcsamples (user_pc(current_thread()));
96 }
97 #endif
98
99 now = mach_absolute_time(); /* Find out what time it is */
100
101 if(now >= proc_info->pms.pmsPop) { /* Is it time for power management state change? */
102 pmsStep(1); /* Yes, advance step */
103 now = mach_absolute_time(); /* Get the time again since we ran a bit */
104 }
105
106 thread = current_thread(); /* Find ourselves */
107 if(thread->machine.qactTimer != 0) { /* Is the timer set? */
108 if (thread->machine.qactTimer <= now) { /* It is set, has it popped? */
109 thread->machine.qactTimer = 0; /* Clear single shot timer */
110 if((unsigned int)thread->machine.vmmControl & 0xFFFFFFFE) { /* Are there any virtual machines? */
111 vmm_timer_pop(thread); /* Yes, check out them out... */
112 }
113 }
114 }
115
116 etimer_intr(USER_MODE(ssp->save_srr1), ssp->save_srr0); /* Handle event timer */
117 break;
118
119 case T_INTERRUPT:
120 /* Call the platform interrupt routine */
121 counter_always(c_incoming_interrupts++);
122
123 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_START,
124 current_cpu, (unsigned int)ssp->save_srr0, 0, 0, 0);
125
126 proc_info->interrupt_handler(
127 proc_info->interrupt_target,
128 proc_info->interrupt_refCon,
129 proc_info->interrupt_nub,
130 proc_info->interrupt_source);
131
132 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_INTR, 0) | DBG_FUNC_END,
133 0, 0, 0, 0, 0);
134
135 break;
136
137 case T_SIGP:
138 /* Did the other processor signal us? */
139 cpu_signal_handler();
140 break;
141
142 case T_SHUTDOWN:
143 cpu_doshutdown();
144 panic("returning from cpu_doshutdown()\n");
145 break;
146
147
148 default:
149 if (!Call_Debugger(type, ssp))
150 unresolved_kernel_trap(type, ssp, dsisr, dar, NULL);
151 break;
152 }
153
154 enable_preemption();
155 return ssp;
156 }