]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/cpu_capabilities.h
xnu-792.17.14.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_capabilities.h
CommitLineData
43866e37 1/*
8f6c56a5 2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
43866e37 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
43866e37 5 *
8f6c56a5
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.
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
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/*
8f6c56a5
A
38 * This is the authoritative way to determine from user mode what
39 * implementation-specific processor features are available.
43866e37 40 * This API only supported for Apple internal use.
8f6c56a5 41 *
43866e37
A
42 */
43
55e303ae
A
44/* Bit definitions for _cpu_capabilities: */
45
46#define kHasMMX 0x00000001
47#define kHasSSE 0x00000002
48#define kHasSSE2 0x00000004
91447636 49#define kHasSSE3 0x00000008
8f6c56a5 50#define kCache32 0x00000010 // cache line size is 32 bytes
55e303ae
A
51#define kCache64 0x00000020
52#define kCache128 0x00000040
8f6c56a5 53#define kFastThreadLocalStorage 0x00000080 // TLS ptr is kept in a user-mode-readable register
55e303ae 54
8f6c56a5
A
55#define kUP 0x00008000 // set if (kNumCPUs == 1)
56#define kNumCPUs 0x00FF0000 // number of CPUs (see _NumCPUs() below)
55e303ae 57
8f6c56a5 58#define kNumCPUsShift 16 // see _NumCPUs() below
55e303ae 59
43866e37 60#ifndef __ASSEMBLER__
91447636
A
61#include <sys/cdefs.h>
62
63__BEGIN_DECLS
64extern int _get_cpu_capabilities( void );
65__END_DECLS
55e303ae
A
66
67inline static
68int _NumCPUs( void )
69{
70 return (_get_cpu_capabilities() & kNumCPUs) >> kNumCPUsShift;
71}
72
73#endif /* __ASSEMBLER__ */
74
75
76/*
77 * The shared kernel/user "comm page(s)":
78 *
8f6c56a5
A
79 * The last eight pages of every address space are reserved for the kernel/user
80 * "comm area". During system initialization, the kernel populates the comm page with
55e303ae
A
81 * code customized for the particular processor and platform.
82 *
8f6c56a5
A
83 * Because Mach VM cannot map the last page of an address space, the max length of
84 * the comm area is seven pages.
55e303ae
A
85 */
86
8f6c56a5
A
87#define _COMM_PAGE_AREA_LENGTH (19*4096)
88 // reserved length of entire comm area
89#define _COMM_PAGE_BASE_ADDRESS (-20*4096)
90 // VM_MAX_ADDRESS-_COMM_PAGE_AREA_LENGTH
91#define _COMM_PAGE_START_ADDRESS (-16*4096)
92 // VM_MAX_ADDRESS-_COMM_PAGE_AREA_LENGTH
93#define _COMM_PAGE_SIGS_OFFSET 0x8000
94 // offset to routine signatures
55e303ae
A
95
96/* data in the comm page */
43866e37 97
8f6c56a5
A
98#define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) // first few bytes are a signature
99#define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) // 16-bit version#
100#define _COMM_PAGE_THIS_VERSION 3 // version of the commarea format
55e303ae 101
8f6c56a5
A
102#define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) // uint32_t _cpu_capabilities
103#define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x021) // uint8_t number of configured CPUs
104#define _COMM_PAGE_VECTOR_FLAVOR (_COMM_PAGE_START_ADDRESS+0x024) // uint8_t SSE/SSE2/SSE3
105#define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) // uint16_t cache line size
55e303ae 106
8f6c56a5 107#define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x030) // 16 unused bytes
8ad349bb 108
8f6c56a5
A
109#define _COMM_PAGE_2_TO_52 (_COMM_PAGE_START_ADDRESS+0x040) // double float constant 2**52
110#define _COMM_PAGE_10_TO_6 (_COMM_PAGE_START_ADDRESS+0x048) // double float constant 10**6
55e303ae 111
8f6c56a5
A
112#define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x050) // 16 unused bytes
113
114#define _COMM_PAGE_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x060) // used by gettimeofday()
115#define _COMM_PAGE_TIMESTAMP (_COMM_PAGE_START_ADDRESS+0x068) // used by gettimeofday()
116#define _COMM_PAGE_SEC_PER_TICK (_COMM_PAGE_START_ADDRESS+0x070) // used by gettimeofday()
8ad349bb 117
8f6c56a5
A
118 /* jump table (bla to this address, which may be a branch to the actual code somewhere else) */
119 /* When new jump table entries are added, corresponding symbols should be added below */
5d5c5d0d 120
8f6c56a5
A
121#define _COMM_PAGE_COMPARE_AND_SWAP32 (_COMM_PAGE_START_ADDRESS+0x080) // compare-and-swap word
122#define _COMM_PAGE_COMPARE_AND_SWAP64 (_COMM_PAGE_START_ADDRESS+0x0c0) // compare-and-swap doubleword
123#define _COMM_PAGE_ENQUEUE (_COMM_PAGE_START_ADDRESS+0x100) // enqueue
124#define _COMM_PAGE_DEQUEUE (_COMM_PAGE_START_ADDRESS+0x140) // dequeue
125#define _COMM_PAGE_MEMORY_BARRIER (_COMM_PAGE_START_ADDRESS+0x180) // add atomic doubleword
126#define _COMM_PAGE_ATOMIC_ADD32 (_COMM_PAGE_START_ADDRESS+0x1a0) // add atomic word
127#define _COMM_PAGE_ATOMIC_ADD64 (_COMM_PAGE_START_ADDRESS+0x1c0) // add atomic doubleword
5d5c5d0d 128
8f6c56a5
A
129#define _COMM_PAGE_NANOTIME_INFO (_COMM_PAGE_START_ADDRESS+0x1e0) // 32 bytes used by nanotime()
130
131#define _COMM_PAGE_ABSOLUTE_TIME (_COMM_PAGE_START_ADDRESS+0x200) // mach_absolute_time()
132#define _COMM_PAGE_SPINLOCK_TRY (_COMM_PAGE_START_ADDRESS+0x220) // spinlock_try()
133#define _COMM_PAGE_SPINLOCK_LOCK (_COMM_PAGE_START_ADDRESS+0x260) // spinlock_lock()
134#define _COMM_PAGE_SPINLOCK_UNLOCK (_COMM_PAGE_START_ADDRESS+0x2a0) // spinlock_unlock()
135#define _COMM_PAGE_PTHREAD_GETSPECIFIC (_COMM_PAGE_START_ADDRESS+0x2c0) // pthread_getspecific()
136#define _COMM_PAGE_GETTIMEOFDAY (_COMM_PAGE_START_ADDRESS+0x2e0) // used by gettimeofday()
137#define _COMM_PAGE_FLUSH_DCACHE (_COMM_PAGE_START_ADDRESS+0x4e0) // sys_dcache_flush()
138#define _COMM_PAGE_FLUSH_ICACHE (_COMM_PAGE_START_ADDRESS+0x520) // sys_icache_invalidate()
139#define _COMM_PAGE_PTHREAD_SELF (_COMM_PAGE_START_ADDRESS+0x580) // pthread_self()
140#define _COMM_PAGE_UNUSED4 (_COMM_PAGE_START_ADDRESS+0x5a0) // 32 unused bytes
141#define _COMM_PAGE_RELINQUISH (_COMM_PAGE_START_ADDRESS+0x5c0) // used by spinlocks
142
143#define _COMM_PAGE_BTS (_COMM_PAGE_START_ADDRESS+0x5e0) // bit test-and-set
144#define _COMM_PAGE_BTC (_COMM_PAGE_START_ADDRESS+0x5f0) // bit test-and-clear
145
146#define _COMM_PAGE_BZERO (_COMM_PAGE_START_ADDRESS+0x600) // bzero()
147#define _COMM_PAGE_BCOPY (_COMM_PAGE_START_ADDRESS+0x780) // bcopy()
148#define _COMM_PAGE_MEMCPY (_COMM_PAGE_START_ADDRESS+0x7a0) // memcpy()
149#define _COMM_PAGE_MEMMOVE (_COMM_PAGE_START_ADDRESS+0x7a0) // memmove()
43866e37 150
8f6c56a5 151#define _COMM_PAGE_NANOTIME (_COMM_PAGE_START_ADDRESS+0xF80) // nanotime()
55e303ae 152
8f6c56a5 153#define _COMM_PAGE_BIGCOPY (_COMM_PAGE_START_ADDRESS+0x1000)// very-long-operand copies
55e303ae 154
8f6c56a5 155#define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0x1600)// end of common page
55e303ae
A
156
157#ifdef __ASSEMBLER__
158#ifdef __COMM_PAGE_SYMBOLS
159
160#define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
8f6c56a5 161 .org (symbol_address - (_COMM_PAGE_BASE_ADDRESS & 0xFFFFE000)) ;\
55e303ae
A
162symbol_name: nop
163
8f6c56a5 164 .text // Required to make a well behaved symbol file
55e303ae 165
91447636
A
166 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap32, _COMM_PAGE_COMPARE_AND_SWAP32)
167 CREATE_COMM_PAGE_SYMBOL(___compare_and_swap64, _COMM_PAGE_COMPARE_AND_SWAP64)
168 CREATE_COMM_PAGE_SYMBOL(___atomic_enqueue, _COMM_PAGE_ENQUEUE)
169 CREATE_COMM_PAGE_SYMBOL(___atomic_dequeue, _COMM_PAGE_DEQUEUE)
170 CREATE_COMM_PAGE_SYMBOL(___memory_barrier, _COMM_PAGE_MEMORY_BARRIER)
171 CREATE_COMM_PAGE_SYMBOL(___atomic_add32, _COMM_PAGE_ATOMIC_ADD32)
172 CREATE_COMM_PAGE_SYMBOL(___atomic_add64, _COMM_PAGE_ATOMIC_ADD64)
55e303ae
A
173 CREATE_COMM_PAGE_SYMBOL(___mach_absolute_time, _COMM_PAGE_ABSOLUTE_TIME)
174 CREATE_COMM_PAGE_SYMBOL(___spin_lock_try, _COMM_PAGE_SPINLOCK_TRY)
175 CREATE_COMM_PAGE_SYMBOL(___spin_lock, _COMM_PAGE_SPINLOCK_LOCK)
176 CREATE_COMM_PAGE_SYMBOL(___spin_unlock, _COMM_PAGE_SPINLOCK_UNLOCK)
177 CREATE_COMM_PAGE_SYMBOL(___pthread_getspecific, _COMM_PAGE_PTHREAD_GETSPECIFIC)
178 CREATE_COMM_PAGE_SYMBOL(___gettimeofday, _COMM_PAGE_GETTIMEOFDAY)
179 CREATE_COMM_PAGE_SYMBOL(___sys_dcache_flush, _COMM_PAGE_FLUSH_DCACHE)
180 CREATE_COMM_PAGE_SYMBOL(___sys_icache_invalidate, _COMM_PAGE_FLUSH_ICACHE)
181 CREATE_COMM_PAGE_SYMBOL(___pthread_self, _COMM_PAGE_PTHREAD_SELF)
182 CREATE_COMM_PAGE_SYMBOL(___spin_lock_relinquish, _COMM_PAGE_RELINQUISH)
91447636
A
183 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_set, _COMM_PAGE_BTS)
184 CREATE_COMM_PAGE_SYMBOL(___bit_test_and_clear, _COMM_PAGE_BTC)
55e303ae
A
185 CREATE_COMM_PAGE_SYMBOL(___bzero, _COMM_PAGE_BZERO)
186 CREATE_COMM_PAGE_SYMBOL(___bcopy, _COMM_PAGE_BCOPY)
187 CREATE_COMM_PAGE_SYMBOL(___memcpy, _COMM_PAGE_MEMCPY)
8f6c56a5
A
188// CREATE_COMM_PAGE_SYMBOL(___memmove, _COMM_PAGE_MEMMOVE)
189 CREATE_COMM_PAGE_SYMBOL(___bigcopy, _COMM_PAGE_BIGCOPY)
91447636 190 CREATE_COMM_PAGE_SYMBOL(___nanotime, _COMM_PAGE_NANOTIME)
55e303ae
A
191 CREATE_COMM_PAGE_SYMBOL(___end_comm_page, _COMM_PAGE_END)
192
8f6c56a5
A
193 .data // Required to make a well behaved symbol file
194 .long 0 // Required to make a well behaved symbol file
55e303ae
A
195
196#endif /* __COMM_PAGE_SYMBOLS */
197#endif /* __ASSEMBLER__ */
43866e37 198
43866e37 199#endif /* _I386_CPU_CAPABILITIES_H */
91447636 200#endif /* PRIVATE */