]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
0a7de745 | 2 | * Copyright (c) 2000-2019 Apple Inc. All rights reserved. |
1c79356b | 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@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* CMU_ENDHIST */ | |
0a7de745 | 32 | /* |
1c79356b A |
33 | * Mach Operating System |
34 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
35 | * All Rights Reserved. | |
0a7de745 | 36 | * |
1c79356b A |
37 | * Permission to use, copy, modify and distribute this software and its |
38 | * documentation is hereby granted, provided that both the copyright | |
39 | * notice and this permission notice appear in all copies of the | |
40 | * software, derivative works or modified versions, and any portions | |
41 | * thereof, and that both notices appear in supporting documentation. | |
0a7de745 | 42 | * |
1c79356b A |
43 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
44 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
45 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
0a7de745 | 46 | * |
1c79356b | 47 | * Carnegie Mellon requests users of this software to return to |
0a7de745 | 48 | * |
1c79356b A |
49 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
50 | * School of Computer Science | |
51 | * Carnegie Mellon University | |
52 | * Pittsburgh PA 15213-3890 | |
0a7de745 | 53 | * |
1c79356b A |
54 | * any improvements or extensions that they make and grant Carnegie Mellon |
55 | * the rights to redistribute these changes. | |
56 | */ | |
57 | ||
58 | /* | |
59 | */ | |
60 | ||
61 | /* | |
62 | * Processor registers for i386 and i486. | |
63 | */ | |
0a7de745 A |
64 | #ifndef _I386_PROC_REG_H_ |
65 | #define _I386_PROC_REG_H_ | |
1c79356b A |
66 | |
67 | /* | |
68 | * Model Specific Registers | |
69 | */ | |
0a7de745 A |
70 | #define MSR_P5_TSC 0x10 /* Time Stamp Register */ |
71 | #define MSR_P5_CESR 0x11 /* Control and Event Select Register */ | |
72 | #define MSR_P5_CTR0 0x12 /* Counter #0 */ | |
73 | #define MSR_P5_CTR1 0x13 /* Counter #1 */ | |
74 | ||
75 | #define MSR_P5_CESR_PC 0x0200 /* Pin Control */ | |
76 | #define MSR_P5_CESR_CC 0x01C0 /* Counter Control mask */ | |
77 | #define MSR_P5_CESR_ES 0x003F /* Event Control mask */ | |
78 | ||
79 | #define MSR_P5_CESR_SHIFT 16 /* Shift to get Counter 1 */ | |
80 | #define MSR_P5_CESR_MASK (MSR_P5_CESR_PC|\ | |
81 | MSR_P5_CESR_CC|\ | |
82 | MSR_P5_CESR_ES) /* Mask Counter */ | |
83 | ||
84 | #define MSR_P5_CESR_CC_CLOCK 0x0100 /* Clock Counting (otherwise Event) */ | |
85 | #define MSR_P5_CESR_CC_DISABLE 0x0000 /* Disable counter */ | |
86 | #define MSR_P5_CESR_CC_CPL012 0x0040 /* Count if the CPL == 0, 1, 2 */ | |
87 | #define MSR_P5_CESR_CC_CPL3 0x0080 /* Count if the CPL == 3 */ | |
88 | #define MSR_P5_CESR_CC_CPL 0x00C0 /* Count regardless of the CPL */ | |
89 | ||
90 | #define MSR_P5_CESR_ES_DATA_READ 0x000000 /* Data Read */ | |
91 | #define MSR_P5_CESR_ES_DATA_WRITE 0x000001 /* Data Write */ | |
92 | #define MSR_P5_CESR_ES_DATA_RW 0x101000 /* Data Read or Write */ | |
93 | #define MSR_P5_CESR_ES_DATA_TLB_MISS 0x000010 /* Data TLB Miss */ | |
94 | #define MSR_P5_CESR_ES_DATA_READ_MISS 0x000011 /* Data Read Miss */ | |
95 | #define MSR_P5_CESR_ES_DATA_WRITE_MISS 0x000100 /* Data Write Miss */ | |
96 | #define MSR_P5_CESR_ES_DATA_RW_MISS 0x101001 /* Data Read or Write Miss */ | |
97 | #define MSR_P5_CESR_ES_HIT_EM 0x000101 /* Write (hit) to M|E state */ | |
98 | #define MSR_P5_CESR_ES_DATA_CACHE_WB 0x000110 /* Cache lines written back */ | |
99 | #define MSR_P5_CESR_ES_EXTERNAL_SNOOP 0x000111 /* External Snoop */ | |
100 | #define MSR_P5_CESR_ES_CACHE_SNOOP_HIT 0x001000 /* Data cache snoop hits */ | |
101 | #define MSR_P5_CESR_ES_MEM_ACCESS_PIPE 0x001001 /* Mem. access in both pipes */ | |
102 | #define MSR_P5_CESR_ES_BANK_CONFLICTS 0x001010 /* Bank conflicts */ | |
103 | #define MSR_P5_CESR_ES_MISALIGNED 0x001011 /* Misaligned Memory or I/O */ | |
104 | #define MSR_P5_CESR_ES_CODE_READ 0x001100 /* Code Read */ | |
105 | #define MSR_P5_CESR_ES_CODE_TLB_MISS 0x001101 /* Code TLB miss */ | |
106 | #define MSR_P5_CESR_ES_CODE_CACHE_MISS 0x001110 /* Code Cache miss */ | |
107 | #define MSR_P5_CESR_ES_SEGMENT_LOADED 0x001111 /* Any segment reg. loaded */ | |
108 | #define MSR_P5_CESR_ES_BRANCHE 0x010010 /* Branches */ | |
109 | #define MSR_P5_CESR_ES_BTB_HIT 0x010011 /* BTB Hits */ | |
110 | #define MSR_P5_CESR_ES_BRANCHE_BTB 0x010100 /* Taken branch or BTB Hit */ | |
111 | #define MSR_P5_CESR_ES_PIPELINE_FLUSH 0x010101 /* Pipeline Flushes */ | |
112 | #define MSR_P5_CESR_ES_INSTRUCTION 0x010110 /* Instruction executed */ | |
113 | #define MSR_P5_CESR_ES_INSTRUCTION_V 0x010111 /* Inst. executed (v-pipe) */ | |
114 | #define MSR_P5_CESR_ES_BUS_CYCLE 0x011000 /* Clocks while bus cycle */ | |
115 | #define MSR_P5_CESR_ES_FULL_WRITE_BUF 0x011001 /* Clocks while full wrt buf. */ | |
116 | #define MSR_P5_CESR_ES_DATA_MEM_READ 0x011010 /* Pipeline waiting for read */ | |
117 | #define MSR_P5_CESR_ES_WRITE_EM 0x011011 /* Stall on write E|M state */ | |
118 | #define MSR_P5_CESR_ES_LOCKED_CYCLE 0x011100 /* Locked bus cycles */ | |
119 | #define MSR_P5_CESR_ES_IO_CYCLE 0x011101 /* I/O Read or Write cycles */ | |
120 | #define MSR_P5_CESR_ES_NON_CACHEABLE 0x011110 /* Non-cacheable Mem. read */ | |
121 | #define MSR_P5_CESR_ES_AGI 0x011111 /* Stall because of AGI */ | |
122 | #define MSR_P5_CESR_ES_FLOP 0x100010 /* Floating Point operations */ | |
123 | #define MSR_P5_CESR_ES_BREAK_DR0 0x100011 /* Breakpoint matches on DR0 */ | |
124 | #define MSR_P5_CESR_ES_BREAK_DR1 0x100100 /* Breakpoint matches on DR1 */ | |
125 | #define MSR_P5_CESR_ES_BREAK_DR2 0x100101 /* Breakpoint matches on DR2 */ | |
126 | #define MSR_P5_CESR_ES_BREAK_DR3 0x100110 /* Breakpoint matches on DR3 */ | |
127 | #define MSR_P5_CESR_ES_HARDWARE_IT 0x100111 /* Hardware interrupts */ | |
1c79356b A |
128 | |
129 | /* | |
130 | * CR0 | |
131 | */ | |
0a7de745 A |
132 | #define CR0_PG 0x80000000 /* Enable paging */ |
133 | #define CR0_CD 0x40000000 /* i486: Cache disable */ | |
134 | #define CR0_NW 0x20000000 /* i486: No write-through */ | |
135 | #define CR0_AM 0x00040000 /* i486: Alignment check mask */ | |
136 | #define CR0_WP 0x00010000 /* i486: Write-protect kernel access */ | |
137 | #define CR0_NE 0x00000020 /* i486: Handle numeric exceptions */ | |
138 | #define CR0_ET 0x00000010 /* Extension type is 80387 */ | |
139 | /* (not official) */ | |
140 | #define CR0_TS 0x00000008 /* Task switch */ | |
141 | #define CR0_EM 0x00000004 /* Emulate coprocessor */ | |
142 | #define CR0_MP 0x00000002 /* Monitor coprocessor */ | |
143 | #define CR0_PE 0x00000001 /* Enable protected mode */ | |
1c79356b A |
144 | |
145 | /* | |
146 | * CR4 | |
147 | */ | |
0a7de745 A |
148 | #define CR4_SEE 0x00008000 /* Secure Enclave Enable XXX */ |
149 | #define CR4_SMAP 0x00200000 /* Supervisor-Mode Access Protect */ | |
150 | #define CR4_SMEP 0x00100000 /* Supervisor-Mode Execute Protect */ | |
151 | #define CR4_OSXSAVE 0x00040000 /* OS supports XSAVE */ | |
152 | #define CR4_PCIDE 0x00020000 /* PCID Enable */ | |
153 | #define CR4_RDWRFSGS 0x00010000 /* RDWRFSGS Enable */ | |
154 | #define CR4_SMXE 0x00004000 /* Enable SMX operation */ | |
155 | #define CR4_VMXE 0x00002000 /* Enable VMX operation */ | |
156 | #define CR4_OSXMM 0x00000400 /* SSE/SSE2 exception support in OS */ | |
157 | #define CR4_OSFXS 0x00000200 /* SSE/SSE2 OS supports FXSave */ | |
158 | #define CR4_PCE 0x00000100 /* Performance-Monitor Count Enable */ | |
159 | #define CR4_PGE 0x00000080 /* Page Global Enable */ | |
160 | #define CR4_MCE 0x00000040 /* Machine Check Exceptions */ | |
161 | #define CR4_PAE 0x00000020 /* Physical Address Extensions */ | |
162 | #define CR4_PSE 0x00000010 /* Page Size Extensions */ | |
163 | #define CR4_DE 0x00000008 /* Debugging Extensions */ | |
164 | #define CR4_TSD 0x00000004 /* Time Stamp Disable */ | |
165 | #define CR4_PVI 0x00000002 /* Protected-mode Virtual Interrupts */ | |
166 | #define CR4_VME 0x00000001 /* Virtual-8086 Mode Extensions */ | |
1c79356b | 167 | |
060df5ea A |
168 | /* |
169 | * XCR0 - XFEATURE_ENABLED_MASK (a.k.a. XFEM) register | |
170 | */ | |
0a7de745 A |
171 | #define XCR0_X87 (1ULL << 0) /* x87, FPU/MMX (always set) */ |
172 | #define XCR0_SSE (1ULL << 1) /* SSE supported by XSAVE/XRESTORE */ | |
173 | #define XCR0_YMM (1ULL << 2) /* YMM state available */ | |
174 | #define XCR0_BNDREGS (1ULL << 3) /* MPX Bounds register state */ | |
175 | #define XCR0_BNDCSR (1ULL << 4) /* MPX Bounds configuration/state */ | |
5ba3f43e | 176 | #if !defined(RC_HIDE_XNU_J137) |
0a7de745 A |
177 | #define XCR0_OPMASK (1ULL << 5) /* Opmask register state */ |
178 | #define XCR0_ZMM_HI256 (1ULL << 6) /* ZMM upper 256-bit state */ | |
179 | #define XCR0_HI16_ZMM (1ULL << 7) /* ZMM16..ZMM31 512-bit state */ | |
5ba3f43e | 180 | #endif /* not RC_HIDE_XNU_J137 */ |
0a7de745 A |
181 | #define XFEM_X87 XCR0_X87 |
182 | #define XFEM_SSE XCR0_SSE | |
183 | #define XFEM_YMM XCR0_YMM | |
184 | #define XFEM_BNDREGS XCR0_BNDREGS | |
185 | #define XFEM_BNDCSR XCR0_BNDCSR | |
5ba3f43e | 186 | #if !defined(XNU_HODE_J137) |
0a7de745 A |
187 | #define XFEM_OPMASK XCR0_OPMASK |
188 | #define XFEM_ZMM_HI256 XCR0_ZMM_HI256 | |
189 | #define XFEM_HI16_ZMM XCR0_HI16_ZMM | |
190 | #define XFEM_ZMM (XFEM_ZMM_HI256 | XFEM_HI16_ZMM | XFEM_OPMASK) | |
5ba3f43e | 191 | #endif /* not XNU_HODE_J137 */ |
060df5ea | 192 | #define XCR0 (0) |
6d2010ae | 193 | |
0a7de745 A |
194 | #define PMAP_PCID_PRESERVE (1ULL << 63) |
195 | #define PMAP_PCID_MASK (0xFFF) | |
196 | ||
197 | #define EARLY_GSBASE_MAGIC 0xffffdeadbeefee00 | |
316670eb | 198 | |
5ba3f43e A |
199 | /* |
200 | * If thread groups are needed for x86, set this to 1 | |
201 | */ | |
202 | #define CONFIG_THREAD_GROUPS 0 | |
203 | ||
0a7de745 | 204 | #ifndef ASSEMBLER |
91447636 A |
205 | |
206 | #include <sys/cdefs.h> | |
b0d623f7 A |
207 | #include <stdint.h> |
208 | ||
91447636 | 209 | __BEGIN_DECLS |
1c79356b | 210 | |
0a7de745 | 211 | #define set_ts() set_cr0(get_cr0() | CR0_TS) |
1c79356b | 212 | |
0a7de745 A |
213 | static inline uint16_t |
214 | get_es(void) | |
6d2010ae A |
215 | { |
216 | uint16_t es; | |
0a7de745 | 217 | __asm__ volatile ("mov %%es, %0" : "=r" (es)); |
6d2010ae A |
218 | return es; |
219 | } | |
220 | ||
0a7de745 A |
221 | static inline void |
222 | set_es(uint16_t es) | |
6d2010ae | 223 | { |
0a7de745 | 224 | __asm__ volatile ("mov %0, %%es" : : "r" (es)); |
6d2010ae A |
225 | } |
226 | ||
0a7de745 A |
227 | static inline uint16_t |
228 | get_ds(void) | |
6d2010ae A |
229 | { |
230 | uint16_t ds; | |
0a7de745 | 231 | __asm__ volatile ("mov %%ds, %0" : "=r" (ds)); |
6d2010ae A |
232 | return ds; |
233 | } | |
234 | ||
0a7de745 A |
235 | static inline void |
236 | set_ds(uint16_t ds) | |
6d2010ae | 237 | { |
0a7de745 | 238 | __asm__ volatile ("mov %0, %%ds" : : "r" (ds)); |
6d2010ae A |
239 | } |
240 | ||
0a7de745 A |
241 | static inline uint16_t |
242 | get_fs(void) | |
6d2010ae A |
243 | { |
244 | uint16_t fs; | |
0a7de745 | 245 | __asm__ volatile ("mov %%fs, %0" : "=r" (fs)); |
6d2010ae A |
246 | return fs; |
247 | } | |
248 | ||
0a7de745 A |
249 | static inline void |
250 | set_fs(uint16_t fs) | |
6d2010ae | 251 | { |
0a7de745 | 252 | __asm__ volatile ("mov %0, %%fs" : : "r" (fs)); |
6d2010ae A |
253 | } |
254 | ||
0a7de745 A |
255 | static inline uint16_t |
256 | get_gs(void) | |
6d2010ae A |
257 | { |
258 | uint16_t gs; | |
0a7de745 | 259 | __asm__ volatile ("mov %%gs, %0" : "=r" (gs)); |
6d2010ae A |
260 | return gs; |
261 | } | |
262 | ||
0a7de745 A |
263 | static inline void |
264 | set_gs(uint16_t gs) | |
6d2010ae | 265 | { |
0a7de745 | 266 | __asm__ volatile ("mov %0, %%gs" : : "r" (gs)); |
6d2010ae A |
267 | } |
268 | ||
0a7de745 A |
269 | static inline uint16_t |
270 | get_ss(void) | |
6d2010ae A |
271 | { |
272 | uint16_t ss; | |
0a7de745 | 273 | __asm__ volatile ("mov %%ss, %0" : "=r" (ss)); |
6d2010ae A |
274 | return ss; |
275 | } | |
276 | ||
0a7de745 A |
277 | static inline void |
278 | set_ss(uint16_t ss) | |
6d2010ae | 279 | { |
0a7de745 | 280 | __asm__ volatile ("mov %0, %%ss" : : "r" (ss)); |
6d2010ae A |
281 | } |
282 | ||
0a7de745 A |
283 | static inline uintptr_t |
284 | get_cr0(void) | |
1c79356b | 285 | { |
0a7de745 A |
286 | uintptr_t cr0; |
287 | __asm__ volatile ("mov %%cr0, %0" : "=r" (cr0)); | |
288 | return cr0; | |
1c79356b A |
289 | } |
290 | ||
0a7de745 A |
291 | static inline void |
292 | set_cr0(uintptr_t value) | |
1c79356b | 293 | { |
0a7de745 | 294 | __asm__ volatile ("mov %0, %%cr0" : : "r" (value)); |
1c79356b A |
295 | } |
296 | ||
0a7de745 A |
297 | static inline uintptr_t |
298 | get_cr2(void) | |
1c79356b | 299 | { |
b0d623f7 | 300 | uintptr_t cr2; |
0a7de745 A |
301 | __asm__ volatile ("mov %%cr2, %0" : "=r" (cr2)); |
302 | return cr2; | |
1c79356b A |
303 | } |
304 | ||
0a7de745 A |
305 | static inline uintptr_t |
306 | get_cr3_raw(void) | |
6d2010ae | 307 | { |
3e170ce0 | 308 | uintptr_t cr3; |
0a7de745 A |
309 | __asm__ volatile ("mov %%cr3, %0" : "=r" (cr3)); |
310 | return cr3; | |
6d2010ae A |
311 | } |
312 | ||
0a7de745 A |
313 | static inline void |
314 | set_cr3_raw(uintptr_t value) | |
6d2010ae | 315 | { |
0a7de745 | 316 | __asm__ volatile ("mov %0, %%cr3" : : "r" (value)); |
6d2010ae A |
317 | } |
318 | ||
0a7de745 A |
319 | static inline uintptr_t |
320 | get_cr3_base(void) | |
6d2010ae | 321 | { |
3e170ce0 | 322 | uintptr_t cr3; |
0a7de745 A |
323 | __asm__ volatile ("mov %%cr3, %0" : "=r" (cr3)); |
324 | return cr3 & ~(0xFFFULL); | |
6d2010ae A |
325 | } |
326 | ||
0a7de745 A |
327 | static inline void |
328 | set_cr3_composed(uintptr_t base, uint16_t pcid, uint64_t preserve) | |
6d2010ae | 329 | { |
0a7de745 | 330 | __asm__ volatile ("mov %0, %%cr3" : : "r" (base | pcid | ( (preserve) << 63) )); |
6d2010ae | 331 | } |
1c79356b | 332 | |
0a7de745 A |
333 | static inline uintptr_t |
334 | get_cr4(void) | |
0c530ab8 | 335 | { |
b0d623f7 | 336 | uintptr_t cr4; |
0a7de745 A |
337 | __asm__ volatile ("mov %%cr4, %0" : "=r" (cr4)); |
338 | return cr4; | |
0c530ab8 A |
339 | } |
340 | ||
0a7de745 A |
341 | static inline void |
342 | set_cr4(uintptr_t value) | |
0c530ab8 | 343 | { |
0a7de745 | 344 | __asm__ volatile ("mov %0, %%cr4" : : "r" (value)); |
0c530ab8 | 345 | } |
91447636 | 346 | |
0a7de745 A |
347 | static inline uintptr_t |
348 | x86_get_flags(void) | |
6d2010ae A |
349 | { |
350 | uintptr_t erflags; | |
0a7de745 | 351 | __asm__ volatile ("pushf; pop %0" : "=r" (erflags)); |
6d2010ae A |
352 | return erflags; |
353 | } | |
354 | ||
0a7de745 A |
355 | static inline void |
356 | clear_ts(void) | |
1c79356b | 357 | { |
0a7de745 | 358 | __asm__ volatile ("clts"); |
1c79356b A |
359 | } |
360 | ||
0a7de745 A |
361 | static inline unsigned short |
362 | get_tr(void) | |
1c79356b | 363 | { |
0a7de745 A |
364 | unsigned short seg; |
365 | __asm__ volatile ("str %0" : "=rm" (seg)); | |
366 | return seg; | |
1c79356b A |
367 | } |
368 | ||
0a7de745 A |
369 | static inline void |
370 | set_tr(unsigned int seg) | |
1c79356b | 371 | { |
0a7de745 | 372 | __asm__ volatile ("ltr %0" : : "rm" ((unsigned short)(seg))); |
1c79356b A |
373 | } |
374 | ||
0a7de745 A |
375 | static inline unsigned short |
376 | sldt(void) | |
1c79356b A |
377 | { |
378 | unsigned short seg; | |
0a7de745 A |
379 | __asm__ volatile ("sldt %0" : "=rm" (seg)); |
380 | return seg; | |
1c79356b A |
381 | } |
382 | ||
0a7de745 A |
383 | static inline void |
384 | lldt(unsigned int seg) | |
1c79356b | 385 | { |
0a7de745 | 386 | __asm__ volatile ("lldt %0" : : "rm" ((unsigned short)(seg))); |
1c79356b A |
387 | } |
388 | ||
0a7de745 A |
389 | static inline void |
390 | lgdt(uintptr_t *desc) | |
b0d623f7 | 391 | { |
0a7de745 | 392 | __asm__ volatile ("lgdt %0" : : "m" (*desc)); |
b0d623f7 A |
393 | } |
394 | ||
0a7de745 A |
395 | static inline void |
396 | lidt(uintptr_t *desc) | |
b0d623f7 | 397 | { |
0a7de745 | 398 | __asm__ volatile ("lidt %0" : : "m" (*desc)); |
b0d623f7 A |
399 | } |
400 | ||
0a7de745 A |
401 | static inline void |
402 | swapgs(void) | |
b0d623f7 | 403 | { |
0a7de745 | 404 | __asm__ volatile ("swapgs"); |
b0d623f7 A |
405 | } |
406 | ||
0a7de745 A |
407 | static inline void |
408 | hlt(void) | |
5ba3f43e | 409 | { |
0a7de745 | 410 | __asm__ volatile ("hlt"); |
5ba3f43e A |
411 | } |
412 | ||
0c530ab8 | 413 | #ifdef MACH_KERNEL_PRIVATE |
b0d623f7 | 414 | |
bd504ef0 A |
415 | extern int rdmsr64_carefully(uint32_t msr, uint64_t *val); |
416 | extern int wrmsr64_carefully(uint32_t msr, uint64_t val); | |
0a7de745 | 417 | #endif /* MACH_KERNEL_PRIVATE */ |
1c79356b | 418 | |
0a7de745 A |
419 | static inline void |
420 | wbinvd(void) | |
91447636 | 421 | { |
0a7de745 | 422 | __asm__ volatile ("wbinvd"); |
91447636 A |
423 | } |
424 | ||
0a7de745 A |
425 | static inline void |
426 | invlpg(uintptr_t addr) | |
1c79356b | 427 | { |
0a7de745 | 428 | __asm__ volatile ("invlpg (%0)" :: "r" (addr) : "memory"); |
1c79356b | 429 | } |
55e303ae | 430 | |
0a7de745 A |
431 | static inline void |
432 | clac(void) | |
04b8595b | 433 | { |
0a7de745 | 434 | __asm__ volatile ("clac"); |
04b8595b A |
435 | } |
436 | ||
0a7de745 A |
437 | static inline void |
438 | stac(void) | |
04b8595b | 439 | { |
0a7de745 | 440 | __asm__ volatile ("stac"); |
04b8595b A |
441 | } |
442 | ||
55e303ae A |
443 | /* |
444 | * Access to machine-specific registers (available on 586 and better only) | |
445 | * Note: the rd* operations modify the parameters directly (without using | |
446 | * pointer indirection), this allows gcc to optimize better | |
447 | */ | |
448 | ||
0a7de745 | 449 | #define rdmsr(msr, lo, hi) \ |
55e303ae A |
450 | __asm__ volatile("rdmsr" : "=a" (lo), "=d" (hi) : "c" (msr)) |
451 | ||
0a7de745 | 452 | #define wrmsr(msr, lo, hi) \ |
55e303ae A |
453 | __asm__ volatile("wrmsr" : : "c" (msr), "a" (lo), "d" (hi)) |
454 | ||
0a7de745 A |
455 | #define rdtsc(lo, hi) \ |
456 | __asm__ volatile("lfence; rdtsc" : "=a" (lo), "=d" (hi)) | |
55e303ae | 457 | |
0a7de745 | 458 | #define rdtsc_nofence(lo, hi) \ |
fe8ab488 A |
459 | __asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi)) |
460 | ||
0a7de745 | 461 | #define write_tsc(lo, hi) wrmsr(0x10, lo, hi) |
55e303ae | 462 | |
0a7de745 | 463 | #define rdpmc(counter, lo, hi) \ |
55e303ae A |
464 | __asm__ volatile("rdpmc" : "=a" (lo), "=d" (hi) : "c" (counter)) |
465 | ||
39236c6e A |
466 | #ifdef XNU_KERNEL_PRIVATE |
467 | extern void do_mfence(void); | |
468 | #define mfence() do_mfence() | |
469 | #endif | |
55e303ae | 470 | |
5ba3f43e | 471 | #ifdef __LP64__ |
0a7de745 A |
472 | static inline uint64_t |
473 | rdpmc64(uint32_t pmc) | |
55e303ae | 474 | { |
0a7de745 | 475 | uint32_t lo = 0, hi = 0; |
39236c6e A |
476 | rdpmc(pmc, lo, hi); |
477 | return (((uint64_t)hi) << 32) | ((uint64_t)lo); | |
55e303ae | 478 | } |
91447636 | 479 | |
0a7de745 A |
480 | static inline uint64_t |
481 | rdmsr64(uint32_t msr) | |
b0d623f7 | 482 | { |
0a7de745 | 483 | uint32_t lo = 0, hi = 0; |
b0d623f7 A |
484 | rdmsr(msr, lo, hi); |
485 | return (((uint64_t)hi) << 32) | ((uint64_t)lo); | |
486 | } | |
487 | ||
0a7de745 A |
488 | static inline void |
489 | wrmsr64(uint32_t msr, uint64_t val) | |
b0d623f7 A |
490 | { |
491 | wrmsr(msr, (val & 0xFFFFFFFFUL), ((val >> 32) & 0xFFFFFFFFUL)); | |
492 | } | |
493 | ||
0a7de745 A |
494 | static inline uint64_t |
495 | rdtsc64(void) | |
b0d623f7 | 496 | { |
6d2010ae | 497 | uint64_t lo, hi; |
b0d623f7 | 498 | rdtsc(lo, hi); |
6d2010ae | 499 | return ((hi) << 32) | (lo); |
b0d623f7 A |
500 | } |
501 | ||
0a7de745 A |
502 | static inline uint64_t |
503 | rdtscp64(uint32_t *aux) | |
b0d623f7 | 504 | { |
6d2010ae | 505 | uint64_t lo, hi; |
0a7de745 A |
506 | __asm__ volatile ("rdtscp; mov %%ecx, %1" |
507 | : "=a" (lo), "=d" (hi), "=m" (*aux) | |
508 | : | |
509 | : "ecx"); | |
6d2010ae | 510 | return ((hi) << 32) | (lo); |
b0d623f7 | 511 | } |
5ba3f43e | 512 | #endif /* __LP64__ */ |
b0d623f7 | 513 | |
91447636 A |
514 | /* |
515 | * rdmsr_carefully() returns 0 when the MSR has been read successfully, | |
516 | * or non-zero (1) if the MSR does not exist. | |
517 | * The implementation is in locore.s. | |
518 | */ | |
519 | extern int rdmsr_carefully(uint32_t msr, uint32_t *lo, uint32_t *hi); | |
91447636 A |
520 | __END_DECLS |
521 | ||
0a7de745 A |
522 | #endif /* ASSEMBLER */ |
523 | ||
524 | #define MSR_IA32_P5_MC_ADDR 0 | |
525 | #define MSR_IA32_P5_MC_TYPE 1 | |
526 | #define MSR_IA32_PLATFORM_ID 0x17 | |
527 | #define MSR_IA32_EBL_CR_POWERON 0x2a | |
528 | ||
529 | #define MSR_IA32_APIC_BASE 0x1b | |
530 | #define MSR_IA32_APIC_BASE_BSP (1<<8) | |
531 | #define MSR_IA32_APIC_BASE_EXTENDED (1<<10) | |
532 | #define MSR_IA32_APIC_BASE_ENABLE (1<<11) | |
533 | #define MSR_IA32_APIC_BASE_BASE (0xfffff<<12) | |
534 | ||
535 | #define MSR_CORE_THREAD_COUNT 0x35 | |
536 | ||
537 | #define MSR_IA32_FEATURE_CONTROL 0x3a | |
538 | #define MSR_IA32_FEATCTL_LOCK (1<<0) | |
539 | #define MSR_IA32_FEATCTL_VMXON_SMX (1<<1) | |
540 | #define MSR_IA32_FEATCTL_VMXON (1<<2) | |
541 | #define MSR_IA32_FEATCTL_CSTATE_SMI (1<<16) | |
542 | ||
543 | #define MSR_IA32_UPDT_TRIG 0x79 | |
544 | #define MSR_IA32_BIOS_SIGN_ID 0x8b | |
545 | #define MSR_IA32_UCODE_WRITE MSR_IA32_UPDT_TRIG | |
546 | #define MSR_IA32_UCODE_REV MSR_IA32_BIOS_SIGN_ID | |
547 | ||
548 | #define MSR_IA32_PERFCTR0 0xc1 | |
549 | #define MSR_IA32_PERFCTR1 0xc2 | |
550 | #define MSR_IA32_PERFCTR3 0xc3 | |
551 | #define MSR_IA32_PERFCTR4 0xc4 | |
552 | ||
553 | #define MSR_PLATFORM_INFO 0xce | |
554 | ||
555 | #define MSR_IA32_MPERF 0xE7 | |
556 | #define MSR_IA32_APERF 0xE8 | |
557 | ||
558 | #define MSR_IA32_ARCH_CAPABILITIES 0x10a | |
559 | #define MSR_IA32_ARCH_CAPABILITIES_RDCL_NO (1ULL << 0) | |
560 | #define MSR_IA32_ARCH_CAPABILITIES_IBRS_ALL (1ULL << 1) | |
561 | #define MSR_IA32_ARCH_CAPABILITIES_RSBA (1ULL << 2) | |
562 | #define MSR_IA32_ARCH_CAPABILITIES_L1DF_NO (1ULL << 3) | |
563 | #define MSR_IA32_ARCH_CAPABILITIES_SSB_NO (1ULL << 4) | |
564 | #define MSR_IA32_ARCH_CAPABILITIES_MDS_NO (1ULL << 5) | |
565 | ||
566 | #define MSR_IA32_TSX_FORCE_ABORT 0x10f | |
567 | #define MSR_IA32_TSXFA_RTM_FORCE_ABORT (1ULL << 0) /* Bit 0 */ | |
568 | ||
569 | #define MSR_IA32_BBL_CR_CTL 0x119 | |
570 | ||
94ff46dc | 571 | |
0a7de745 A |
572 | #define MSR_IA32_SYSENTER_CS 0x174 |
573 | #define MSR_IA32_SYSENTER_ESP 0x175 | |
574 | #define MSR_IA32_SYSENTER_EIP 0x176 | |
575 | ||
576 | #define MSR_IA32_MCG_CAP 0x179 | |
577 | #define MSR_IA32_MCG_STATUS 0x17a | |
578 | #define MSR_IA32_MCG_CTL 0x17b | |
579 | ||
580 | #define MSR_IA32_EVNTSEL0 0x186 | |
581 | #define MSR_IA32_EVNTSEL1 0x187 | |
582 | #define MSR_IA32_EVNTSEL2 0x188 | |
583 | #define MSR_IA32_EVNTSEL3 0x189 | |
584 | ||
585 | #define MSR_FLEX_RATIO 0x194 | |
586 | #define MSR_IA32_PERF_STS 0x198 | |
587 | #define MSR_IA32_PERF_CTL 0x199 | |
588 | #define MSR_IA32_CLOCK_MODULATION 0x19a | |
589 | ||
590 | #define MSR_IA32_MISC_ENABLE 0x1a0 | |
591 | ||
592 | ||
593 | #define MSR_IA32_PACKAGE_THERM_STATUS 0x1b1 | |
594 | #define MSR_IA32_PACKAGE_THERM_INTERRUPT 0x1b2 | |
595 | ||
596 | #define MSR_IA32_DEBUGCTLMSR 0x1d9 | |
597 | #define MSR_IA32_LASTBRANCHFROMIP 0x1db | |
598 | #define MSR_IA32_LASTBRANCHTOIP 0x1dc | |
599 | #define MSR_IA32_LASTINTFROMIP 0x1dd | |
600 | #define MSR_IA32_LASTINTTOIP 0x1de | |
601 | ||
602 | #define MSR_IA32_CR_PAT 0x277 | |
603 | ||
604 | #define MSR_IA32_MTRRCAP 0xfe | |
605 | #define MSR_IA32_MTRR_DEF_TYPE 0x2ff | |
606 | #define MSR_IA32_MTRR_PHYSBASE(n) (0x200 + 2*(n)) | |
607 | #define MSR_IA32_MTRR_PHYSMASK(n) (0x200 + 2*(n) + 1) | |
608 | #define MSR_IA32_MTRR_FIX64K_00000 0x250 | |
609 | #define MSR_IA32_MTRR_FIX16K_80000 0x258 | |
610 | #define MSR_IA32_MTRR_FIX16K_A0000 0x259 | |
611 | #define MSR_IA32_MTRR_FIX4K_C0000 0x268 | |
612 | #define MSR_IA32_MTRR_FIX4K_C8000 0x269 | |
613 | #define MSR_IA32_MTRR_FIX4K_D0000 0x26a | |
614 | #define MSR_IA32_MTRR_FIX4K_D8000 0x26b | |
615 | #define MSR_IA32_MTRR_FIX4K_E0000 0x26c | |
616 | #define MSR_IA32_MTRR_FIX4K_E8000 0x26d | |
617 | #define MSR_IA32_MTRR_FIX4K_F0000 0x26e | |
618 | #define MSR_IA32_MTRR_FIX4K_F8000 0x26f | |
619 | ||
620 | #define MSR_IA32_PERF_FIXED_CTR0 0x309 | |
621 | ||
622 | #define MSR_IA32_PERF_FIXED_CTR_CTRL 0x38D | |
623 | #define MSR_IA32_PERF_GLOBAL_STATUS 0x38E | |
624 | #define MSR_IA32_PERF_GLOBAL_CTRL 0x38F | |
625 | #define MSR_IA32_PERF_GLOBAL_OVF_CTRL 0x390 | |
626 | ||
627 | #define MSR_IA32_PKG_C3_RESIDENCY 0x3F8 | |
628 | #define MSR_IA32_PKG_C6_RESIDENCY 0x3F9 | |
629 | #define MSR_IA32_PKG_C7_RESIDENCY 0x3FA | |
630 | ||
631 | #define MSR_IA32_CORE_C3_RESIDENCY 0x3FC | |
632 | #define MSR_IA32_CORE_C6_RESIDENCY 0x3FD | |
633 | #define MSR_IA32_CORE_C7_RESIDENCY 0x3FE | |
634 | ||
635 | #define MSR_IA32_MC0_CTL 0x400 | |
636 | #define MSR_IA32_MC0_STATUS 0x401 | |
637 | #define MSR_IA32_MC0_ADDR 0x402 | |
638 | #define MSR_IA32_MC0_MISC 0x403 | |
639 | ||
640 | #define MSR_IA32_VMX_BASE 0x480 | |
641 | #define MSR_IA32_VMX_BASIC MSR_IA32_VMX_BASE | |
642 | #define MSR_IA32_VMX_PINBASED_CTLS MSR_IA32_VMX_BASE+1 | |
643 | #define MSR_IA32_VMX_PROCBASED_CTLS MSR_IA32_VMX_BASE+2 | |
644 | #define MSR_IA32_VMX_EXIT_CTLS MSR_IA32_VMX_BASE+3 | |
645 | #define MSR_IA32_VMX_ENTRY_CTLS MSR_IA32_VMX_BASE+4 | |
646 | #define MSR_IA32_VMX_MISC MSR_IA32_VMX_BASE+5 | |
647 | #define MSR_IA32_VMX_CR0_FIXED0 MSR_IA32_VMX_BASE+6 | |
648 | #define MSR_IA32_VMX_CR0_FIXED1 MSR_IA32_VMX_BASE+7 | |
649 | #define MSR_IA32_VMX_CR4_FIXED0 MSR_IA32_VMX_BASE+8 | |
650 | #define MSR_IA32_VMX_CR4_FIXED1 MSR_IA32_VMX_BASE+9 | |
651 | #define MSR_IA32_VMX_VMCS_ENUM MSR_IA32_VMX_BASE+10 | |
652 | #define MSR_IA32_VMX_PROCBASED_CTLS2 MSR_IA32_VMX_BASE+11 | |
653 | #define MSR_IA32_VMX_EPT_VPID_CAP MSR_IA32_VMX_BASE+12 | |
654 | #define MSR_IA32_VMX_EPT_VPID_CAP_AD_SHIFT 21 | |
655 | #define MSR_IA32_VMX_TRUE_PINBASED_CTLS MSR_IA32_VMX_BASE+13 | |
656 | #define MSR_IA32_VMX_TRUE_PROCBASED_CTLS MSR_IA32_VMX_BASE+14 | |
657 | #define MSR_IA32_VMX_TRUE_VMEXIT_CTLS MSR_IA32_VMX_BASE+15 | |
658 | #define MSR_IA32_VMX_TRUE_VMENTRY_CTLS MSR_IA32_VMX_BASE+16 | |
659 | #define MSR_IA32_VMX_VMFUNC MSR_IA32_VMX_BASE+17 | |
660 | ||
661 | #define MSR_IA32_DS_AREA 0x600 | |
662 | ||
663 | #define MSR_IA32_PKG_POWER_SKU_UNIT 0x606 | |
664 | #define MSR_IA32_PKG_C2_RESIDENCY 0x60D | |
665 | #define MSR_IA32_PKG_ENERGY_STATUS 0x611 | |
666 | #define MSR_IA32_DDR_ENERGY_STATUS 0x619 | |
667 | #define MSR_IA32_LLC_FLUSHED_RESIDENCY_TIMER 0x61D | |
668 | #define MSR_IA32_RING_PERF_STATUS 0x621 | |
669 | ||
670 | #define MSR_IA32_PKG_C8_RESIDENCY 0x630 | |
671 | #define MSR_IA32_PKG_C9_RESIDENCY 0x631 | |
672 | #define MSR_IA32_PKG_C10_RESIDENCY 0x632 | |
673 | ||
674 | #define MSR_IA32_PP0_ENERGY_STATUS 0x639 | |
675 | #define MSR_IA32_PP1_ENERGY_STATUS 0x641 | |
676 | #define MSR_IA32_IA_PERF_LIMIT_REASONS_SKL 0x64F | |
677 | ||
678 | #define MSR_IA32_IA_PERF_LIMIT_REASONS 0x690 | |
679 | #define MSR_IA32_GT_PERF_LIMIT_REASONS 0x6B0 | |
680 | ||
681 | #define MSR_IA32_TSC_DEADLINE 0x6e0 | |
682 | ||
683 | #define MSR_IA32_EFER 0xC0000080 | |
684 | #define MSR_IA32_EFER_SCE 0x00000001 | |
685 | #define MSR_IA32_EFER_LME 0x00000100 | |
686 | #define MSR_IA32_EFER_LMA 0x00000400 | |
687 | #define MSR_IA32_EFER_NXE 0x00000800 | |
688 | ||
689 | #define MSR_IA32_STAR 0xC0000081 | |
690 | #define MSR_IA32_LSTAR 0xC0000082 | |
691 | #define MSR_IA32_CSTAR 0xC0000083 | |
692 | #define MSR_IA32_FMASK 0xC0000084 | |
693 | ||
694 | #define MSR_IA32_FS_BASE 0xC0000100 | |
695 | #define MSR_IA32_GS_BASE 0xC0000101 | |
696 | #define MSR_IA32_KERNEL_GS_BASE 0xC0000102 | |
697 | #define MSR_IA32_TSC_AUX 0xC0000103 | |
698 | ||
699 | #define HV_VMX_EPTP_MEMORY_TYPE_UC 0x0 | |
700 | #define HV_VMX_EPTP_MEMORY_TYPE_WB 0x6 | |
701 | #define HV_VMX_EPTP_WALK_LENGTH(wl) (0ULL | ((((wl) - 1) & 0x7) << 3)) | |
702 | #define HV_VMX_EPTP_ENABLE_AD_FLAGS (1ULL << 6) | |
703 | ||
704 | #endif /* _I386_PROC_REG_H_ */ |