]>
Commit | Line | Data |
---|---|---|
c0fea474 A |
1 | /* |
2 | * Copyright (c) 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_FREE_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * @APPLE_FREE_COPYRIGHT@ | |
27 | */ | |
28 | ||
29 | /* | |
30 | * Author: Bill Angell, Apple | |
31 | * Date: 10/auht-five | |
32 | * | |
33 | * Random diagnostics | |
34 | * | |
35 | * Try to keep the x86 selectors in-sync with the ppc selectors. | |
36 | * | |
37 | */ | |
38 | ||
39 | ||
40 | #include <kern/machine.h> | |
41 | #include <kern/processor.h> | |
42 | #include <mach/machine.h> | |
43 | #include <mach/processor_info.h> | |
44 | #include <mach/mach_types.h> | |
45 | #include <mach/boolean.h> | |
46 | #include <kern/thread.h> | |
47 | #include <kern/task.h> | |
48 | #include <kern/ipc_kobject.h> | |
49 | #include <mach/vm_param.h> | |
50 | #include <ipc/port.h> | |
51 | #include <ipc/ipc_entry.h> | |
52 | #include <ipc/ipc_space.h> | |
53 | #include <ipc/ipc_object.h> | |
54 | #include <ipc/ipc_port.h> | |
55 | #include <vm/vm_kern.h> | |
56 | #include <vm/vm_map.h> | |
57 | #include <vm/vm_page.h> | |
58 | #include <vm/pmap.h> | |
59 | #include <pexpert/pexpert.h> | |
60 | #include <console/video_console.h> | |
61 | #include <i386/cpu_data.h> | |
62 | #include <i386/Diagnostics.h> | |
63 | #include <i386/mp.h> | |
64 | #include <i386/pmCPU.h> | |
65 | #include <i386/tsc.h> | |
66 | #include <i386/hpet.h> | |
67 | #include <mach/i386/syscall_sw.h> | |
68 | ||
69 | extern uint64_t lastNapClear; | |
70 | ||
71 | diagWork dgWork; | |
72 | uint64_t lastNapClear = 0ULL; | |
73 | uint64_t lastRuptClear = 0ULL; | |
74 | ||
75 | typedef struct pmdata { | |
76 | uint64_t pmNapDur; /* Time since last query */ | |
77 | pmStats_t pmd; /* Powermanagement statistics */ | |
78 | } pmdata; | |
79 | ||
80 | ||
81 | ||
82 | int | |
83 | diagCall64(__unused x86_saved_state_t * regs) | |
84 | { | |
85 | panic("diagCall not yet supported for 64 bit tasks\n"); | |
86 | } | |
87 | ||
88 | ||
89 | int | |
90 | diagCall(x86_saved_state_t * state) | |
91 | { | |
92 | ||
93 | uint32_t stk, curpos, i, j; | |
94 | uint32_t selector, data; | |
95 | int err; | |
96 | uint64_t currNap, durNap; | |
97 | x86_saved_state32_t *regs; | |
98 | ||
99 | assert(is_saved_state32(state)); | |
100 | regs = saved_state32(state); | |
101 | ||
102 | if (!(dgWork.dgFlags & enaDiagSCs)) | |
103 | return 0; /* If not enabled, cause an exception */ | |
104 | ||
105 | stk = regs->uesp; /* Point to the stack */ | |
106 | err = copyin((user_addr_t) (stk + 4), (char *) &selector, sizeof(uint32_t)); /* Get the selector */ | |
107 | if (err) { | |
108 | return 0; /* Failed to fetch stack */ | |
109 | } | |
110 | switch (selector) { /* Select the routine */ | |
111 | ||
112 | case dgRuptStat: /* Suck Interruption statistics */ | |
113 | ||
114 | err = copyin((user_addr_t) (stk + 8), (char *) &data, sizeof(uint32_t)); /* Get the selector */ | |
115 | ||
116 | if (data == 0) {/* If number of processors is 0, clear all | |
117 | * counts */ | |
118 | for (i = 0; i < real_ncpus; i++) { /* Cycle through | |
119 | * processors */ | |
120 | for (j = 0; j < 256; j++) | |
121 | cpu_data_ptr[i]->cpu_hwIntCnt[j] = 0; | |
122 | } | |
123 | ||
124 | lastRuptClear = mach_absolute_time(); /* Get the time of clear */ | |
125 | return 1; /* Normal return */ | |
126 | } | |
127 | err = copyin((user_addr_t) (stk + 8), (char *) &data, sizeof(uint32_t)); /* Get the selector */ | |
128 | ||
129 | (void) copyout((char *) &real_ncpus, data, sizeof(real_ncpus)); /* Copy out number of | |
130 | * processors */ | |
131 | ||
132 | currNap = mach_absolute_time(); /* Get the time now */ | |
133 | durNap = currNap - lastRuptClear; /* Get the last interval | |
134 | * duration */ | |
135 | if (durNap == 0) | |
136 | durNap = 1; /* This is a very short time, make it | |
137 | * bigger */ | |
138 | ||
139 | curpos = data + sizeof(real_ncpus); /* Point to the next | |
140 | * available spot */ | |
141 | ||
142 | for (i = 0; i < real_ncpus; i++) { /* Move 'em all out */ | |
143 | (void) copyout((char *) &durNap, curpos, 8); /* Copy out the time | |
144 | * since last clear */ | |
145 | (void) copyout((char *) &cpu_data_ptr[i]->cpu_hwIntCnt, curpos + 8, 256 * sizeof(uint32_t)); /* Copy out interrupt | |
146 | * data for this | |
147 | * processor */ | |
148 | curpos = curpos + (256 * sizeof(uint32_t) + 8); /* Point to next out put | |
149 | * slot */ | |
150 | } | |
151 | ||
152 | break; | |
153 | ||
154 | default: /* Handle invalid ones */ | |
155 | return 0; /* Return an exception */ | |
156 | ||
157 | } | |
158 | ||
159 | return 1; /* Normal non-ast check return */ | |
160 | } |