]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu_capabilities.h
xnu-517.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_capabilities.h
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 #ifndef _I386_CPU_CAPABILITIES_H
27 #define _I386_CPU_CAPABILITIES_H
28
29 /* Sadly, some clients of this interface misspell __APPLE_API_PRIVATE.
30 * To avoid breaking them, we accept the incorrect _APPLE_API_PRIVATE.
31 */
32 #ifdef _APPLE_API_PRIVATE
33 #ifndef __APPLE_API_PRIVATE
34 #define __APPLE_API_PRIVATE
35 #endif /* __APPLE_API_PRIVATE */
36 #endif /* _APPLE_API_PRIVATE */
37
38 #ifndef __APPLE_API_PRIVATE
39 #error cpu_capabilities.h is for Apple Internal use only
40 #else /* __APPLE_API_PRIVATE */
41
42 /*
43 * This is the authoritative way to determine from user mode what
44 * implementation-specific processor features are available.
45 * This API only supported for Apple internal use.
46 *
47 */
48
49 /* Bit definitions for _cpu_capabilities: */
50
51 #define kHasMMX 0x00000001
52 #define kHasSSE 0x00000002
53 #define kHasSSE2 0x00000004
54 #define kHasPNI 0x00000008 // Prescott New Instructions
55 #define kCache32 0x00000010 // cache line size is 32 bytes
56 #define kCache64 0x00000020
57 #define kCache128 0x00000040
58
59 #define kUP 0x00008000 // set if (kNumCPUs == 1)
60 #define kNumCPUs 0x00FF0000 // number of CPUs (see _NumCPUs() below)
61
62 #define kNumCPUsShift 16 // see _NumCPUs() below
63
64 #ifndef __ASSEMBLER__
65
66 extern uint32_t _get_cpu_capabilities( void );
67
68 inline static
69 int _NumCPUs( void )
70 {
71 return (_get_cpu_capabilities() & kNumCPUs) >> kNumCPUsShift;
72 }
73
74 #endif /* __ASSEMBLER__ */
75
76
77 /*
78 * The shared kernel/user "comm page(s)":
79 *
80 * The last eight pages of every address space are reserved for the kernel/user
81 * "comm area". During system initialization, the kernel populates the comm page with
82 * code customized for the particular processor and platform.
83 *
84 * Because Mach VM cannot map the last page of an address space, the max length of
85 * the comm area is seven pages.
86 */
87
88 #define _COMM_PAGE_BASE_ADDRESS 0xBFFF9000 // VM_MAX_ADDRESS - 7 * 4096
89 #define _COMM_PAGE_SIGS_OFFSET 0x4000 // offset to routine signatures
90 #define _COMM_PAGE_AREA_LENGTH ( 7*4096) // reserved length of entire comm area
91
92 /* data in the comm page */
93
94 #define _COMM_PAGE_SIGNATURE (_COMM_PAGE_BASE_ADDRESS+0x000) // first few bytes are a signature
95 #define _COMM_PAGE_VERSION (_COMM_PAGE_BASE_ADDRESS+0x01E) // 16-bit version#
96 #define _COMM_PAGE_THIS_VERSION 1 // this is version 1 of the commarea format
97
98 #define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_BASE_ADDRESS+0x020) // uint32_t _cpu_capabilities
99 #define _COMM_PAGE_NCPUS (_COMM_PAGE_BASE_ADDRESS+0x021) // uint8_t number of configured CPUs
100 #define _COMM_PAGE_VECTOR_FLAVOR (_COMM_PAGE_BASE_ADDRESS+0x024) // uint8_t SSE/SSE2/PNI
101 #define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_BASE_ADDRESS+0x026) // uint16_t cache line size
102
103 #define _COMM_PAGE_UNUSED1 (_COMM_PAGE_BASE_ADDRESS+0x030) // 16 unused bytes
104
105 #define _COMM_PAGE_2_TO_52 (_COMM_PAGE_BASE_ADDRESS+0x040) // double float constant 2**52
106 #define _COMM_PAGE_10_TO_6 (_COMM_PAGE_BASE_ADDRESS+0x048) // double float constant 10**6
107
108 #define _COMM_PAGE_UNUSED2 (_COMM_PAGE_BASE_ADDRESS+0x050) // 16 unused bytes
109
110 #define _COMM_PAGE_TIMEBASE (_COMM_PAGE_BASE_ADDRESS+0x060) // used by gettimeofday()
111 #define _COMM_PAGE_TIMESTAMP (_COMM_PAGE_BASE_ADDRESS+0x068) // used by gettimeofday()
112 #define _COMM_PAGE_SEC_PER_TICK (_COMM_PAGE_BASE_ADDRESS+0x070) // used by gettimeofday()
113
114 #define _COMM_PAGE_UNUSED3 (_COMM_PAGE_BASE_ADDRESS+0x080) // 384 unused bytes
115
116 /* jump table (bla to this address, which may be a branch to the actual code somewhere else) */
117 /* When new jump table entries are added, corresponding symbols should be added below */
118
119 #define _COMM_PAGE_ABSOLUTE_TIME (_COMM_PAGE_BASE_ADDRESS+0x200) // mach_absolute_time()
120 #define _COMM_PAGE_SPINLOCK_TRY (_COMM_PAGE_BASE_ADDRESS+0x220) // spinlock_try()
121 #define _COMM_PAGE_SPINLOCK_LOCK (_COMM_PAGE_BASE_ADDRESS+0x260) // spinlock_lock()
122 #define _COMM_PAGE_SPINLOCK_UNLOCK (_COMM_PAGE_BASE_ADDRESS+0x2a0) // spinlock_unlock()
123 #define _COMM_PAGE_PTHREAD_GETSPECIFIC (_COMM_PAGE_BASE_ADDRESS+0x2c0) // pthread_getspecific()
124 #define _COMM_PAGE_GETTIMEOFDAY (_COMM_PAGE_BASE_ADDRESS+0x2e0) // used by gettimeofday()
125 #define _COMM_PAGE_FLUSH_DCACHE (_COMM_PAGE_BASE_ADDRESS+0x4e0) // sys_dcache_flush()
126 #define _COMM_PAGE_FLUSH_ICACHE (_COMM_PAGE_BASE_ADDRESS+0x520) // sys_icache_invalidate()
127 #define _COMM_PAGE_PTHREAD_SELF (_COMM_PAGE_BASE_ADDRESS+0x580) // pthread_self()
128 #define _COMM_PAGE_UNUSED4 (_COMM_PAGE_BASE_ADDRESS+0x5a0) // 32 unused bytes
129 #define _COMM_PAGE_RELINQUISH (_COMM_PAGE_BASE_ADDRESS+0x5c0) // used by spinlocks
130
131 #define _COMM_PAGE_UNUSED5 (_COMM_PAGE_BASE_ADDRESS+0x5e0) // 32 unused bytes
132
133 #define _COMM_PAGE_BZERO (_COMM_PAGE_BASE_ADDRESS+0x600) // bzero()
134 #define _COMM_PAGE_BCOPY (_COMM_PAGE_BASE_ADDRESS+0x780) // bcopy()
135 #define _COMM_PAGE_MEMCPY (_COMM_PAGE_BASE_ADDRESS+0x7a0) // memcpy()
136 #define _COMM_PAGE_MEMMOVE (_COMM_PAGE_BASE_ADDRESS+0x7a0) // memmove()
137
138 #define _COMM_PAGE_UNUSED6 (_COMM_PAGE_BASE_ADDRESS+0xF80) // 128 unused bytes
139
140 #define _COMM_PAGE_BIGCOPY (_COMM_PAGE_BASE_ADDRESS+0x1000)// very-long-operand copies
141
142 #define _COMM_PAGE_END (_COMM_PAGE_BASE_ADDRESS+0x1600)// end of common page
143
144 #ifdef __ASSEMBLER__
145 #ifdef __COMM_PAGE_SYMBOLS
146
147 #define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
148 .org (symbol_address - (_COMM_PAGE_BASE_ADDRESS & 0xFFFFE000)) ;\
149 symbol_name: nop
150
151 .text // Required to make a well behaved symbol file
152
153 CREATE_COMM_PAGE_SYMBOL(___mach_absolute_time, _COMM_PAGE_ABSOLUTE_TIME)
154 CREATE_COMM_PAGE_SYMBOL(___spin_lock_try, _COMM_PAGE_SPINLOCK_TRY)
155 CREATE_COMM_PAGE_SYMBOL(___spin_lock, _COMM_PAGE_SPINLOCK_LOCK)
156 CREATE_COMM_PAGE_SYMBOL(___spin_unlock, _COMM_PAGE_SPINLOCK_UNLOCK)
157 CREATE_COMM_PAGE_SYMBOL(___pthread_getspecific, _COMM_PAGE_PTHREAD_GETSPECIFIC)
158 CREATE_COMM_PAGE_SYMBOL(___gettimeofday, _COMM_PAGE_GETTIMEOFDAY)
159 CREATE_COMM_PAGE_SYMBOL(___sys_dcache_flush, _COMM_PAGE_FLUSH_DCACHE)
160 CREATE_COMM_PAGE_SYMBOL(___sys_icache_invalidate, _COMM_PAGE_FLUSH_ICACHE)
161 CREATE_COMM_PAGE_SYMBOL(___pthread_self, _COMM_PAGE_PTHREAD_SELF)
162 CREATE_COMM_PAGE_SYMBOL(___spin_lock_relinquish, _COMM_PAGE_RELINQUISH)
163 CREATE_COMM_PAGE_SYMBOL(___bzero, _COMM_PAGE_BZERO)
164 CREATE_COMM_PAGE_SYMBOL(___bcopy, _COMM_PAGE_BCOPY)
165 CREATE_COMM_PAGE_SYMBOL(___memcpy, _COMM_PAGE_MEMCPY)
166 // CREATE_COMM_PAGE_SYMBOL(___memmove, _COMM_PAGE_MEMMOVE)
167 CREATE_COMM_PAGE_SYMBOL(___bigcopy, _COMM_PAGE_BIGCOPY)
168 CREATE_COMM_PAGE_SYMBOL(___end_comm_page, _COMM_PAGE_END)
169
170 .data // Required to make a well behaved symbol file
171 .long 0 // Required to make a well behaved symbol file
172
173 #endif /* __COMM_PAGE_SYMBOLS */
174 #endif /* __ASSEMBLER__ */
175
176 #endif /* __APPLE_API_PRIVATE */
177 #endif /* _I386_CPU_CAPABILITIES_H */