]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/cpu_capabilities.h
xnu-1228.3.13.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_capabilities.h
CommitLineData
43866e37 1/*
2d21ac55 2 * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
43866e37 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
43866e37 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
43866e37 27 */
91447636 28#ifdef PRIVATE
43866e37
A
29
30#ifndef _I386_CPU_CAPABILITIES_H
31#define _I386_CPU_CAPABILITIES_H
32
91447636
A
33#ifndef __ASSEMBLER__
34#include <stdint.h>
35#endif
55e303ae 36
55e303ae 37/*
43866e37 38 * This API only supported for Apple internal use.
43866e37
A
39 */
40
55e303ae
A
41/* Bit definitions for _cpu_capabilities: */
42
43#define kHasMMX 0x00000001
44#define kHasSSE 0x00000002
45#define kHasSSE2 0x00000004
91447636 46#define kHasSSE3 0x00000008
0c530ab8 47#define kCache32 0x00000010 /* cache line size is 32 bytes */
55e303ae
A
48#define kCache64 0x00000020
49#define kCache128 0x00000040
0c530ab8 50#define kFastThreadLocalStorage 0x00000080 /* TLS ptr is kept in a user-mode-readable register */
2d21ac55 51#define kHasSupplementalSSE3 0x00000100
0c530ab8 52#define k64Bit 0x00000200 /* processor supports EM64T (not what mode you're running in) */
2d21ac55
A
53#define kHasSSE4_1 0x00000400
54#define kHasSSE4_2 0x00000800
55e303ae 55
2d21ac55 56#define kSlow 0x00004000 /* tsc < nanosecond */
0c530ab8
A
57#define kUP 0x00008000 /* set if (kNumCPUs == 1) */
58#define kNumCPUs 0x00FF0000 /* number of CPUs (see _NumCPUs() below) */
55e303ae 59
0c530ab8 60#define kNumCPUsShift 16 /* see _NumCPUs() below */
55e303ae 61
43866e37 62#ifndef __ASSEMBLER__
91447636
A
63#include <sys/cdefs.h>
64
65__BEGIN_DECLS
66extern int _get_cpu_capabilities( void );
67__END_DECLS
55e303ae
A
68
69inline static
70int _NumCPUs( void )
71{
72 return (_get_cpu_capabilities() & kNumCPUs) >> kNumCPUsShift;
73}
74
75#endif /* __ASSEMBLER__ */
76
77
78/*
79 * The shared kernel/user "comm page(s)":
80 *
0c530ab8
A
81 * The last several pages of every address space are reserved for the kernel/user
82 * "comm area". During system initialization, the kernel populates the comm pages with
55e303ae
A
83 * code customized for the particular processor and platform.
84 *
0c530ab8 85 * Because Mach VM cannot map the last page of an address space, we don't use it.
55e303ae
A
86 */
87
0c530ab8
A
88#define _COMM_PAGE32_AREA_LENGTH ( 19 * 4096 ) /* reserved length of entire comm area */
89#define _COMM_PAGE32_BASE_ADDRESS ( -20 * 4096 ) /* base address of allocated memory */
90#define _COMM_PAGE32_START_ADDRESS ( -16 * 4096 ) /* address traditional commpage code starts on */
91#define _COMM_PAGE32_AREA_USED ( 19 * 4096 ) /* this is the amt actually allocated */
92
93#define _COMM_PAGE64_AREA_LENGTH ( 2 * 1024 * 1024 ) /* reserved length of entire comm area (2MB) */
94#define _COMM_PAGE64_BASE_ADDRESS ( 0x00007fffffe00000ULL ) /* base address of allocated memory */
95#define _COMM_PAGE64_START_ADDRESS ( _COMM_PAGE64_BASE_ADDRESS ) /* address traditional commpage code starts on */
96#define _COMM_PAGE64_AREA_USED ( 2 * 4096 ) /* this is the amt actually populated */
97
2d21ac55
A
98/* no need for an Objective-C area on Intel */
99#define _COMM_PAGE32_OBJC_SIZE 0ULL
100#define _COMM_PAGE32_OBJC_BASE 0ULL
101#define _COMM_PAGE64_OBJC_SIZE 0ULL
102#define _COMM_PAGE64_OBJC_BASE 0ULL
0c530ab8
A
103
104#if defined(__i386__)
105
106#define _COMM_PAGE_AREA_LENGTH _COMM_PAGE32_AREA_LENGTH
107#define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE32_BASE_ADDRESS
108#define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
109#define _COMM_PAGE_AREA_USED _COMM_PAGE32_AREA_USED
110#define _COMM_PAGE_SIGS_OFFSET 0x8000 /* offset to routine signatures */
111
112#elif defined(__x86_64__)
113
114#define _COMM_PAGE_AREA_LENGTH _COMM_PAGE64_AREA_LENGTH
115#define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE64_BASE_ADDRESS
116#define _COMM_PAGE_START_ADDRESS _COMM_PAGE64_START_ADDRESS
117#define _COMM_PAGE_AREA_USED _COMM_PAGE64_AREA_USED
118
119#else
120#error architecture not supported
121#endif
55e303ae
A
122
123/* data in the comm page */
43866e37 124
0c530ab8
A
125#define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) /* first few bytes are a signature */
126#define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) /* 16-bit version# */
2d21ac55 127#define _COMM_PAGE_THIS_VERSION 7 /* version of the commarea format */
55e303ae 128
0c530ab8
A
129#define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) /* uint32_t _cpu_capabilities */
130#define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) /* uint8_t number of configured CPUs */
131#define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) /* uint16_t cache line size */
132
2d21ac55
A
133#define _COMM_PAGE_SCHED_GEN (_COMM_PAGE_START_ADDRESS+0x028) /* uint32_t scheduler generation number (count of pre-emptions) */
134
135#define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x02c) /* 20 unused bytes */
8f6c56a5 136
0c530ab8
A
137#if defined(__i386__) /* following are not defined in 64-bit */
138#define _COMM_PAGE_2_TO_52 (_COMM_PAGE_START_ADDRESS+0x040) /* double float constant 2**52 */
139#define _COMM_PAGE_10_TO_6 (_COMM_PAGE_START_ADDRESS+0x048) /* double float constant 10**6 */
140#else
141#define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x040) /* 16 unused bytes */
142#endif
143
2d21ac55 144#define _COMM_PAGE_TIME_DATA_START (_COMM_PAGE_START_ADDRESS+0x050) /* base of offsets below (_NT_SCALE etc) */
0c530ab8
A
145#define _COMM_PAGE_NT_TSC_BASE (_COMM_PAGE_START_ADDRESS+0x050) /* used by nanotime() */
146#define _COMM_PAGE_NT_SCALE (_COMM_PAGE_START_ADDRESS+0x058) /* used by nanotime() */
147#define _COMM_PAGE_NT_SHIFT (_COMM_PAGE_START_ADDRESS+0x05c) /* used by nanotime() */
148#define _COMM_PAGE_NT_NS_BASE (_COMM_PAGE_START_ADDRESS+0x060) /* used by nanotime() */
2d21ac55
A
149#define _COMM_PAGE_NT_GENERATION (_COMM_PAGE_START_ADDRESS+0x068) /* used by nanotime() */
150#define _COMM_PAGE_GTOD_GENERATION (_COMM_PAGE_START_ADDRESS+0x06c) /* used by gettimeofday() */
151#define _COMM_PAGE_GTOD_NS_BASE (_COMM_PAGE_START_ADDRESS+0x070) /* used by gettimeofday() */
152#define _COMM_PAGE_GTOD_SEC_BASE (_COMM_PAGE_START_ADDRESS+0x078) /* used by gettimeofday() */
153
154/* Warning: kernel commpage.h has a matching c typedef for the following. They must be kept in sync. */
155/* These offsets are from _COMM_PAGE_TIME_DATA_START */
0c530ab8 156
2d21ac55 157#define _NT_TSC_BASE 0
0c530ab8
A
158#define _NT_SCALE 8
159#define _NT_SHIFT 12
160#define _NT_NS_BASE 16
2d21ac55
A
161#define _NT_GENERATION 24
162#define _GTOD_GENERATION 28
163#define _GTOD_NS_BASE 32
164#define _GTOD_SEC_BASE 40
6601e61a 165
0c530ab8 166 /* jump table (jmp to this address, which may be a branch to the actual code somewhere else) */
6601e61a 167 /* When new jump table entries are added, corresponding symbols should be added below */
4452a7af 168
0c530ab8
A
169#define _COMM_PAGE_COMPARE_AND_SWAP32 (_COMM_PAGE_START_ADDRESS+0x080) /* compare-and-swap word */
170#define _COMM_PAGE_COMPARE_AND_SWAP64 (_COMM_PAGE_START_ADDRESS+0x0c0) /* compare-and-swap doubleword */
171#define _COMM_PAGE_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x100) /* enqueue */
172#define _COMM_PAGE_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x140) /* dequeue */
173#define _COMM_PAGE_MEMORY_BARRIER (_COMM_PAGE_START_ADDRESS+0x180) /* memory barrier */
174#define _COMM_PAGE_ATOMIC_ADD32 (_COMM_PAGE_START_ADDRESS+0x1a0) /* add atomic word */
175#define _COMM_PAGE_ATOMIC_ADD64 (_COMM_PAGE_START_ADDRESS+0x1c0) /* add atomic doubleword */
176
2d21ac55 177#define _COMM_PAGE_UNUSED4 (_COMM_PAGE_START_ADDRESS+0x1e0) /* 32 unused bytes */
0c530ab8
A
178
179#define _COMM_PAGE_ABSOLUTE_TIME (_COMM_PAGE_START_ADDRESS+0x200) /* mach_absolute_time() */
180#define _COMM_PAGE_SPINLOCK_TRY (_COMM_PAGE_START_ADDRESS+0x220) /* spinlock_try() */
181#define _COMM_PAGE_SPINLOCK_LOCK (_COMM_PAGE_START_ADDRESS+0x260) /* spinlock_lock() */
182#define _COMM_PAGE_SPINLOCK_UNLOCK (_COMM_PAGE_START_ADDRESS+0x2a0) /* spinlock_unlock() */
183#define _COMM_PAGE_PTHREAD_GETSPECIFIC (_COMM_PAGE_START_ADDRESS+0x2c0) /* pthread_getspecific() */
184#define _COMM_PAGE_GETTIMEOFDAY (_COMM_PAGE_START_ADDRESS+0x2e0) /* used by gettimeofday() */
185#define _COMM_PAGE_FLUSH_DCACHE (_COMM_PAGE_START_ADDRESS+0x4e0) /* sys_dcache_flush() */
186#define _COMM_PAGE_FLUSH_ICACHE (_COMM_PAGE_START_ADDRESS+0x520) /* sys_icache_invalidate() */
187#define _COMM_PAGE_PTHREAD_SELF (_COMM_PAGE_START_ADDRESS+0x580) /* pthread_self() */
188
2d21ac55 189#define _COMM_PAGE_UNUSED5 (_COMM_PAGE_START_ADDRESS+0x5a0) /* 32 unused bytes */
0c530ab8
A
190
191#define _COMM_PAGE_RELINQUISH (_COMM_PAGE_START_ADDRESS+0x5c0) /* used by spinlocks */
192#define _COMM_PAGE_BTS (_COMM_PAGE_START_ADDRESS+0x5e0) /* bit test-and-set */
193#define _COMM_PAGE_BTC (_COMM_PAGE_START_ADDRESS+0x5f0) /* bit test-and-clear */
6601e61a 194
0c530ab8
A
195#define _COMM_PAGE_BZERO (_COMM_PAGE_START_ADDRESS+0x600) /* bzero() */
196#define _COMM_PAGE_BCOPY (_COMM_PAGE_START_ADDRESS+0x780) /* bcopy() */
197#define _COMM_PAGE_MEMCPY (_COMM_PAGE_START_ADDRESS+0x7a0) /* memcpy() */
198#define _COMM_PAGE_MEMMOVE (_COMM_PAGE_START_ADDRESS+0x7a0) /* memmove() */
2d21ac55 199#define _COMM_PAGE_BCOPY_END (_COMM_PAGE_START_ADDRESS+0xfff) /* used by rosetta */
0c530ab8 200
0c530ab8
A
201#define _COMM_PAGE_MEMSET_PATTERN (_COMM_PAGE_START_ADDRESS+0x1000) /* used by nonzero memset() */
202#define _COMM_PAGE_LONGCOPY (_COMM_PAGE_START_ADDRESS+0x1200) /* used by bcopy() for very long operands */
2d21ac55 203#define _COMM_PAGE_LONGCOPY_END (_COMM_PAGE_START_ADDRESS+0x15ff) /* used by rosetta */
0c530ab8 204
2d21ac55 205#define _COMM_PAGE_UNUSED6 (_COMM_PAGE_START_ADDRESS+0x1600) /* unused */
43866e37 206
0c530ab8 207#define _COMM_PAGE_NANOTIME (_COMM_PAGE_START_ADDRESS+0x1700) /* nanotime() */
55e303ae 208
0c530ab8 209#define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0x1780) /* end of common page - insert new stuff here */
55e303ae 210
0c530ab8
A
211/* _COMM_PAGE_COMPARE_AND_SWAP{32,64}B are not used on x86 and are
212 * maintained here for source compatability. These will be removed at
213 * some point, so don't go relying on them. */
214#define _COMM_PAGE_COMPARE_AND_SWAP32B (_COMM_PAGE_START_ADDRESS+0xf80) /* compare-and-swap word w barrier */
215#define _COMM_PAGE_COMPARE_AND_SWAP64B (_COMM_PAGE_START_ADDRESS+0xfc0) /* compare-and-swap doubleword w barrier */
55e303ae
A
216
217#ifdef __ASSEMBLER__
218#ifdef __COMM_PAGE_SYMBOLS
219
220#define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
0c530ab8 221 .org (symbol_address - (_COMM_PAGE_START_ADDRESS & 0xFFFFE000)) ;\
55e303ae
A
222symbol_name: nop
223
0c530ab8 224 .text /* Required to make a well behaved symbol file */
55e303ae 225
91447636
A
226 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap32, _COMM_PAGE_COMPARE_AND_SWAP32)
227 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap64, _COMM_PAGE_COMPARE_AND_SWAP64)
228 CREATE_COMM_PAGE_SYMBOL(___atomic_enqueue, _COMM_PAGE_ENQUEUE)
229 CREATE_COMM_PAGE_SYMBOL(___atomic_dequeue, _COMM_PAGE_DEQUEUE)
230 CREATE_COMM_PAGE_SYMBOL(___memory_barrier, _COMM_PAGE_MEMORY_BARRIER)
231 CREATE_COMM_PAGE_SYMBOL(___atomic_add32, _COMM_PAGE_ATOMIC_ADD32)
232 CREATE_COMM_PAGE_SYMBOL(___atomic_add64, _COMM_PAGE_ATOMIC_ADD64)
55e303ae
A
233 CREATE_COMM_PAGE_SYMBOL(___mach_absolute_time, _COMM_PAGE_ABSOLUTE_TIME)
234 CREATE_COMM_PAGE_SYMBOL(___spin_lock_try, _COMM_PAGE_SPINLOCK_TRY)
235 CREATE_COMM_PAGE_SYMBOL(___spin_lock, _COMM_PAGE_SPINLOCK_LOCK)
236 CREATE_COMM_PAGE_SYMBOL(___spin_unlock, _COMM_PAGE_SPINLOCK_UNLOCK)
237 CREATE_COMM_PAGE_SYMBOL(___pthread_getspecific, _COMM_PAGE_PTHREAD_GETSPECIFIC)
238 CREATE_COMM_PAGE_SYMBOL(___gettimeofday, _COMM_PAGE_GETTIMEOFDAY)
239 CREATE_COMM_PAGE_SYMBOL(___sys_dcache_flush, _COMM_PAGE_FLUSH_DCACHE)
240 CREATE_COMM_PAGE_SYMBOL(___sys_icache_invalidate, _COMM_PAGE_FLUSH_ICACHE)
241 CREATE_COMM_PAGE_SYMBOL(___pthread_self, _COMM_PAGE_PTHREAD_SELF)
242 CREATE_COMM_PAGE_SYMBOL(___spin_lock_relinquish, _COMM_PAGE_RELINQUISH)
91447636
A
243 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_set, _COMM_PAGE_BTS)
244 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_clear, _COMM_PAGE_BTC)
55e303ae
A
245 CREATE_COMM_PAGE_SYMBOL(___bzero, _COMM_PAGE_BZERO)
246 CREATE_COMM_PAGE_SYMBOL(___bcopy, _COMM_PAGE_BCOPY)
247 CREATE_COMM_PAGE_SYMBOL(___memcpy, _COMM_PAGE_MEMCPY)
0c530ab8 248/* CREATE_COMM_PAGE_SYMBOL(___memmove, _COMM_PAGE_MEMMOVE) */
0c530ab8
A
249 CREATE_COMM_PAGE_SYMBOL(___memset_pattern, _COMM_PAGE_MEMSET_PATTERN)
250 CREATE_COMM_PAGE_SYMBOL(___longcopy, _COMM_PAGE_LONGCOPY)
91447636 251 CREATE_COMM_PAGE_SYMBOL(___nanotime, _COMM_PAGE_NANOTIME)
55e303ae
A
252 CREATE_COMM_PAGE_SYMBOL(___end_comm_page, _COMM_PAGE_END)
253
0c530ab8
A
254 .data /* Required to make a well behaved symbol file */
255 .long 0 /* Required to make a well behaved symbol file */
55e303ae
A
256
257#endif /* __COMM_PAGE_SYMBOLS */
258#endif /* __ASSEMBLER__ */
43866e37 259
43866e37 260#endif /* _I386_CPU_CAPABILITIES_H */
91447636 261#endif /* PRIVATE */