]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/proc_reg.h
xnu-792.18.15.tar.gz
[apple/xnu.git] / osfmk / i386 / proc_reg.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 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@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31/* CMU_ENDHIST */
32/*
33 * Mach Operating System
34 * Copyright (c) 1991,1990 Carnegie Mellon University
35 * All Rights Reserved.
36 *
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.
42 *
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.
46 *
47 * Carnegie Mellon requests users of this software to return to
48 *
49 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
50 * School of Computer Science
51 * Carnegie Mellon University
52 * Pittsburgh PA 15213-3890
53 *
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 */
64#ifndef _I386_PROC_REG_H_
65#define _I386_PROC_REG_H_
66
67/*
68 * Model Specific Registers
69 */
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 */
128
129/*
130 * CR0
131 */
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 */
144
145/*
146 * CR4
147 */
55e303ae
A
148#define CR4_FXS 0x00000200 /* SSE/SSE2 OS supports FXSave */
149#define CR4_XMM 0x00000400 /* SSE/SSE2 instructions supported in OS */
91447636 150#define CR4_PGE 0x00000080 /* p6: Page Global Enable */
1c79356b 151#define CR4_MCE 0x00000040 /* p5: Machine Check Exceptions */
91447636 152#define CR4_PAE 0x00000020 /* p5: Physical Address Extensions */
1c79356b
A
153#define CR4_PSE 0x00000010 /* p5: Page Size Extensions */
154#define CR4_DE 0x00000008 /* p5: Debugging Extensions */
155#define CR4_TSD 0x00000004 /* p5: Time Stamp Disable */
156#define CR4_PVI 0x00000002 /* p5: Protected-mode Virtual Interrupts */
157#define CR4_VME 0x00000001 /* p5: Virtual-8086 Mode Extensions */
158
159#ifndef ASSEMBLER
91447636
A
160
161#include <sys/cdefs.h>
162__BEGIN_DECLS
1c79356b
A
163
164#define set_ts() \
165 set_cr0(get_cr0() | CR0_TS)
1c79356b 166
91447636 167static inline unsigned int get_cr0(void)
1c79356b
A
168{
169 register unsigned int cr0;
170 __asm__ volatile("mov %%cr0, %0" : "=r" (cr0));
171 return(cr0);
172}
173
91447636 174static inline void set_cr0(unsigned int value)
1c79356b
A
175{
176 __asm__ volatile("mov %0, %%cr0" : : "r" (value));
177}
178
91447636 179static inline unsigned int get_cr2(void)
1c79356b
A
180{
181 register unsigned int cr2;
182 __asm__ volatile("mov %%cr2, %0" : "=r" (cr2));
183 return(cr2);
184}
185
91447636 186static inline unsigned int get_cr3(void)
1c79356b
A
187{
188 register unsigned int cr3;
189 __asm__ volatile("mov %%cr3, %0" : "=r" (cr3));
190 return(cr3);
191}
192
91447636 193static inline void set_cr3(unsigned int value)
1c79356b
A
194{
195 __asm__ volatile("mov %0, %%cr3" : : "r" (value));
196}
1c79356b 197
89b3af67
A
198static inline uint32_t get_cr4(void)
199{
200 uint32_t cr4;
201 __asm__ volatile("mov %%cr4, %0" : "=r" (cr4));
202 return(cr4);
203}
204
205static inline void set_cr4(uint32_t value)
206{
207 __asm__ volatile("mov %0, %%cr4" : : "r" (value));
208}
91447636
A
209
210static inline void clear_ts(void)
1c79356b
A
211{
212 __asm__ volatile("clts");
213}
214
91447636 215static inline unsigned short get_tr(void)
1c79356b
A
216{
217 unsigned short seg;
218 __asm__ volatile("str %0" : "=rm" (seg));
219 return(seg);
220}
221
91447636 222static inline void set_tr(unsigned int seg)
1c79356b
A
223{
224 __asm__ volatile("ltr %0" : : "rm" ((unsigned short)(seg)));
225}
226
89b3af67 227static inline unsigned short sldt(void)
1c79356b
A
228{
229 unsigned short seg;
230 __asm__ volatile("sldt %0" : "=rm" (seg));
231 return(seg);
232}
233
89b3af67 234static inline void lldt(unsigned int seg)
1c79356b
A
235{
236 __asm__ volatile("lldt %0" : : "rm" ((unsigned short)(seg)));
237}
238
89b3af67
A
239#ifdef MACH_KERNEL_PRIVATE
240extern void flush_tlb64(void);
91447636 241static inline void flush_tlb(void)
1c79356b
A
242{
243 unsigned long cr3_temp;
89b3af67
A
244 if (cpu_mode_is64bit()) {
245 flush_tlb64();
246 return;
247 }
1c79356b
A
248 __asm__ volatile("movl %%cr3, %0; movl %0, %%cr3" : "=r" (cr3_temp) :: "memory");
249}
89b3af67 250#endif /* MACH_KERNEL_PRIVATE */
1c79356b 251
91447636
A
252static inline void wbinvd(void)
253{
254 __asm__ volatile("wbinvd");
255}
256
257static inline void invlpg(unsigned long addr)
1c79356b
A
258{
259 __asm__ volatile("invlpg (%0)" :: "r" (addr) : "memory");
260}
55e303ae
A
261
262/*
263 * Access to machine-specific registers (available on 586 and better only)
264 * Note: the rd* operations modify the parameters directly (without using
265 * pointer indirection), this allows gcc to optimize better
266 */
267
268#define rdmsr(msr,lo,hi) \
269 __asm__ volatile("rdmsr" : "=a" (lo), "=d" (hi) : "c" (msr))
270
271#define wrmsr(msr,lo,hi) \
272 __asm__ volatile("wrmsr" : : "c" (msr), "a" (lo), "d" (hi))
273
274#define rdtsc(lo,hi) \
275 __asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi))
276
277#define write_tsc(lo,hi) wrmsr(0x10, lo, hi)
278
279#define rdpmc(counter,lo,hi) \
280 __asm__ volatile("rdpmc" : "=a" (lo), "=d" (hi) : "c" (counter))
281
91447636 282static inline uint64_t rdmsr64(uint32_t msr)
55e303ae
A
283{
284 uint64_t ret;
285 __asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr));
286 return ret;
287}
288
91447636 289static inline void wrmsr64(uint32_t msr, uint64_t val)
55e303ae
A
290{
291 __asm__ volatile("wrmsr" : : "c" (msr), "A" (val));
292}
293
91447636 294static inline uint64_t rdtsc64(void)
55e303ae
A
295{
296 uint64_t ret;
297 __asm__ volatile("rdtsc" : "=A" (ret));
298 return ret;
299}
91447636
A
300
301/*
302 * rdmsr_carefully() returns 0 when the MSR has been read successfully,
303 * or non-zero (1) if the MSR does not exist.
304 * The implementation is in locore.s.
305 */
306extern int rdmsr_carefully(uint32_t msr, uint32_t *lo, uint32_t *hi);
307
308__END_DECLS
309
1c79356b
A
310#endif /* ASSEMBLER */
311
55e303ae
A
312#define MSR_IA32_P5_MC_ADDR 0
313#define MSR_IA32_P5_MC_TYPE 1
314#define MSR_IA32_PLATFORM_ID 0x17
315#define MSR_IA32_EBL_CR_POWERON 0x2a
316
317#define MSR_IA32_APIC_BASE 0x1b
318#define MSR_IA32_APIC_BASE_BSP (1<<8)
319#define MSR_IA32_APIC_BASE_ENABLE (1<<11)
320#define MSR_IA32_APIC_BASE_BASE (0xfffff<<12)
321
322#define MSR_IA32_UCODE_WRITE 0x79
323#define MSR_IA32_UCODE_REV 0x8b
324
325#define MSR_IA32_PERFCTR0 0xc1
326#define MSR_IA32_PERFCTR1 0xc2
327
89b3af67
A
328#define MSR_PMG_CST_CONFIG_CONTROL 0xe2
329
55e303ae
A
330#define MSR_IA32_BBL_CR_CTL 0x119
331
89b3af67
A
332#define MSR_IA32_SYSENTER_CS 0x174
333#define MSR_IA32_SYSENTER_ESP 0x175
334#define MSR_IA32_SYSENTER_EIP 0x176
335
55e303ae
A
336#define MSR_IA32_MCG_CAP 0x179
337#define MSR_IA32_MCG_STATUS 0x17a
338#define MSR_IA32_MCG_CTL 0x17b
339
340#define MSR_IA32_EVNTSEL0 0x186
341#define MSR_IA32_EVNTSEL1 0x187
342
89b3af67
A
343#define MSR_IA32_PERF_STS 0x198
344#define MSR_IA32_PERF_CTL 0x199
345
91447636
A
346#define MSR_IA32_MISC_ENABLE 0x1a0
347
55e303ae
A
348#define MSR_IA32_DEBUGCTLMSR 0x1d9
349#define MSR_IA32_LASTBRANCHFROMIP 0x1db
350#define MSR_IA32_LASTBRANCHTOIP 0x1dc
351#define MSR_IA32_LASTINTFROMIP 0x1dd
352#define MSR_IA32_LASTINTTOIP 0x1de
353
91447636
A
354#define MSR_IA32_CR_PAT 0x277
355
55e303ae
A
356#define MSR_IA32_MC0_CTL 0x400
357#define MSR_IA32_MC0_STATUS 0x401
358#define MSR_IA32_MC0_ADDR 0x402
359#define MSR_IA32_MC0_MISC 0x403
360
91447636
A
361#define MSR_IA32_MTRRCAP 0xfe
362#define MSR_IA32_MTRR_DEF_TYPE 0x2ff
363#define MSR_IA32_MTRR_PHYSBASE(n) (0x200 + 2*(n))
364#define MSR_IA32_MTRR_PHYSMASK(n) (0x200 + 2*(n) + 1)
365#define MSR_IA32_MTRR_FIX64K_00000 0x250
366#define MSR_IA32_MTRR_FIX16K_80000 0x258
367#define MSR_IA32_MTRR_FIX16K_A0000 0x259
368#define MSR_IA32_MTRR_FIX4K_C0000 0x268
369#define MSR_IA32_MTRR_FIX4K_C8000 0x269
370#define MSR_IA32_MTRR_FIX4K_D0000 0x26a
371#define MSR_IA32_MTRR_FIX4K_D8000 0x26b
372#define MSR_IA32_MTRR_FIX4K_E0000 0x26c
373#define MSR_IA32_MTRR_FIX4K_E8000 0x26d
374#define MSR_IA32_MTRR_FIX4K_F0000 0x26e
375#define MSR_IA32_MTRR_FIX4K_F8000 0x26f
376
89b3af67
A
377
378#define MSR_IA32_EFER 0xC0000080
379#define MSR_IA32_EFER_SCE 0x00000001
380#define MSR_IA32_EFER_LME 0x00000100
381#define MSR_IA32_EFER_LMA 0x00000400
382#define MSR_IA32_EFER_NXE 0x00000800
383
384#define MSR_IA32_STAR 0xC0000081
385#define MSR_IA32_LSTAR 0xC0000082
386#define MSR_IA32_CSTAR 0xC0000083
387#define MSR_IA32_FMASK 0xC0000084
388
389#define MSR_IA32_FS_BASE 0xC0000100
390#define MSR_IA32_GS_BASE 0xC0000101
391#define MSR_IA32_KERNEL_GS_BASE 0xC0000102
392
1c79356b 393#endif /* _I386_PROC_REG_H_ */