2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * @OSF_FREE_COPYRIGHT@
26 * @APPLE_FREE_COPYRIGHT@
30 * Author: Bill Angell, Apple
35 * Try to keep the x86 selectors in-sync with the ppc selectors.
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>
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>
59 #include <pexpert/pexpert.h>
60 #include <console/video_console.h>
61 #include <i386/cpu_data.h>
62 #include <i386/Diagnostics.h>
64 #include <i386/pmCPU.h>
66 #include <i386/hpet.h>
67 #include <mach/i386/syscall_sw.h>
69 extern uint64_t lastNapClear
;
72 uint64_t lastNapClear
= 0ULL;
73 uint64_t lastRuptClear
= 0ULL;
75 typedef struct pmdata
{
76 uint64_t pmNapDur
; /* Time since last query */
77 pmStats_t pmd
; /* Powermanagement statistics */
83 diagCall64(__unused x86_saved_state_t
* regs
)
85 panic("diagCall not yet supported for 64 bit tasks\n");
90 diagCall(x86_saved_state_t
* state
)
93 uint32_t stk
, curpos
, i
, j
;
94 uint32_t selector
, data
;
96 uint64_t currNap
, durNap
;
97 x86_saved_state32_t
*regs
;
99 assert(is_saved_state32(state
));
100 regs
= saved_state32(state
);
102 if (!(dgWork
.dgFlags
& enaDiagSCs
))
103 return 0; /* If not enabled, cause an exception */
105 stk
= regs
->uesp
; /* Point to the stack */
106 err
= copyin((user_addr_t
) (stk
+ 4), (char *) &selector
, sizeof(uint32_t)); /* Get the selector */
108 return 0; /* Failed to fetch stack */
110 switch (selector
) { /* Select the routine */
112 case dgRuptStat
: /* Suck Interruption statistics */
114 err
= copyin((user_addr_t
) (stk
+ 8), (char *) &data
, sizeof(uint32_t)); /* Get the selector */
116 if (data
== 0) {/* If number of processors is 0, clear all
118 for (i
= 0; i
< real_ncpus
; i
++) { /* Cycle through
120 for (j
= 0; j
< 256; j
++)
121 cpu_data_ptr
[i
]->cpu_hwIntCnt
[j
] = 0;
124 lastRuptClear
= mach_absolute_time(); /* Get the time of clear */
125 return 1; /* Normal return */
127 err
= copyin((user_addr_t
) (stk
+ 8), (char *) &data
, sizeof(uint32_t)); /* Get the selector */
129 (void) copyout((char *) &real_ncpus
, data
, sizeof(real_ncpus
)); /* Copy out number of
132 currNap
= mach_absolute_time(); /* Get the time now */
133 durNap
= currNap
- lastRuptClear
; /* Get the last interval
136 durNap
= 1; /* This is a very short time, make it
139 curpos
= data
+ sizeof(real_ncpus
); /* Point to the next
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
148 curpos
= curpos
+ (256 * sizeof(uint32_t) + 8); /* Point to next out put
154 default: /* Handle invalid ones */
155 return 0; /* Return an exception */
159 return 1; /* Normal non-ast check return */