]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu_capabilities.h
470e8a3e73cdbb347f21c606f32d0ecb03989144
[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 /* in-order execution */
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
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
79 /*
80 * The shared kernel/user "comm page(s)":
81 *
82 * The last several pages of every address space are reserved for the kernel/user
83 * "comm area". During system initialization, the kernel populates the comm pages with
84 * code customized for the particular processor and platform.
85 *
86 * Because Mach VM cannot map the last page of an address space, we don't use it.
87 */
88
89 #define _COMM_PAGE32_AREA_LENGTH ( 19 * 4096 ) /* reserved length of entire comm area */
90 #define _COMM_PAGE32_BASE_ADDRESS ( 0xfffec000 ) /* base address of allocated memory, -20 pages */
91 #define _COMM_PAGE32_START_ADDRESS ( 0xffff0000 ) /* address traditional commpage code starts on, -16 pages */
92 #define _COMM_PAGE32_AREA_USED ( 19 * 4096 ) /* this is the amt actually allocated */
93 #define _COMM_PAGE32_SIGS_OFFSET 0x8000 /* offset to routine signatures */
94
95 #define _COMM_PAGE64_AREA_LENGTH ( 2 * 1024 * 1024 ) /* reserved length of entire comm area (2MB) */
96 #define _COMM_PAGE64_BASE_ADDRESS ( 0x00007fffffe00000ULL ) /* base address of allocated memory */
97 #define _COMM_PAGE64_START_ADDRESS ( _COMM_PAGE64_BASE_ADDRESS ) /* address traditional commpage code starts on */
98 #define _COMM_PAGE64_AREA_USED ( 2 * 4096 ) /* this is the amt actually populated */
99
100 /* no need for an Objective-C area on Intel */
101 #define _COMM_PAGE32_OBJC_SIZE 0ULL
102 #define _COMM_PAGE32_OBJC_BASE 0ULL
103 #define _COMM_PAGE64_OBJC_SIZE 0ULL
104 #define _COMM_PAGE64_OBJC_BASE 0ULL
105
106 #ifdef KERNEL_PRIVATE
107
108 /* Inside the kernel, comm page addresses are absolute addresses
109 * assuming they are a part of the 32-bit commpage. They may
110 * be mapped somewhere else, especially for the 64-bit commpage.
111 */
112 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
113 #define _COMM_PAGE_SIGS_OFFSET _COMM_PAGE32_SIGS_OFFSET
114
115 #else /* !KERNEL_PRIVATE */
116
117 #if defined(__i386__)
118
119 #define _COMM_PAGE_AREA_LENGTH _COMM_PAGE32_AREA_LENGTH
120 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE32_BASE_ADDRESS
121 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
122 #define _COMM_PAGE_AREA_USED _COMM_PAGE32_AREA_USED
123 #define _COMM_PAGE_SIGS_OFFSET _COMM_PAGE32_SIGS_OFFSET
124
125 #elif defined(__x86_64__)
126
127 #define _COMM_PAGE_AREA_LENGTH _COMM_PAGE64_AREA_LENGTH
128 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE64_BASE_ADDRESS
129 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE64_START_ADDRESS
130 #define _COMM_PAGE_AREA_USED _COMM_PAGE64_AREA_USED
131
132 #else
133 #error architecture not supported
134 #endif
135
136 #endif /* !KERNEL_PRIVATE */
137
138 /* data in the comm page */
139
140 #define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) /* first few bytes are a signature */
141 #define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) /* 16-bit version# */
142 #define _COMM_PAGE_THIS_VERSION 11 /* version of the commarea format */
143
144 #define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) /* uint32_t _cpu_capabilities */
145 #define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) /* uint8_t number of configured CPUs */
146 #define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) /* uint16_t cache line size */
147
148 #define _COMM_PAGE_SCHED_GEN (_COMM_PAGE_START_ADDRESS+0x028) /* uint32_t scheduler generation number (count of pre-emptions) */
149 #define _COMM_PAGE_MEMORY_PRESSURE (_COMM_PAGE_START_ADDRESS+0x02c) /* uint32_t copy of vm_memory_pressure */
150 #define _COMM_PAGE_SPIN_COUNT (_COMM_PAGE_START_ADDRESS+0x030) /* uint32_t max spin count for mutex's */
151
152 #define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x034) /* 12 unused bytes */
153
154 #ifdef KERNEL_PRIVATE
155
156 /* slots defined in all cases, but commpage setup code must not populate for 64-bit commpage */
157 #define _COMM_PAGE_2_TO_52 (_COMM_PAGE_START_ADDRESS+0x040) /* double float constant 2**52 */
158 #define _COMM_PAGE_10_TO_6 (_COMM_PAGE_START_ADDRESS+0x048) /* double float constant 10**6 */
159
160 #else /* !KERNEL_PRIVATE */
161
162 #if defined(__i386__) /* following are not defined in 64-bit */
163 #define _COMM_PAGE_2_TO_52 (_COMM_PAGE_START_ADDRESS+0x040) /* double float constant 2**52 */
164 #define _COMM_PAGE_10_TO_6 (_COMM_PAGE_START_ADDRESS+0x048) /* double float constant 10**6 */
165 #else
166 #define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x040) /* 16 unused bytes */
167 #endif
168
169 #endif /* !KERNEL_PRIVATE */
170
171 #define _COMM_PAGE_TIME_DATA_START (_COMM_PAGE_START_ADDRESS+0x050) /* base of offsets below (_NT_SCALE etc) */
172 #define _COMM_PAGE_NT_TSC_BASE (_COMM_PAGE_START_ADDRESS+0x050) /* used by nanotime() */
173 #define _COMM_PAGE_NT_SCALE (_COMM_PAGE_START_ADDRESS+0x058) /* used by nanotime() */
174 #define _COMM_PAGE_NT_SHIFT (_COMM_PAGE_START_ADDRESS+0x05c) /* used by nanotime() */
175 #define _COMM_PAGE_NT_NS_BASE (_COMM_PAGE_START_ADDRESS+0x060) /* used by nanotime() */
176 #define _COMM_PAGE_NT_GENERATION (_COMM_PAGE_START_ADDRESS+0x068) /* used by nanotime() */
177 #define _COMM_PAGE_GTOD_GENERATION (_COMM_PAGE_START_ADDRESS+0x06c) /* used by gettimeofday() */
178 #define _COMM_PAGE_GTOD_NS_BASE (_COMM_PAGE_START_ADDRESS+0x070) /* used by gettimeofday() */
179 #define _COMM_PAGE_GTOD_SEC_BASE (_COMM_PAGE_START_ADDRESS+0x078) /* used by gettimeofday() */
180
181 /* Warning: kernel commpage.h has a matching c typedef for the following. They must be kept in sync. */
182 /* These offsets are from _COMM_PAGE_TIME_DATA_START */
183
184 #define _NT_TSC_BASE 0
185 #define _NT_SCALE 8
186 #define _NT_SHIFT 12
187 #define _NT_NS_BASE 16
188 #define _NT_GENERATION 24
189 #define _GTOD_GENERATION 28
190 #define _GTOD_NS_BASE 32
191 #define _GTOD_SEC_BASE 40
192
193 /* jump table (jmp to this address, which may be a branch to the actual code somewhere else) */
194 /* When new jump table entries are added, corresponding symbols should be added below */
195 /* New slots should be allocated with at least 16-byte alignment. Some like bcopy require */
196 /* 32-byte alignment, and should be aligned as such in the assembly source before they are relocated */
197 #define _COMM_PAGE_COMPARE_AND_SWAP32 (_COMM_PAGE_START_ADDRESS+0x080) /* compare-and-swap word */
198 #define _COMM_PAGE_COMPARE_AND_SWAP64 (_COMM_PAGE_START_ADDRESS+0x0c0) /* compare-and-swap doubleword */
199 #define _COMM_PAGE_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x100) /* enqueue */
200 #define _COMM_PAGE_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x140) /* dequeue */
201 #define _COMM_PAGE_MEMORY_BARRIER (_COMM_PAGE_START_ADDRESS+0x180) /* memory barrier */
202 #define _COMM_PAGE_ATOMIC_ADD32 (_COMM_PAGE_START_ADDRESS+0x1a0) /* add atomic word */
203 #define _COMM_PAGE_ATOMIC_ADD64 (_COMM_PAGE_START_ADDRESS+0x1c0) /* add atomic doubleword */
204
205 #define _COMM_PAGE_CPU_NUMBER (_COMM_PAGE_START_ADDRESS+0x1e0) /* user-level cpu_number() */
206
207 #define _COMM_PAGE_ABSOLUTE_TIME (_COMM_PAGE_START_ADDRESS+0x200) /* mach_absolute_time() */
208 #define _COMM_PAGE_SPINLOCK_TRY (_COMM_PAGE_START_ADDRESS+0x220) /* spinlock_try() */
209 #define _COMM_PAGE_SPINLOCK_LOCK (_COMM_PAGE_START_ADDRESS+0x260) /* spinlock_lock() */
210 #define _COMM_PAGE_SPINLOCK_UNLOCK (_COMM_PAGE_START_ADDRESS+0x2a0) /* spinlock_unlock() */
211 #define _COMM_PAGE_PTHREAD_GETSPECIFIC (_COMM_PAGE_START_ADDRESS+0x2c0) /* pthread_getspecific() */
212 #define _COMM_PAGE_GETTIMEOFDAY (_COMM_PAGE_START_ADDRESS+0x2e0) /* used by gettimeofday() */
213 #define _COMM_PAGE_FLUSH_DCACHE (_COMM_PAGE_START_ADDRESS+0x4e0) /* sys_dcache_flush() */
214 #define _COMM_PAGE_FLUSH_ICACHE (_COMM_PAGE_START_ADDRESS+0x520) /* sys_icache_invalidate() */
215 #define _COMM_PAGE_PTHREAD_SELF (_COMM_PAGE_START_ADDRESS+0x580) /* pthread_self() */
216
217 #define _COMM_PAGE_PREEMPT (_COMM_PAGE_START_ADDRESS+0x5a0) /* used by PFZ code */
218
219 #define _COMM_PAGE_RELINQUISH (_COMM_PAGE_START_ADDRESS+0x5c0) /* used by spinlocks */
220 #define _COMM_PAGE_BTS (_COMM_PAGE_START_ADDRESS+0x5e0) /* bit test-and-set */
221 #define _COMM_PAGE_BTC (_COMM_PAGE_START_ADDRESS+0x5f0) /* bit test-and-clear */
222
223 #define _COMM_PAGE_BZERO (_COMM_PAGE_START_ADDRESS+0x600) /* bzero() */
224 #define _COMM_PAGE_BCOPY (_COMM_PAGE_START_ADDRESS+0x780) /* bcopy() */
225 #define _COMM_PAGE_MEMCPY (_COMM_PAGE_START_ADDRESS+0x7a0) /* memcpy() */
226 #define _COMM_PAGE_MEMMOVE (_COMM_PAGE_START_ADDRESS+0x7a0) /* memmove() */
227 #define _COMM_PAGE_BCOPY_END (_COMM_PAGE_START_ADDRESS+0xfff) /* used by rosetta */
228
229 #define _COMM_PAGE_MEMSET_PATTERN (_COMM_PAGE_START_ADDRESS+0x1000) /* used by nonzero memset() */
230 #define _COMM_PAGE_LONGCOPY (_COMM_PAGE_START_ADDRESS+0x1200) /* used by bcopy() for very long operands */
231 #define _COMM_PAGE_LONGCOPY_END (_COMM_PAGE_START_ADDRESS+0x15ff) /* used by rosetta */
232
233 #define _COMM_PAGE_BACKOFF (_COMM_PAGE_START_ADDRESS+0x1600) /* called from PFZ */
234 #define _COMM_PAGE_FIFO_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x1680) /* FIFO enqueue */
235 #define _COMM_PAGE_FIFO_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x16c0) /* FIFO dequeue */
236 #define _COMM_PAGE_NANOTIME (_COMM_PAGE_START_ADDRESS+0x1700) /* nanotime() */
237 #define _COMM_PAGE_MUTEX_LOCK (_COMM_PAGE_START_ADDRESS+0x1780) /* pthread_mutex_lock() */
238
239 #define _COMM_PAGE_UNUSED5 (_COMM_PAGE_START_ADDRESS+0x17e0) /* unused space for regular code up to 0x1c00 */
240
241 #define _COMM_PAGE_PFZ_START (_COMM_PAGE_START_ADDRESS+0x1c00) /* start of Preemption Free Zone */
242
243 #define _COMM_PAGE_PFZ_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x1c00) /* internal routine for FIFO enqueue */
244 #define _COMM_PAGE_PFZ_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x1c80) /* internal routine for FIFO dequeue */
245 #define _COMM_PAGE_PFZ_MUTEX_LOCK (_COMM_PAGE_START_ADDRESS+0x1d00) /* internal routine for pthread_mutex_lock() */
246
247 #define _COMM_PAGE_UNUSED6 (_COMM_PAGE_START_ADDRESS+0x1d80) /* unused space for PFZ code up to 0x1fff */
248
249 #define _COMM_PAGE_PFZ_END (_COMM_PAGE_START_ADDRESS+0x1fff) /* end of Preemption Free Zone */
250
251 #define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0x1fff) /* end of common page - insert new stuff here */
252
253 /* _COMM_PAGE_COMPARE_AND_SWAP{32,64}B are not used on x86 and are
254 * maintained here for source compatability. These will be removed at
255 * some point, so don't go relying on them. */
256 #define _COMM_PAGE_COMPARE_AND_SWAP32B (_COMM_PAGE_START_ADDRESS+0xf80) /* compare-and-swap word w barrier */
257 #define _COMM_PAGE_COMPARE_AND_SWAP64B (_COMM_PAGE_START_ADDRESS+0xfc0) /* compare-and-swap doubleword w barrier */
258
259 #ifdef __ASSEMBLER__
260 #ifdef __COMM_PAGE_SYMBOLS
261
262 #define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
263 .org (symbol_address - (_COMM_PAGE_START_ADDRESS & 0xFFFFE000)) ;\
264 symbol_name: nop
265
266 .text /* Required to make a well behaved symbol file */
267
268 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap32, _COMM_PAGE_COMPARE_AND_SWAP32)
269 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap64, _COMM_PAGE_COMPARE_AND_SWAP64)
270 CREATE_COMM_PAGE_SYMBOL(___atomic_enqueue, _COMM_PAGE_ENQUEUE)
271 CREATE_COMM_PAGE_SYMBOL(___atomic_dequeue, _COMM_PAGE_DEQUEUE)
272 CREATE_COMM_PAGE_SYMBOL(___memory_barrier, _COMM_PAGE_MEMORY_BARRIER)
273 CREATE_COMM_PAGE_SYMBOL(___atomic_add32, _COMM_PAGE_ATOMIC_ADD32)
274 CREATE_COMM_PAGE_SYMBOL(___atomic_add64, _COMM_PAGE_ATOMIC_ADD64)
275 CREATE_COMM_PAGE_SYMBOL(___cpu_number, _COMM_PAGE_CPU_NUMBER)
276 CREATE_COMM_PAGE_SYMBOL(___mach_absolute_time, _COMM_PAGE_ABSOLUTE_TIME)
277 CREATE_COMM_PAGE_SYMBOL(___spin_lock_try, _COMM_PAGE_SPINLOCK_TRY)
278 CREATE_COMM_PAGE_SYMBOL(___spin_lock, _COMM_PAGE_SPINLOCK_LOCK)
279 CREATE_COMM_PAGE_SYMBOL(___spin_unlock, _COMM_PAGE_SPINLOCK_UNLOCK)
280 CREATE_COMM_PAGE_SYMBOL(___pthread_getspecific, _COMM_PAGE_PTHREAD_GETSPECIFIC)
281 CREATE_COMM_PAGE_SYMBOL(___gettimeofday, _COMM_PAGE_GETTIMEOFDAY)
282 CREATE_COMM_PAGE_SYMBOL(___sys_dcache_flush, _COMM_PAGE_FLUSH_DCACHE)
283 CREATE_COMM_PAGE_SYMBOL(___sys_icache_invalidate, _COMM_PAGE_FLUSH_ICACHE)
284 CREATE_COMM_PAGE_SYMBOL(___pthread_self, _COMM_PAGE_PTHREAD_SELF)
285 CREATE_COMM_PAGE_SYMBOL(___pfz_preempt, _COMM_PAGE_PREEMPT)
286 CREATE_COMM_PAGE_SYMBOL(___spin_lock_relinquish, _COMM_PAGE_RELINQUISH)
287 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_set, _COMM_PAGE_BTS)
288 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_clear, _COMM_PAGE_BTC)
289 CREATE_COMM_PAGE_SYMBOL(___bzero, _COMM_PAGE_BZERO)
290 CREATE_COMM_PAGE_SYMBOL(___bcopy, _COMM_PAGE_BCOPY)
291 CREATE_COMM_PAGE_SYMBOL(___memcpy, _COMM_PAGE_MEMCPY)
292 /* CREATE_COMM_PAGE_SYMBOL(___memmove, _COMM_PAGE_MEMMOVE) */
293 CREATE_COMM_PAGE_SYMBOL(___memset_pattern, _COMM_PAGE_MEMSET_PATTERN)
294 CREATE_COMM_PAGE_SYMBOL(___longcopy, _COMM_PAGE_LONGCOPY)
295 CREATE_COMM_PAGE_SYMBOL(___backoff, _COMM_PAGE_BACKOFF)
296 CREATE_COMM_PAGE_SYMBOL(___fifo_enqueue, _COMM_PAGE_FIFO_ENQUEUE)
297 CREATE_COMM_PAGE_SYMBOL(___fifo_dequeue, _COMM_PAGE_FIFO_DEQUEUE)
298 CREATE_COMM_PAGE_SYMBOL(___nanotime, _COMM_PAGE_NANOTIME)
299 CREATE_COMM_PAGE_SYMBOL(___mutex_lock, _COMM_PAGE_MUTEX_LOCK)
300 CREATE_COMM_PAGE_SYMBOL(___pfz_enqueue, _COMM_PAGE_PFZ_ENQUEUE)
301 CREATE_COMM_PAGE_SYMBOL(___pfz_dequeue, _COMM_PAGE_PFZ_DEQUEUE)
302 CREATE_COMM_PAGE_SYMBOL(___pfz_mutex_lock, _COMM_PAGE_PFZ_MUTEX_LOCK)
303 CREATE_COMM_PAGE_SYMBOL(___end_comm_page, _COMM_PAGE_END)
304
305 .data /* Required to make a well behaved symbol file */
306 .long 0 /* Required to make a well behaved symbol file */
307
308 #endif /* __COMM_PAGE_SYMBOLS */
309 #endif /* __ASSEMBLER__ */
310
311 #endif /* _I386_CPU_CAPABILITIES_H */
312 #endif /* PRIVATE */