]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/Diagnostics.c
34209af9eb825fea6ff0d9364d1a6b94b3073981
2 * Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * @OSF_FREE_COPYRIGHT@
32 * @APPLE_FREE_COPYRIGHT@
36 * Author: Bill Angell, Apple
41 * Try to keep the x86 selectors in-sync with the ppc selectors.
46 #include <kern/machine.h>
47 #include <kern/processor.h>
48 #include <mach/machine.h>
49 #include <mach/processor_info.h>
50 #include <mach/mach_types.h>
51 #include <mach/boolean.h>
52 #include <kern/thread.h>
53 #include <kern/task.h>
54 #include <kern/ipc_kobject.h>
55 #include <mach/vm_param.h>
57 #include <ipc/ipc_entry.h>
58 #include <ipc/ipc_space.h>
59 #include <ipc/ipc_object.h>
60 #include <ipc/ipc_port.h>
61 #include <vm/vm_kern.h>
62 #include <vm/vm_map.h>
63 #include <vm/vm_page.h>
65 #include <pexpert/pexpert.h>
66 #include <console/video_console.h>
67 #include <i386/cpu_data.h>
68 #include <i386/Diagnostics.h>
70 #include <i386/pmCPU.h>
72 #include <i386/hpet.h>
73 #include <mach/i386/syscall_sw.h>
75 extern uint64_t lastNapClear
;
78 uint64_t lastNapClear
= 0ULL;
79 uint64_t lastRuptClear
= 0ULL;
83 diagCall64(x86_saved_state_t
* state
)
85 uint64_t curpos
, i
, j
;
86 uint64_t selector
, data
;
87 uint64_t currNap
, durNap
;
88 x86_saved_state64_t
*regs
;
90 assert(is_saved_state64(state
));
91 regs
= saved_state64(state
);
93 if (!(dgWork
.dgFlags
& enaDiagSCs
))
94 return 0; /* If not enabled, cause an exception */
98 switch (selector
) { /* Select the routine */
99 case dgRuptStat
: /* Suck Interruption statistics */
100 data
= regs
->rsi
; /* Get the number of processors */
102 if (data
== 0) { /* If no location is specified for data, clear all
105 for (i
= 0; i
< real_ncpus
; i
++) { /* Cycle through
107 for (j
= 0; j
< 256; j
++)
108 cpu_data_ptr
[i
]->cpu_hwIntCnt
[j
] = 0;
111 lastRuptClear
= mach_absolute_time(); /* Get the time of clear */
112 return 1; /* Normal return */
115 (void) copyout((char *) &real_ncpus
, data
, sizeof(real_ncpus
)); /* Copy out number of
118 currNap
= mach_absolute_time(); /* Get the time now */
119 durNap
= currNap
- lastRuptClear
; /* Get the last interval
122 durNap
= 1; /* This is a very short time, make it
125 curpos
= data
+ sizeof(real_ncpus
); /* Point to the next
128 for (i
= 0; i
< real_ncpus
; i
++) { /* Move 'em all out */
129 (void) copyout((char *) &durNap
, curpos
, 8); /* Copy out the time
130 * since last clear */
131 (void) copyout((char *) &cpu_data_ptr
[i
]->cpu_hwIntCnt
, curpos
+ 8, 256 * sizeof(uint32_t)); /* Copy out interrupt
134 curpos
= curpos
+ (256 * sizeof(uint32_t) + 8); /* Point to next out put
139 default: /* Handle invalid ones */
140 return 0; /* Return an exception */
144 return 1; /* Normal non-ast check return */
149 diagCall(x86_saved_state_t
* state
)
151 uint32_t stk
, curpos
, i
, j
;
152 uint32_t selector
, data
;
154 uint64_t currNap
, durNap
;
155 x86_saved_state32_t
*regs
;
157 assert(is_saved_state32(state
));
158 regs
= saved_state32(state
);
160 if (!(dgWork
.dgFlags
& enaDiagSCs
))
161 return 0; /* If not enabled, cause an exception */
163 stk
= regs
->uesp
; /* Point to the stack */
164 err
= copyin((user_addr_t
) (stk
+ 4), (char *) &selector
, sizeof(uint32_t)); /* Get the selector */
166 return 0; /* Failed to fetch stack */
168 switch (selector
) { /* Select the routine */
169 case dgRuptStat
: /* Suck Interruption statistics */
171 err
= copyin((user_addr_t
) (stk
+ 8), (char *) &data
, sizeof(uint32_t)); /* Get the selector */
173 if (data
== 0) {/* If number of processors is 0, clear all
175 for (i
= 0; i
< real_ncpus
; i
++) { /* Cycle through
177 for (j
= 0; j
< 256; j
++)
178 cpu_data_ptr
[i
]->cpu_hwIntCnt
[j
] = 0;
181 lastRuptClear
= mach_absolute_time(); /* Get the time of clear */
182 return 1; /* Normal return */
185 (void) copyout((char *) &real_ncpus
, data
, sizeof(real_ncpus
)); /* Copy out number of
188 currNap
= mach_absolute_time(); /* Get the time now */
189 durNap
= currNap
- lastRuptClear
; /* Get the last interval
192 durNap
= 1; /* This is a very short time, make it
195 curpos
= data
+ sizeof(real_ncpus
); /* Point to the next
198 for (i
= 0; i
< real_ncpus
; i
++) { /* Move 'em all out */
199 (void) copyout((char *) &durNap
, curpos
, 8); /* Copy out the time
200 * since last clear */
201 (void) copyout((char *) &cpu_data_ptr
[i
]->cpu_hwIntCnt
, curpos
+ 8, 256 * sizeof(uint32_t)); /* Copy out interrupt
204 curpos
= curpos
+ (256 * sizeof(uint32_t) + 8); /* Point to next out put
210 default: /* Handle invalid ones */
211 return 0; /* Return an exception */
215 return 1; /* Normal non-ast check return */