2 * Copyright (c) 2003-2006 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@
24 #ifndef _I386_CPU_CAPABILITIES_H
25 #define _I386_CPU_CAPABILITIES_H
32 * This API only supported for Apple internal use.
35 /* Bit definitions for _cpu_capabilities: */
37 #define kHasMMX 0x00000001
38 #define kHasSSE 0x00000002
39 #define kHasSSE2 0x00000004
40 #define kHasSSE3 0x00000008
41 #define kCache32 0x00000010 /* cache line size is 32 bytes */
42 #define kCache64 0x00000020
43 #define kCache128 0x00000040
44 #define kFastThreadLocalStorage 0x00000080 /* TLS ptr is kept in a user-mode-readable register */
45 #define kHasSupplementalSSE3 0x00000100
46 #define kHasMNI kHasSupplementalSSE3
47 #define k64Bit 0x00000200 /* processor supports EM64T (not what mode you're running in) */
49 #define kUP 0x00008000 /* set if (kNumCPUs == 1) */
50 #define kNumCPUs 0x00FF0000 /* number of CPUs (see _NumCPUs() below) */
52 #define kNumCPUsShift 16 /* see _NumCPUs() below */
55 #include <sys/cdefs.h>
58 extern int _get_cpu_capabilities( void );
64 return (_get_cpu_capabilities() & kNumCPUs
) >> kNumCPUsShift
;
67 #endif /* __ASSEMBLER__ */
71 * The shared kernel/user "comm page(s)":
73 * The last several pages of every address space are reserved for the kernel/user
74 * "comm area". During system initialization, the kernel populates the comm pages with
75 * code customized for the particular processor and platform.
77 * Because Mach VM cannot map the last page of an address space, we don't use it.
80 #define _COMM_PAGE32_AREA_LENGTH ( 19 * 4096 ) /* reserved length of entire comm area */
81 #define _COMM_PAGE32_BASE_ADDRESS ( -20 * 4096 ) /* base address of allocated memory */
82 #define _COMM_PAGE32_START_ADDRESS ( -16 * 4096 ) /* address traditional commpage code starts on */
83 #define _COMM_PAGE32_AREA_USED ( 19 * 4096 ) /* this is the amt actually allocated */
85 #define _COMM_PAGE64_AREA_LENGTH ( 2 * 1024 * 1024 ) /* reserved length of entire comm area (2MB) */
86 #define _COMM_PAGE64_BASE_ADDRESS ( 0x00007fffffe00000ULL ) /* base address of allocated memory */
87 #define _COMM_PAGE64_START_ADDRESS ( _COMM_PAGE64_BASE_ADDRESS ) /* address traditional commpage code starts on */
88 #define _COMM_PAGE64_AREA_USED ( 2 * 4096 ) /* this is the amt actually populated */
93 #define _COMM_PAGE_AREA_LENGTH _COMM_PAGE32_AREA_LENGTH
94 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE32_BASE_ADDRESS
95 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
96 #define _COMM_PAGE_AREA_USED _COMM_PAGE32_AREA_USED
97 #define _COMM_PAGE_SIGS_OFFSET 0x8000 /* offset to routine signatures */
99 #elif defined(__x86_64__)
101 #define _COMM_PAGE_AREA_LENGTH _COMM_PAGE64_AREA_LENGTH
102 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE64_BASE_ADDRESS
103 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE64_START_ADDRESS
104 #define _COMM_PAGE_AREA_USED _COMM_PAGE64_AREA_USED
107 #error architecture not supported
110 /* data in the comm page */
112 #define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) /* first few bytes are a signature */
113 #define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) /* 16-bit version# */
114 #define _COMM_PAGE_THIS_VERSION 6 /* version of the commarea format */
116 #define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) /* uint32_t _cpu_capabilities */
117 #define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) /* uint8_t number of configured CPUs */
118 #define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) /* uint16_t cache line size */
120 #define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x028) /* 24 unused bytes */
122 #if defined(__i386__) /* following are not defined in 64-bit */
123 #define _COMM_PAGE_2_TO_52 (_COMM_PAGE_START_ADDRESS+0x040) /* double float constant 2**52 */
124 #define _COMM_PAGE_10_TO_6 (_COMM_PAGE_START_ADDRESS+0x048) /* double float constant 10**6 */
126 #define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x040) /* 16 unused bytes */
129 #define _COMM_PAGE_NT_TSC_BASE (_COMM_PAGE_START_ADDRESS+0x050) /* used by nanotime() */
130 #define _COMM_PAGE_NT_SCALE (_COMM_PAGE_START_ADDRESS+0x058) /* used by nanotime() */
131 #define _COMM_PAGE_NT_SHIFT (_COMM_PAGE_START_ADDRESS+0x05c) /* used by nanotime() */
132 #define _COMM_PAGE_NT_NS_BASE (_COMM_PAGE_START_ADDRESS+0x060) /* used by nanotime() */
134 #define _COMM_PAGE_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x068) /* used by gettimeofday() */
135 #define _COMM_PAGE_TIMESTAMP (_COMM_PAGE_START_ADDRESS+0x070) /* used by gettimeofday() */
136 #define _COMM_PAGE_TIMEENABLE (_COMM_PAGE_START_ADDRESS+0x078) /* used by gettimeofday() */
138 #define _NT_TSC_BASE 0 /* offsets into nanotime data */
141 #define _NT_NS_BASE 16
142 #define _TIMEBASE 0 /* offsets into gettimeofday data */
144 #define _TIMEENABLE 16
146 /* jump table (jmp to this address, which may be a branch to the actual code somewhere else) */
147 /* When new jump table entries are added, corresponding symbols should be added below */
149 #define _COMM_PAGE_COMPARE_AND_SWAP32 (_COMM_PAGE_START_ADDRESS+0x080) /* compare-and-swap word */
150 #define _COMM_PAGE_COMPARE_AND_SWAP64 (_COMM_PAGE_START_ADDRESS+0x0c0) /* compare-and-swap doubleword */
151 #define _COMM_PAGE_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x100) /* enqueue */
152 #define _COMM_PAGE_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x140) /* dequeue */
153 #define _COMM_PAGE_MEMORY_BARRIER (_COMM_PAGE_START_ADDRESS+0x180) /* memory barrier */
154 #define _COMM_PAGE_ATOMIC_ADD32 (_COMM_PAGE_START_ADDRESS+0x1a0) /* add atomic word */
155 #define _COMM_PAGE_ATOMIC_ADD64 (_COMM_PAGE_START_ADDRESS+0x1c0) /* add atomic doubleword */
157 #define _COMM_PAGE_UNUSED3 (_COMM_PAGE_START_ADDRESS+0x1e0) /* 32 unused bytes */
159 #define _COMM_PAGE_ABSOLUTE_TIME (_COMM_PAGE_START_ADDRESS+0x200) /* mach_absolute_time() */
160 #define _COMM_PAGE_SPINLOCK_TRY (_COMM_PAGE_START_ADDRESS+0x220) /* spinlock_try() */
161 #define _COMM_PAGE_SPINLOCK_LOCK (_COMM_PAGE_START_ADDRESS+0x260) /* spinlock_lock() */
162 #define _COMM_PAGE_SPINLOCK_UNLOCK (_COMM_PAGE_START_ADDRESS+0x2a0) /* spinlock_unlock() */
163 #define _COMM_PAGE_PTHREAD_GETSPECIFIC (_COMM_PAGE_START_ADDRESS+0x2c0) /* pthread_getspecific() */
164 #define _COMM_PAGE_GETTIMEOFDAY (_COMM_PAGE_START_ADDRESS+0x2e0) /* used by gettimeofday() */
165 #define _COMM_PAGE_FLUSH_DCACHE (_COMM_PAGE_START_ADDRESS+0x4e0) /* sys_dcache_flush() */
166 #define _COMM_PAGE_FLUSH_ICACHE (_COMM_PAGE_START_ADDRESS+0x520) /* sys_icache_invalidate() */
167 #define _COMM_PAGE_PTHREAD_SELF (_COMM_PAGE_START_ADDRESS+0x580) /* pthread_self() */
169 #define _COMM_PAGE_UNUSED4 (_COMM_PAGE_START_ADDRESS+0x5a0) /* 32 unused bytes */
171 #define _COMM_PAGE_RELINQUISH (_COMM_PAGE_START_ADDRESS+0x5c0) /* used by spinlocks */
172 #define _COMM_PAGE_BTS (_COMM_PAGE_START_ADDRESS+0x5e0) /* bit test-and-set */
173 #define _COMM_PAGE_BTC (_COMM_PAGE_START_ADDRESS+0x5f0) /* bit test-and-clear */
175 #define _COMM_PAGE_BZERO (_COMM_PAGE_START_ADDRESS+0x600) /* bzero() */
176 #define _COMM_PAGE_BCOPY (_COMM_PAGE_START_ADDRESS+0x780) /* bcopy() */
177 #define _COMM_PAGE_MEMCPY (_COMM_PAGE_START_ADDRESS+0x7a0) /* memcpy() */
178 #define _COMM_PAGE_MEMMOVE (_COMM_PAGE_START_ADDRESS+0x7a0) /* memmove() */
180 #define _COMM_PAGE_OLD_NANOTIME (_COMM_PAGE_START_ADDRESS+0xf80) /* old nanotime location (deprecated) */
181 #define _COMM_PAGE_MEMSET_PATTERN (_COMM_PAGE_START_ADDRESS+0x1000) /* used by nonzero memset() */
182 #define _COMM_PAGE_LONGCOPY (_COMM_PAGE_START_ADDRESS+0x1200) /* used by bcopy() for very long operands */
184 #define _COMM_PAGE_SYSTEM_INTEGRITY (_COMM_PAGE_START_ADDRESS+0x1600) /* system integrity data, 256 bytes */
186 #define _COMM_PAGE_NANOTIME (_COMM_PAGE_START_ADDRESS+0x1700) /* nanotime() */
188 #define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0x1780) /* end of common page - insert new stuff here */
190 /* _COMM_PAGE_COMPARE_AND_SWAP{32,64}B are not used on x86 and are
191 * maintained here for source compatability. These will be removed at
192 * some point, so don't go relying on them. */
193 #define _COMM_PAGE_COMPARE_AND_SWAP32B (_COMM_PAGE_START_ADDRESS+0xf80) /* compare-and-swap word w barrier */
194 #define _COMM_PAGE_COMPARE_AND_SWAP64B (_COMM_PAGE_START_ADDRESS+0xfc0) /* compare-and-swap doubleword w barrier */
197 #ifdef __COMM_PAGE_SYMBOLS
199 #define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
200 .org (symbol_address - (_COMM_PAGE_START_ADDRESS & 0xFFFFE000)) ;\
203 .text
/* Required to make a well behaved symbol file */
205 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap32
, _COMM_PAGE_COMPARE_AND_SWAP32
)
206 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap64
, _COMM_PAGE_COMPARE_AND_SWAP64
)
207 CREATE_COMM_PAGE_SYMBOL(___atomic_enqueue
, _COMM_PAGE_ENQUEUE
)
208 CREATE_COMM_PAGE_SYMBOL(___atomic_dequeue
, _COMM_PAGE_DEQUEUE
)
209 CREATE_COMM_PAGE_SYMBOL(___memory_barrier
, _COMM_PAGE_MEMORY_BARRIER
)
210 CREATE_COMM_PAGE_SYMBOL(___atomic_add32
, _COMM_PAGE_ATOMIC_ADD32
)
211 CREATE_COMM_PAGE_SYMBOL(___atomic_add64
, _COMM_PAGE_ATOMIC_ADD64
)
212 CREATE_COMM_PAGE_SYMBOL(___mach_absolute_time
, _COMM_PAGE_ABSOLUTE_TIME
)
213 CREATE_COMM_PAGE_SYMBOL(___spin_lock_try
, _COMM_PAGE_SPINLOCK_TRY
)
214 CREATE_COMM_PAGE_SYMBOL(___spin_lock
, _COMM_PAGE_SPINLOCK_LOCK
)
215 CREATE_COMM_PAGE_SYMBOL(___spin_unlock
, _COMM_PAGE_SPINLOCK_UNLOCK
)
216 CREATE_COMM_PAGE_SYMBOL(___pthread_getspecific
, _COMM_PAGE_PTHREAD_GETSPECIFIC
)
217 CREATE_COMM_PAGE_SYMBOL(___gettimeofday
, _COMM_PAGE_GETTIMEOFDAY
)
218 CREATE_COMM_PAGE_SYMBOL(___sys_dcache_flush
, _COMM_PAGE_FLUSH_DCACHE
)
219 CREATE_COMM_PAGE_SYMBOL(___sys_icache_invalidate
, _COMM_PAGE_FLUSH_ICACHE
)
220 CREATE_COMM_PAGE_SYMBOL(___pthread_self
, _COMM_PAGE_PTHREAD_SELF
)
221 CREATE_COMM_PAGE_SYMBOL(___spin_lock_relinquish
, _COMM_PAGE_RELINQUISH
)
222 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_set
, _COMM_PAGE_BTS
)
223 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_clear
, _COMM_PAGE_BTC
)
224 CREATE_COMM_PAGE_SYMBOL(___bzero
, _COMM_PAGE_BZERO
)
225 CREATE_COMM_PAGE_SYMBOL(___bcopy
, _COMM_PAGE_BCOPY
)
226 CREATE_COMM_PAGE_SYMBOL(___memcpy
, _COMM_PAGE_MEMCPY
)
227 /* CREATE_COMM_PAGE_SYMBOL(___memmove, _COMM_PAGE_MEMMOVE) */
228 CREATE_COMM_PAGE_SYMBOL(___old_nanotime
, _COMM_PAGE_OLD_NANOTIME
)
229 CREATE_COMM_PAGE_SYMBOL(___memset_pattern
, _COMM_PAGE_MEMSET_PATTERN
)
230 CREATE_COMM_PAGE_SYMBOL(___longcopy
, _COMM_PAGE_LONGCOPY
)
231 CREATE_COMM_PAGE_SYMBOL(___nanotime
, _COMM_PAGE_NANOTIME
)
232 CREATE_COMM_PAGE_SYMBOL(___end_comm_page
, _COMM_PAGE_END
)
234 .data
/* Required to make a well behaved symbol file */
235 .long 0 /* Required to make a well behaved symbol file */
237 #endif /* __COMM_PAGE_SYMBOLS */
238 #endif /* __ASSEMBLER__ */
240 #endif /* _I386_CPU_CAPABILITIES_H */