]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/cpu_capabilities.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_capabilities.h
CommitLineData
43866e37 1/*
cb323159 2 * Copyright (c) 2003-2019 Apple Inc. All rights reserved.
43866e37 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
43866e37 27 */
0a7de745 28#ifdef PRIVATE
43866e37
A
29
30#ifndef _I386_CPU_CAPABILITIES_H
31#define _I386_CPU_CAPABILITIES_H
32
0a7de745 33#ifndef __ASSEMBLER__
91447636
A
34#include <stdint.h>
35#endif
0a7de745 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
0a7de745
A
43#define kHasMMX 0x00000001
44#define kHasSSE 0x00000002
45#define kHasSSE2 0x00000004
46#define kHasSSE3 0x00000008
47#define kCache32 0x00000010 /* cache line size is 32 bytes */
48#define kCache64 0x00000020
49#define kCache128 0x00000040
50#define kFastThreadLocalStorage 0x00000080 /* TLS ptr is kept in a user-mode-readable register */
51#define kHasSupplementalSSE3 0x00000100
52#define k64Bit 0x00000200 /* processor supports EM64T (not what mode you're running in) */
53#define kHasSSE4_1 0x00000400
54#define kHasSSE4_2 0x00000800
55#define kHasAES 0x00001000
56#define kInOrderPipeline 0x00002000
57#define kSlow 0x00004000 /* tsc < nanosecond */
58#define kUP 0x00008000 /* set if (kNumCPUs == 1) */
59#define kNumCPUs 0x00FF0000 /* number of CPUs (see _NumCPUs() below) */
60#define kNumCPUsShift 16
61#define kHasAVX1_0 0x01000000
62#define kHasRDRAND 0x02000000
63#define kHasF16C 0x04000000
64#define kHasENFSTRG 0x08000000
65#define kHasFMA 0x10000000
66#define kHasAVX2_0 0x20000000
67#define kHasBMI1 0x40000000
68#define kHasBMI2 0x80000000
69/* Extending into 64-bits from here: */
70#define kHasRTM 0x0000000100000000ULL
71#define kHasHLE 0x0000000200000000ULL
72#define kHasRDSEED 0x0000000800000000ULL
73#define kHasADX 0x0000000400000000ULL
74#define kHasMPX 0x0000001000000000ULL
75#define kHasSGX 0x0000002000000000ULL
0a7de745
A
76#define kHasAVX512F 0x0000004000000000ULL
77#define kHasAVX512CD 0x0000008000000000ULL
78#define kHasAVX512DQ 0x0000010000000000ULL
79#define kHasAVX512BW 0x0000020000000000ULL
80#define kHasAVX512IFMA 0x0000040000000000ULL
81#define kHasAVX512VBMI 0x0000080000000000ULL
82#define kHasAVX512VL 0x0000100000000000ULL
cb323159
A
83#define kHasVAES 0x0000200000000000ULL
84#define kHasVPCLMULQDQ 0x0000400000000000ULL
85#define kHasAVX512VNNI 0x0000800000000000ULL
86#define kHasAVX512BITALG 0x0001000000000000ULL
87#define kHasAVX512VPOPCNTDQ 0x0002000000000000ULL
bd504ef0 88
f427ee49 89#define kIsTranslated 0x4000000000000000ULL
55e303ae 90
0a7de745 91#ifndef __ASSEMBLER__
91447636 92#include <sys/cdefs.h>
5ba3f43e 93#include <sys/commpage.h>
91447636
A
94
95__BEGIN_DECLS
bd504ef0 96extern uint64_t _get_cpu_capabilities( void );
91447636 97__END_DECLS
55e303ae 98
39037602 99__inline static
0a7de745
A
100int
101_NumCPUs( void )
55e303ae 102{
bd504ef0 103 return (int) (_get_cpu_capabilities() & kNumCPUs) >> kNumCPUsShift;
55e303ae
A
104}
105
106#endif /* __ASSEMBLER__ */
107
6d2010ae
A
108/* The following macro is used to generate the 64-bit commpage address for a given
109 * routine, based on its 32-bit address. This is used in the kernel to compile
110 * the 64-bit commpage. Since the kernel can be a 32-bit object, cpu_capabilities.h
111 * only defines the 32-bit address.
112 */
0a7de745 113#define _COMM_PAGE_32_TO_64( ADDRESS ) ( ADDRESS + _COMM_PAGE64_START_ADDRESS - _COMM_PAGE32_START_ADDRESS )
6d2010ae 114
55e303ae
A
115
116/*
117 * The shared kernel/user "comm page(s)":
118 *
0c530ab8
A
119 * The last several pages of every address space are reserved for the kernel/user
120 * "comm area". During system initialization, the kernel populates the comm pages with
55e303ae
A
121 * code customized for the particular processor and platform.
122 *
0c530ab8 123 * Because Mach VM cannot map the last page of an address space, we don't use it.
55e303ae 124 */
0a7de745
A
125
126#define _COMM_PAGE32_AREA_LENGTH ( 1 * 4096 ) /* reserved length of entire comm area */
127#define _COMM_PAGE32_BASE_ADDRESS ( 0xffff0000 ) /* base address of allocated memory */
128#define _COMM_PAGE32_START_ADDRESS ( _COMM_PAGE32_BASE_ADDRESS ) /* address traditional commpage code starts on */
129#define _COMM_PAGE32_AREA_USED ( 1 * 4096 ) /* this is the amt actually allocated */
130#define _COMM_PAGE32_SIGS_OFFSET 0x8000 /* offset to routine signatures */
131
132#define _COMM_PAGE64_AREA_LENGTH ( 1 * 4096 ) /* reserved length of entire comm area (2MB) */
6d2010ae 133#ifdef __ASSEMBLER__
0a7de745 134#define _COMM_PAGE64_BASE_ADDRESS ( 0x00007fffffe00000 ) /* base address of allocated memory */
6d2010ae 135#else /* __ASSEMBLER__ */
0a7de745 136#define _COMM_PAGE64_BASE_ADDRESS ( 0x00007fffffe00000ULL ) /* base address of allocated memory */
6d2010ae 137#endif /* __ASSEMBLER__ */
0a7de745
A
138#define _COMM_PAGE64_START_ADDRESS ( _COMM_PAGE64_BASE_ADDRESS ) /* address traditional commpage code starts on */
139#define _COMM_PAGE64_AREA_USED ( 1 * 4096 ) /* this is the amt actually populated */
0c530ab8 140
2d21ac55 141/* no need for an Objective-C area on Intel */
0a7de745
A
142#define _COMM_PAGE32_OBJC_SIZE 0ULL
143#define _COMM_PAGE32_OBJC_BASE 0ULL
144#define _COMM_PAGE64_OBJC_SIZE 0ULL
145#define _COMM_PAGE64_OBJC_BASE 0ULL
0c530ab8 146
b0d623f7
A
147#ifdef KERNEL_PRIVATE
148
149/* Inside the kernel, comm page addresses are absolute addresses
150 * assuming they are a part of the 32-bit commpage. They may
151 * be mapped somewhere else, especially for the 64-bit commpage.
152 */
0a7de745
A
153#define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
154#define _COMM_PAGE_SIGS_OFFSET _COMM_PAGE32_SIGS_OFFSET
b0d623f7
A
155
156#else /* !KERNEL_PRIVATE */
157
c3c9b80d
A
158/*
159 * <sys/commpage.h> defines a couple of conveniency macros
160 * to help read data from the commpage.
161 */
0c530ab8
A
162#if defined(__i386__)
163
0a7de745
A
164#define _COMM_PAGE_AREA_LENGTH _COMM_PAGE32_AREA_LENGTH
165#define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE32_BASE_ADDRESS
166#define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_START_ADDRESS
167#define _COMM_PAGE_AREA_USED _COMM_PAGE32_AREA_USED
168#define _COMM_PAGE_SIGS_OFFSET _COMM_PAGE32_SIGS_OFFSET
0c530ab8
A
169
170#elif defined(__x86_64__)
171
0a7de745
A
172#define _COMM_PAGE_AREA_LENGTH _COMM_PAGE64_AREA_LENGTH
173#define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE64_BASE_ADDRESS
174#define _COMM_PAGE_START_ADDRESS _COMM_PAGE64_START_ADDRESS
175#define _COMM_PAGE_AREA_USED _COMM_PAGE64_AREA_USED
0c530ab8
A
176
177#else
178#error architecture not supported
179#endif
0a7de745 180
b0d623f7
A
181#endif /* !KERNEL_PRIVATE */
182
55e303ae 183/* data in the comm page */
0a7de745
A
184
185#define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) /* first 16 bytes are a signature */
186#define _COMM_PAGE_SIGNATURELEN (0x10)
187#define _COMM_PAGE_CPU_CAPABILITIES64 (_COMM_PAGE_START_ADDRESS+0x010) /* uint64_t _cpu_capabilities */
188#define _COMM_PAGE_UNUSED (_COMM_PAGE_START_ADDRESS+0x018) /* 6 unused bytes */
189#define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) /* 16-bit version# */
f427ee49 190#define _COMM_PAGE_THIS_VERSION 14
0a7de745
A
191
192#define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) /* uint32_t _cpu_capabilities (retained for compatibility) */
193#define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) /* uint8_t number of configured CPUs (hw.logicalcpu at boot time) */
194#define _COMM_PAGE_UNUSED0 (_COMM_PAGE_START_ADDRESS+0x024) /* 2 unused bytes, previouly reserved for expansion of cpu_capabilities */
195#define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) /* uint16_t cache line size */
196
f427ee49 197#define _COMM_PAGE_UNUSED4 (_COMM_PAGE_START_ADDRESS+0x028) /* used to be _COMM_PAGE_SCHED_GEN: uint32_t scheduler generation number (count of pre-emptions) */
0a7de745 198#define _COMM_PAGE_MEMORY_PRESSURE (_COMM_PAGE_START_ADDRESS+0x02c) /* uint32_t copy of vm_memory_pressure */
f427ee49 199#define _COMM_PAGE_UNUSED3 (_COMM_PAGE_START_ADDRESS+0x030) /* used to be _COMM_PAGE_SPIN_COUNT: uint32_t max spin count for mutex's */
0a7de745
A
200
201#define _COMM_PAGE_ACTIVE_CPUS (_COMM_PAGE_START_ADDRESS+0x034) /* uint8_t number of active CPUs (hw.activecpu) */
202#define _COMM_PAGE_PHYSICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x035) /* uint8_t number of physical CPUs (hw.physicalcpu_max) */
cb323159 203#define _COMM_PAGE_LOGICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x036) /* uint8_t number of logical CPUs (hw.logicalcpu_max) */
0a7de745
A
204#define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x037) /* 1 unused bytes */
205#define _COMM_PAGE_MEMORY_SIZE (_COMM_PAGE_START_ADDRESS+0x038) /* uint64_t max memory size */
206
207#define _COMM_PAGE_CPUFAMILY (_COMM_PAGE_START_ADDRESS+0x040) /* uint32_t hw.cpufamily, x86*/
208#define _COMM_PAGE_KDEBUG_ENABLE (_COMM_PAGE_START_ADDRESS+0x044) /* uint32_t export "kdebug_enable" to userspace */
209#define _COMM_PAGE_ATM_DIAGNOSTIC_CONFIG (_COMM_PAGE_START_ADDRESS+0x48) /* uint32_t export "atm_diagnostic_config" to userspace */
210
cb323159 211#define _COMM_PAGE_DTRACE_DOF_ENABLED (_COMM_PAGE_START_ADDRESS+0x04C) /* uint8_t 0 if userspace DOF disable, 1 if enabled */
f427ee49
A
212#define _COMM_PAGE_KERNEL_PAGE_SHIFT (_COMM_PAGE_START_ADDRESS+0x04D) /* uint8_t kernel vm page shift. COMM_PAGE_VERSION >= 14 */
213#define _COMM_PAGE_USER_PAGE_SHIFT_64 (_COMM_PAGE_START_ADDRESS+0x04E) /* uint8_t user vm page shift. COMM_PAGE_VERSION >= 14 */
214#define _COMM_PAGE_UNUSED2 (_COMM_PAGE_START_ADDRESS+0x04F) /* 0x4F unused */
0a7de745
A
215
216#define _COMM_PAGE_TIME_DATA_START (_COMM_PAGE_START_ADDRESS+0x050) /* base of offsets below (_NT_SCALE etc) */
217#define _COMM_PAGE_NT_TSC_BASE (_COMM_PAGE_START_ADDRESS+0x050) /* used by nanotime() */
218#define _COMM_PAGE_NT_SCALE (_COMM_PAGE_START_ADDRESS+0x058) /* used by nanotime() */
219#define _COMM_PAGE_NT_SHIFT (_COMM_PAGE_START_ADDRESS+0x05c) /* used by nanotime() */
220#define _COMM_PAGE_NT_NS_BASE (_COMM_PAGE_START_ADDRESS+0x060) /* used by nanotime() */
221#define _COMM_PAGE_NT_GENERATION (_COMM_PAGE_START_ADDRESS+0x068) /* used by nanotime() */
222#define _COMM_PAGE_GTOD_GENERATION (_COMM_PAGE_START_ADDRESS+0x06c) /* used by gettimeofday() */
223#define _COMM_PAGE_GTOD_NS_BASE (_COMM_PAGE_START_ADDRESS+0x070) /* used by gettimeofday() */
224#define _COMM_PAGE_GTOD_SEC_BASE (_COMM_PAGE_START_ADDRESS+0x078) /* used by gettimeofday() */
225
fe8ab488 226/* NOTE: APPROX_TIME must be aligned to 64-byte cache line size: */
0a7de745
A
227#define _COMM_PAGE_APPROX_TIME (_COMM_PAGE_START_ADDRESS+0x080) /* used by mach_approximate_time() */
228#define _COMM_PAGE_APPROX_TIME_SUPPORTED (_COMM_PAGE_START_ADDRESS+0x088) /* used by mach_approximate_time() */
fe8ab488 229
39037602 230/* Align following entries to next cache line */
0a7de745
A
231#define _COMM_PAGE_CONT_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x0C0) /* used by mach_continuous_time() */
232#define _COMM_PAGE_BOOTTIME_USEC (_COMM_PAGE_START_ADDRESS+0x0C8) /* uint64_t boottime */
233#define _COMM_PAGE_NEWTIMEOFDAY_DATA (_COMM_PAGE_START_ADDRESS+0x0D0) /* used by gettimeofday(). Currently, sizeof(new_commpage_timeofday_data_t) = 40 */
2d21ac55 234
cb323159 235/* Resume packed values to the next cacheline */
f427ee49 236#define _COMM_PAGE_DYLD_FLAGS (_COMM_PAGE_START_ADDRESS+0x100) /* uint64_t export kern.dyld_system_flags to userspace */
cb323159 237
0a7de745 238#define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0xfff) /* end of common page */
316670eb 239
2d21ac55
A
240/* Warning: kernel commpage.h has a matching c typedef for the following. They must be kept in sync. */
241/* These offsets are from _COMM_PAGE_TIME_DATA_START */
0c530ab8 242
0a7de745
A
243#define _NT_TSC_BASE 0
244#define _NT_SCALE 8
245#define _NT_SHIFT 12
246#define _NT_NS_BASE 16
247#define _NT_GENERATION 24
248#define _GTOD_GENERATION 28
249#define _GTOD_NS_BASE 32
250#define _GTOD_SEC_BASE 40
251
252/* jump table (jmp to this address, which may be a branch to the actual code somewhere else) */
253/* When new jump table entries are added, corresponding symbols should be added below */
254/* New slots should be allocated with at least 16-byte alignment. Some like bcopy require */
255/* 32-byte alignment, and should be aligned as such in the assembly source before they are relocated */
256#define _COMM_PAGE_TEXT_START (_COMM_PAGE_START_ADDRESS+0x1000)
316670eb 257#define _COMM_PAGE32_TEXT_START (_COMM_PAGE32_BASE_ADDRESS+0x1000) /* start of text section */
0a7de745
A
258#define _COMM_PAGE64_TEXT_START (_COMM_PAGE64_BASE_ADDRESS+0x1000)
259#define _COMM_PAGE_TEXT_AREA_USED ( 1 * 4096 )
260#define _COMM_PAGE_TEXT_AREA_LENGTH ( 1 * 4096 )
261#define _PFZ32_SLIDE_RANGE ( 14 ) /* pages between 0xfffff000 and _COMM_PAGE32_TEXT_START */
262#define _PFZ64_SLIDE_RANGE ( 510 ) /* pages between 0x00007ffffffff000 and _COMM_PAGE64_TEXT_START */
316670eb 263
0a7de745 264/* setup start offset in the commpage text region for each jump table entry
316670eb
A
265 * the Comm Page Offset is shortened to _COMM_TEXT_[label]_OFFSET
266 */
0c530ab8 267
0a7de745
A
268#define _COMM_TEXT_PREEMPT_OFFSET (0x5a0) /* called from withing pfz */
269#define _COMM_TEXT_BACKOFF_OFFSET (0x600) /* called from PFZ */
270#define _COMM_TEXT_RET_OFFSET (0x680) /* called from PFZ */
271#define _COMM_TEXT_PFZ_START_OFFSET (0xc00) /* offset for Preemption Free Zone */
272#define _COMM_TEXT_PFZ_ENQUEUE_OFFSET (0xc00) /* internal FIFO enqueue */
273#define _COMM_TEXT_PFZ_DEQUEUE_OFFSET (0xc80) /* internal FIFO dequeue */
274#define _COMM_TEXT_UNUSED_OFFSET (0xd00) /* end of routines in text page */
275#define _COMM_TEXT_PFZ_END_OFFSET (0xd00) /* offset for end of PFZ */
b0d623f7 276
b0d623f7 277
0a7de745
A
278#define _COMM_PAGE_PREEMPT (_COMM_PAGE_TEXT_START+_COMM_TEXT_PREEMPT_OFFSET)
279#define _COMM_PAGE_BACKOFF (_COMM_PAGE_TEXT_START+_COMM_TEXT_BACKOFF_OFFSET)
280#define _COMM_PAGE_RET (_COMM_PAGE_TEXT_START+_COMM_TEXT_RET_OFFSET)
b0d623f7 281
0a7de745 282#define _COMM_PAGE_PFZ_START (_COMM_PAGE_TEXT_START+_COMM_PAGE_PFZ_START_OFFSET)
b0d623f7 283
0a7de745
A
284#define _COMM_PAGE_PFZ_ENQUEUE (_COMM_PAGE_TEXT_START+_COMM_TEXT_PFZ_ENQUEUE_OFFSET)
285#define _COMM_PAGE_PFZ_DEQUEUE (_COMM_PAGE_TEXT_START+_COMM_TEXT_PFZ_DEQUEUE_OFFSET)
55e303ae 286
0a7de745
A
287#define _COMM_PAGE_UNUSED6 (_COMM_PAGE_TEXT_START+_COMM_TEXT_UNUSED_OFFSET)
288#define _COMM_PAGE_PFZ_END (_COMM_PAGE_TEXT_START+_COMM_TEXT_PFZ_END_OFFSET)
289#define _COMM_PAGE_TEXT_END (_COMM_PAGE_TEXT_START+_COMM_TEXT_PFZ_END_OFFSET) /* end of common text page */
55e303ae 290
0c530ab8
A
291/* _COMM_PAGE_COMPARE_AND_SWAP{32,64}B are not used on x86 and are
292 * maintained here for source compatability. These will be removed at
293 * some point, so don't go relying on them. */
0a7de745
A
294#define _COMM_PAGE_COMPARE_AND_SWAP32B (_COMM_PAGE_START_ADDRESS+0xf80) /* compare-and-swap word w barrier */
295#define _COMM_PAGE_COMPARE_AND_SWAP64B (_COMM_PAGE_START_ADDRESS+0xfc0) /* compare-and-swap doubleword w barrier */
55e303ae 296
f427ee49
A
297/*
298 * _COMM_PAGE_USER_PAGE_SHIFT32 and _COMM_PAGE_USER_PAGE_SHIFT64 are the same on x86.
299 * But both defined to maintain compatability with the arm commpage.
300 */
301#define _COMM_PAGE_USER_PAGE_SHIFT_32 _COMM_PAGE_USER_PAGE_SHIFT_64
302
55e303ae
A
303#ifdef __ASSEMBLER__
304#ifdef __COMM_PAGE_SYMBOLS
305
0a7de745
A
306#define CREATE_COMM_PAGE_SYMBOL(symbol_name, symbol_address) \
307 .org (symbol_address - (_COMM_PAGE_START_ADDRESS & 0xFFFFE000)) ;\
55e303ae
A
308symbol_name: nop
309
0a7de745
A
310.text
311/* Required to make a well behaved symbol file */
55e303ae 312
0a7de745
A
313CREATE_COMM_PAGE_SYMBOL(___preempt, _COMM_PAGE_PREEMPT)
314CREATE_COMM_PAGE_SYMBOL(___backoff, _COMM_PAGE_BACKOFF)
315CREATE_COMM_PAGE_SYMBOL(___pfz_enqueue, _COMM_PAGE_PFZ_ENQUEUE)
316CREATE_COMM_PAGE_SYMBOL(___pfz_dequeue, _COMM_PAGE_PFZ_DEQUEUE)
317CREATE_COMM_PAGE_SYMBOL(___end_comm_page, _COMM_PAGE_END)
55e303ae 318
0a7de745
A
319.data /* Required to make a well behaved symbol file */
320.long 0 /* Required to make a well behaved symbol file */
55e303ae
A
321
322#endif /* __COMM_PAGE_SYMBOLS */
323#endif /* __ASSEMBLER__ */
43866e37 324
43866e37 325#endif /* _I386_CPU_CAPABILITIES_H */
91447636 326#endif /* PRIVATE */