]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu_capabilities.h
a820ea7aa442cabbfdda9476a84b67011d0c189c
[apple/xnu.git] / osfmk / i386 / cpu_capabilities.h
1 /*
2 * Copyright (c) 2003-2009 Apple 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 #ifdef PRIVATE
29
30 #ifndef _I386_CPU_CAPABILITIES_H
31 #define _I386_CPU_CAPABILITIES_H
32
33 #ifndef __ASSEMBLER__
34 #include <stdint.h>
35 #endif
36
37 /*
38 * This API only supported for Apple internal use.
39 */
40
41 /* Bit definitions for _cpu_capabilities: */
42
43 #define kHasMMX 0x00000001
44 #define kHasSSE 0x00000002
45 #define kHasSSE2 0x00000004
46 #define kHasSSE3 0x00000008
47 #define kCache32 0x00000010 /* cache line size is 32 bytes */
48 #define kCache64 0x00000020
49 #define kCache128 0x00000040
50 #define kFastThreadLocalStorage 0x00000080 /* TLS ptr is kept in a user-mode-readable register */
51 #define kHasSupplementalSSE3 0x00000100
52 #define k64Bit 0x00000200 /* processor supports EM64T (not what mode you're running in) */
53 #define kHasSSE4_1 0x00000400
54 #define kHasSSE4_2 0x00000800
55 #define kHasAES 0x00001000
56 #define kInOrderPipeline 0x00002000
57 #define kSlow 0x00004000 /* tsc < nanosecond */
58 #define kUP 0x00008000 /* set if (kNumCPUs == 1) */
59 #define kNumCPUs 0x00FF0000 /* number of CPUs (see _NumCPUs() below) */
60 #define kHasAVX1_0 0x01000000
61 #define kNumCPUsShift 16 /* see _NumCPUs() below */
62
63 #ifndef __ASSEMBLER__
64 #include <sys/cdefs.h>
65
66 __BEGIN_DECLS
67 extern int _get_cpu_capabilities( void );
68 __END_DECLS
69
70 inline static
71 int _NumCPUs( void )
72 {
73 return (_get_cpu_capabilities() & kNumCPUs) >> kNumCPUsShift;
74 }
75
76 #endif /* __ASSEMBLER__ */
77
78 /* The following macro is used to generate the 64-bit commpage address for a given
79 * routine, based on its 32-bit address. This is used in the kernel to compile
80 * the 64-bit commpage. Since the kernel can be a 32-bit object, cpu_capabilities.h
81 * only defines the 32-bit address.
82 */
83 #define _COMM_PAGE_32_TO_64( ADDRESS ) ( ADDRESS + _COMM_PAGE64_START_ADDRESS - _COMM_PAGE32_START_ADDRESS )
84
85
86 /*
87 * The shared kernel/user "comm page(s)":
88 *
89 * The last several pages of every address space are reserved for the kernel/user
90 * "comm area". During system initialization, the kernel populates the comm pages with
91 * code customized for the particular processor and platform.
92 *
93 * Because Mach VM cannot map the last page of an address space, we don't use it.
94 */
95
96 #define _COMM_PAGE32_AREA_LENGTH ( 2 * 4096 ) /* reserved length of entire comm area */
97 #define _COMM_PAGE32_BASE_ADDRESS ( 0xffff0000 ) /* base address of allocated memory */
98 #define _COMM_PAGE32_START_ADDRESS ( _COMM_PAGE32_BASE_ADDRESS ) /* address traditional commpage code starts on */
99 #define _COMM_PAGE32_AREA_USED ( 2 * 4096 ) /* this is the amt actually allocated */
100 #define _COMM_PAGE32_SIGS_OFFSET 0x8000 /* offset to routine signatures */
101
102 #define _COMM_PAGE64_AREA_LENGTH ( 2 * 1024 * 1024 ) /* reserved length of entire comm area (2MB) */
103 #ifdef __ASSEMBLER__
104 #define _COMM_PAGE64_BASE_ADDRESS ( 0x00007fffffe00000 ) /* base address of allocated memory */
105 #else /* __ASSEMBLER__ */
106 #define _COMM_PAGE64_BASE_ADDRESS ( 0x00007fffffe00000ULL ) /* base address of allocated memory */
107 #endif /* __ASSEMBLER__ */
108 #define _COMM_PAGE64_START_ADDRESS ( _COMM_PAGE64_BASE_ADDRESS ) /* address traditional commpage code starts on */
109 #define _COMM_PAGE64_AREA_USED ( 2 * 4096 ) /* this is the amt actually populated */
110
111 /* no need for an Objective-C area on Intel */
112 #define _COMM_PAGE32_OBJC_SIZE 0ULL
113 #define _COMM_PAGE32_OBJC_BASE 0ULL
114 #define _COMM_PAGE64_OBJC_SIZE 0ULL
115 #define _COMM_PAGE64_OBJC_BASE 0ULL
116
117 #ifdef KERNEL_PRIVATE
118
119 /* Inside the kernel, comm page addresses are absolute addresses
120 * assuming they are a part of the 32-bit commpage. They may
121 * be mapped somewhere else, especially for the 64-bit commpage.
122 */
123 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
124 #define _COMM_PAGE_SIGS_OFFSET _COMM_PAGE32_SIGS_OFFSET
125
126 #else /* !KERNEL_PRIVATE */
127
128 #if defined(__i386__)
129
130 #define _COMM_PAGE_AREA_LENGTH _COMM_PAGE32_AREA_LENGTH
131 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE32_BASE_ADDRESS
132 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
133 #define _COMM_PAGE_AREA_USED _COMM_PAGE32_AREA_USED
134 #define _COMM_PAGE_SIGS_OFFSET _COMM_PAGE32_SIGS_OFFSET
135
136 #elif defined(__x86_64__)
137
138 #define _COMM_PAGE_AREA_LENGTH _COMM_PAGE64_AREA_LENGTH
139 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE64_BASE_ADDRESS
140 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE64_START_ADDRESS
141 #define _COMM_PAGE_AREA_USED _COMM_PAGE64_AREA_USED
142
143 #else
144 #error architecture not supported
145 #endif
146
147 #endif /* !KERNEL_PRIVATE */
148
149 /* data in the comm page */
150
151 #define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) /* first few bytes are a signature */
152 #define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) /* 16-bit version# */
153 #define _COMM_PAGE_THIS_VERSION 12 /* version of the commarea format */
154
155 #define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) /* uint32_t _cpu_capabilities */
156 #define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) /* uint8_t number of configured CPUs (hw.logicalcpu at boot time) */
157 #define _COMM_PAGE_UNUSED0 (_COMM_PAGE_START_ADDRESS+0x024) /* 2 unused bytes, reserved for future expansion of cpu_capabilities */
158 #define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) /* uint16_t cache line size */
159
160 #define _COMM_PAGE_SCHED_GEN (_COMM_PAGE_START_ADDRESS+0x028) /* uint32_t scheduler generation number (count of pre-emptions) */
161 #define _COMM_PAGE_MEMORY_PRESSURE (_COMM_PAGE_START_ADDRESS+0x02c) /* uint32_t copy of vm_memory_pressure */
162 #define _COMM_PAGE_SPIN_COUNT (_COMM_PAGE_START_ADDRESS+0x030) /* uint32_t max spin count for mutex's */
163
164 #define _COMM_PAGE_ACTIVE_CPUS (_COMM_PAGE_START_ADDRESS+0x034) /* uint8_t number of active CPUs (hw.activecpu) */
165 #define _COMM_PAGE_PHYSICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x035) /* uint8_t number of physical CPUs (hw.physicalcpu_max) */
166 #define _COMM_PAGE_LOGICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x036) /* uint8_t number of logical CPUs (hw.logicalcpu_max) */
167 #define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x037) /* 1 unused bytes */
168 #define _COMM_PAGE_MEMORY_SIZE (_COMM_PAGE_START_ADDRESS+0x038) /* uint64_t max memory size */
169
170 #define _COMM_PAGE_CPUFAMILY (_COMM_PAGE_START_ADDRESS+0x040) /* uint32_t hw.cpufamily, x86*/
171 #define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x044) /* [0x44,0x50) unused */
172
173 #define _COMM_PAGE_TIME_DATA_START (_COMM_PAGE_START_ADDRESS+0x050) /* base of offsets below (_NT_SCALE etc) */
174 #define _COMM_PAGE_NT_TSC_BASE (_COMM_PAGE_START_ADDRESS+0x050) /* used by nanotime() */
175 #define _COMM_PAGE_NT_SCALE (_COMM_PAGE_START_ADDRESS+0x058) /* used by nanotime() */
176 #define _COMM_PAGE_NT_SHIFT (_COMM_PAGE_START_ADDRESS+0x05c) /* used by nanotime() */
177 #define _COMM_PAGE_NT_NS_BASE (_COMM_PAGE_START_ADDRESS+0x060) /* used by nanotime() */
178 #define _COMM_PAGE_NT_GENERATION (_COMM_PAGE_START_ADDRESS+0x068) /* used by nanotime() */
179 #define _COMM_PAGE_GTOD_GENERATION (_COMM_PAGE_START_ADDRESS+0x06c) /* used by gettimeofday() */
180 #define _COMM_PAGE_GTOD_NS_BASE (_COMM_PAGE_START_ADDRESS+0x070) /* used by gettimeofday() */
181 #define _COMM_PAGE_GTOD_SEC_BASE (_COMM_PAGE_START_ADDRESS+0x078) /* used by gettimeofday() */
182
183 /* Warning: kernel commpage.h has a matching c typedef for the following. They must be kept in sync. */
184 /* These offsets are from _COMM_PAGE_TIME_DATA_START */
185
186 #define _NT_TSC_BASE 0
187 #define _NT_SCALE 8
188 #define _NT_SHIFT 12
189 #define _NT_NS_BASE 16
190 #define _NT_GENERATION 24
191 #define _GTOD_GENERATION 28
192 #define _GTOD_NS_BASE 32
193 #define _GTOD_SEC_BASE 40
194
195 /* jump table (jmp to this address, which may be a branch to the actual code somewhere else) */
196 /* When new jump table entries are added, corresponding symbols should be added below */
197 /* New slots should be allocated with at least 16-byte alignment. Some like bcopy require */
198 /* 32-byte alignment, and should be aligned as such in the assembly source before they are relocated */
199 #define _COMM_PAGE_TEXT_START (_COMM_PAGE_START_ADDRESS+0x080) /* start of text section */
200
201 #define _COMM_PAGE_PREEMPT (_COMM_PAGE_START_ADDRESS+0x5a0) /* used by PFZ code */
202 #define _COMM_PAGE_BACKOFF (_COMM_PAGE_START_ADDRESS+0x1600) /* called from PFZ */
203
204 #define _COMM_PAGE_PFZ_START (_COMM_PAGE_START_ADDRESS+0x1c00) /* start of Preemption Free Zone */
205
206 #define _COMM_PAGE_PFZ_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x1c00) /* internal routine for FIFO enqueue */
207 #define _COMM_PAGE_PFZ_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x1c80) /* internal routine for FIFO dequeue */
208 #define _COMM_PAGE_PFZ_MUTEX_LOCK (_COMM_PAGE_START_ADDRESS+0x1d00) /* internal routine for pthread_mutex_lock() */
209
210 #define _COMM_PAGE_UNUSED6 (_COMM_PAGE_START_ADDRESS+0x1d80) /* unused space for PFZ code up to 0x1fff */
211
212 #define _COMM_PAGE_PFZ_END (_COMM_PAGE_START_ADDRESS+0x1fff) /* end of Preemption Free Zone */
213
214 #define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0x1fff) /* end of common page - insert new stuff here */
215
216 /* _COMM_PAGE_COMPARE_AND_SWAP{32,64}B are not used on x86 and are
217 * maintained here for source compatability. These will be removed at
218 * some point, so don't go relying on them. */
219 #define _COMM_PAGE_COMPARE_AND_SWAP32B (_COMM_PAGE_START_ADDRESS+0xf80) /* compare-and-swap word w barrier */
220 #define _COMM_PAGE_COMPARE_AND_SWAP64B (_COMM_PAGE_START_ADDRESS+0xfc0) /* compare-and-swap doubleword w barrier */
221
222 #ifdef __ASSEMBLER__
223 #ifdef __COMM_PAGE_SYMBOLS
224
225 #define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
226 .org (symbol_address - (_COMM_PAGE_START_ADDRESS & 0xFFFFE000)) ;\
227 symbol_name: nop
228
229 .text /* Required to make a well behaved symbol file */
230
231 CREATE_COMM_PAGE_SYMBOL(___preempt, _COMM_PAGE_PREEMPT)
232 CREATE_COMM_PAGE_SYMBOL(___backoff, _COMM_PAGE_BACKOFF)
233 CREATE_COMM_PAGE_SYMBOL(___pfz_enqueue, _COMM_PAGE_PFZ_ENQUEUE)
234 CREATE_COMM_PAGE_SYMBOL(___pfz_dequeue, _COMM_PAGE_PFZ_DEQUEUE)
235 CREATE_COMM_PAGE_SYMBOL(___pfz_mutex_lock, _COMM_PAGE_PFZ_MUTEX_LOCK)
236 CREATE_COMM_PAGE_SYMBOL(___end_comm_page, _COMM_PAGE_END)
237
238 .data /* Required to make a well behaved symbol file */
239 .long 0 /* Required to make a well behaved symbol file */
240
241 #endif /* __COMM_PAGE_SYMBOLS */
242 #endif /* __ASSEMBLER__ */
243
244 #endif /* _I386_CPU_CAPABILITIES_H */
245 #endif /* PRIVATE */