2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 #ifndef _I386_CPU_CAPABILITIES_H
33 #define _I386_CPU_CAPABILITIES_H
40 * This is the authoritative way to determine from user mode what
41 * implementation-specific processor features are available.
42 * This API only supported for Apple internal use.
46 /* Bit definitions for _cpu_capabilities: */
48 #define kHasMMX 0x00000001
49 #define kHasSSE 0x00000002
50 #define kHasSSE2 0x00000004
51 #define kHasSSE3 0x00000008
52 #define kCache32 0x00000010 // cache line size is 32 bytes
53 #define kCache64 0x00000020
54 #define kCache128 0x00000040
55 #define kFastThreadLocalStorage 0x00000080 // TLS ptr is kept in a user-mode-readable register
57 #define kUP 0x00008000 // set if (kNumCPUs == 1)
58 #define kNumCPUs 0x00FF0000 // number of CPUs (see _NumCPUs() below)
60 #define kNumCPUsShift 16 // see _NumCPUs() below
63 #include <sys/cdefs.h>
66 extern int _get_cpu_capabilities( void );
72 return (_get_cpu_capabilities() & kNumCPUs
) >> kNumCPUsShift
;
75 #endif /* __ASSEMBLER__ */
79 * The shared kernel/user "comm page(s)":
81 * The last eight pages of every address space are reserved for the kernel/user
82 * "comm area". During system initialization, the kernel populates the comm page with
83 * code customized for the particular processor and platform.
85 * Because Mach VM cannot map the last page of an address space, the max length of
86 * the comm area is seven pages.
89 #define _COMM_PAGE_AREA_LENGTH (19*4096)
90 // reserved length of entire comm area
91 #define _COMM_PAGE_BASE_ADDRESS (-20*4096)
92 // VM_MAX_ADDRESS-_COMM_PAGE_AREA_LENGTH
93 #define _COMM_PAGE_START_ADDRESS (-16*4096)
94 // VM_MAX_ADDRESS-_COMM_PAGE_AREA_LENGTH
95 #define _COMM_PAGE_SIGS_OFFSET 0x8000
96 // offset to routine signatures
98 /* data in the comm page */
100 #define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) // first few bytes are a signature
101 #define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) // 16-bit version#
102 #define _COMM_PAGE_THIS_VERSION 3 // version of the commarea format
104 #define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) // uint32_t _cpu_capabilities
105 #define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x021) // uint8_t number of configured CPUs
106 #define _COMM_PAGE_VECTOR_FLAVOR (_COMM_PAGE_START_ADDRESS+0x024) // uint8_t SSE/SSE2/SSE3
107 #define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) // uint16_t cache line size
109 #define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x030) // 16 unused bytes
111 #define _COMM_PAGE_2_TO_52 (_COMM_PAGE_START_ADDRESS+0x040) // double float constant 2**52
112 #define _COMM_PAGE_10_TO_6 (_COMM_PAGE_START_ADDRESS+0x048) // double float constant 10**6
114 #define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x050) // 16 unused bytes
116 #define _COMM_PAGE_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x060) // used by gettimeofday()
117 #define _COMM_PAGE_TIMESTAMP (_COMM_PAGE_START_ADDRESS+0x068) // used by gettimeofday()
118 #define _COMM_PAGE_SEC_PER_TICK (_COMM_PAGE_START_ADDRESS+0x070) // used by gettimeofday()
120 /* jump table (bla to this address, which may be a branch to the actual code somewhere else) */
121 /* When new jump table entries are added, corresponding symbols should be added below */
123 #define _COMM_PAGE_COMPARE_AND_SWAP32 (_COMM_PAGE_START_ADDRESS+0x080) // compare-and-swap word
124 #define _COMM_PAGE_COMPARE_AND_SWAP64 (_COMM_PAGE_START_ADDRESS+0x0c0) // compare-and-swap doubleword
125 #define _COMM_PAGE_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x100) // enqueue
126 #define _COMM_PAGE_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x140) // dequeue
127 #define _COMM_PAGE_MEMORY_BARRIER (_COMM_PAGE_START_ADDRESS+0x180) // add atomic doubleword
128 #define _COMM_PAGE_ATOMIC_ADD32 (_COMM_PAGE_START_ADDRESS+0x1a0) // add atomic word
129 #define _COMM_PAGE_ATOMIC_ADD64 (_COMM_PAGE_START_ADDRESS+0x1c0) // add atomic doubleword
131 #define _COMM_PAGE_NANOTIME_INFO (_COMM_PAGE_START_ADDRESS+0x1e0) // 32 bytes used by nanotime()
133 #define _COMM_PAGE_ABSOLUTE_TIME (_COMM_PAGE_START_ADDRESS+0x200) // mach_absolute_time()
134 #define _COMM_PAGE_SPINLOCK_TRY (_COMM_PAGE_START_ADDRESS+0x220) // spinlock_try()
135 #define _COMM_PAGE_SPINLOCK_LOCK (_COMM_PAGE_START_ADDRESS+0x260) // spinlock_lock()
136 #define _COMM_PAGE_SPINLOCK_UNLOCK (_COMM_PAGE_START_ADDRESS+0x2a0) // spinlock_unlock()
137 #define _COMM_PAGE_PTHREAD_GETSPECIFIC (_COMM_PAGE_START_ADDRESS+0x2c0) // pthread_getspecific()
138 #define _COMM_PAGE_GETTIMEOFDAY (_COMM_PAGE_START_ADDRESS+0x2e0) // used by gettimeofday()
139 #define _COMM_PAGE_FLUSH_DCACHE (_COMM_PAGE_START_ADDRESS+0x4e0) // sys_dcache_flush()
140 #define _COMM_PAGE_FLUSH_ICACHE (_COMM_PAGE_START_ADDRESS+0x520) // sys_icache_invalidate()
141 #define _COMM_PAGE_PTHREAD_SELF (_COMM_PAGE_START_ADDRESS+0x580) // pthread_self()
142 #define _COMM_PAGE_UNUSED4 (_COMM_PAGE_START_ADDRESS+0x5a0) // 32 unused bytes
143 #define _COMM_PAGE_RELINQUISH (_COMM_PAGE_START_ADDRESS+0x5c0) // used by spinlocks
145 #define _COMM_PAGE_BTS (_COMM_PAGE_START_ADDRESS+0x5e0) // bit test-and-set
146 #define _COMM_PAGE_BTC (_COMM_PAGE_START_ADDRESS+0x5f0) // bit test-and-clear
148 #define _COMM_PAGE_BZERO (_COMM_PAGE_START_ADDRESS+0x600) // bzero()
149 #define _COMM_PAGE_BCOPY (_COMM_PAGE_START_ADDRESS+0x780) // bcopy()
150 #define _COMM_PAGE_MEMCPY (_COMM_PAGE_START_ADDRESS+0x7a0) // memcpy()
151 #define _COMM_PAGE_MEMMOVE (_COMM_PAGE_START_ADDRESS+0x7a0) // memmove()
153 #define _COMM_PAGE_NANOTIME (_COMM_PAGE_START_ADDRESS+0xF80) // nanotime()
155 #define _COMM_PAGE_BIGCOPY (_COMM_PAGE_START_ADDRESS+0x1000)// very-long-operand copies
157 #define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0x1600)// end of common page
160 #ifdef __COMM_PAGE_SYMBOLS
162 #define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
163 .org (symbol_address - (_COMM_PAGE_BASE_ADDRESS & 0xFFFFE000)) ;\
166 .text
// Required to make a well behaved symbol file
168 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap32
, _COMM_PAGE_COMPARE_AND_SWAP32
)
169 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap64
, _COMM_PAGE_COMPARE_AND_SWAP64
)
170 CREATE_COMM_PAGE_SYMBOL(___atomic_enqueue
, _COMM_PAGE_ENQUEUE
)
171 CREATE_COMM_PAGE_SYMBOL(___atomic_dequeue
, _COMM_PAGE_DEQUEUE
)
172 CREATE_COMM_PAGE_SYMBOL(___memory_barrier
, _COMM_PAGE_MEMORY_BARRIER
)
173 CREATE_COMM_PAGE_SYMBOL(___atomic_add32
, _COMM_PAGE_ATOMIC_ADD32
)
174 CREATE_COMM_PAGE_SYMBOL(___atomic_add64
, _COMM_PAGE_ATOMIC_ADD64
)
175 CREATE_COMM_PAGE_SYMBOL(___mach_absolute_time
, _COMM_PAGE_ABSOLUTE_TIME
)
176 CREATE_COMM_PAGE_SYMBOL(___spin_lock_try
, _COMM_PAGE_SPINLOCK_TRY
)
177 CREATE_COMM_PAGE_SYMBOL(___spin_lock
, _COMM_PAGE_SPINLOCK_LOCK
)
178 CREATE_COMM_PAGE_SYMBOL(___spin_unlock
, _COMM_PAGE_SPINLOCK_UNLOCK
)
179 CREATE_COMM_PAGE_SYMBOL(___pthread_getspecific
, _COMM_PAGE_PTHREAD_GETSPECIFIC
)
180 CREATE_COMM_PAGE_SYMBOL(___gettimeofday
, _COMM_PAGE_GETTIMEOFDAY
)
181 CREATE_COMM_PAGE_SYMBOL(___sys_dcache_flush
, _COMM_PAGE_FLUSH_DCACHE
)
182 CREATE_COMM_PAGE_SYMBOL(___sys_icache_invalidate
, _COMM_PAGE_FLUSH_ICACHE
)
183 CREATE_COMM_PAGE_SYMBOL(___pthread_self
, _COMM_PAGE_PTHREAD_SELF
)
184 CREATE_COMM_PAGE_SYMBOL(___spin_lock_relinquish
, _COMM_PAGE_RELINQUISH
)
185 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_set
, _COMM_PAGE_BTS
)
186 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_clear
, _COMM_PAGE_BTC
)
187 CREATE_COMM_PAGE_SYMBOL(___bzero
, _COMM_PAGE_BZERO
)
188 CREATE_COMM_PAGE_SYMBOL(___bcopy
, _COMM_PAGE_BCOPY
)
189 CREATE_COMM_PAGE_SYMBOL(___memcpy
, _COMM_PAGE_MEMCPY
)
190 // CREATE_COMM_PAGE_SYMBOL(___memmove, _COMM_PAGE_MEMMOVE)
191 CREATE_COMM_PAGE_SYMBOL(___bigcopy
, _COMM_PAGE_BIGCOPY
)
192 CREATE_COMM_PAGE_SYMBOL(___nanotime
, _COMM_PAGE_NANOTIME
)
193 CREATE_COMM_PAGE_SYMBOL(___end_comm_page
, _COMM_PAGE_END
)
195 .data
// Required to make a well behaved symbol file
196 .long 0 // Required to make a well behaved symbol file
198 #endif /* __COMM_PAGE_SYMBOLS */
199 #endif /* __ASSEMBLER__ */
201 #endif /* _I386_CPU_CAPABILITIES_H */