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