]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/proc_reg.h
xnu-792.6.61.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
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
37839358
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * @OSF_COPYRIGHT@
24 */
25/* CMU_ENDHIST */
26/*
27 * Mach Operating System
28 * Copyright (c) 1991,1990 Carnegie Mellon University
29 * All Rights Reserved.
30 *
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
36 *
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 *
41 * Carnegie Mellon requests users of this software to return to
42 *
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
47 *
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
50 */
51
52/*
53 */
54
55/*
56 * Processor registers for i386 and i486.
57 */
58#ifndef _I386_PROC_REG_H_
59#define _I386_PROC_REG_H_
60
61/*
62 * Model Specific Registers
63 */
64#define MSR_P5_TSC 0x10 /* Time Stamp Register */
65#define MSR_P5_CESR 0x11 /* Control and Event Select Register */
66#define MSR_P5_CTR0 0x12 /* Counter #0 */
67#define MSR_P5_CTR1 0x13 /* Counter #1 */
68
69#define MSR_P5_CESR_PC 0x0200 /* Pin Control */
70#define MSR_P5_CESR_CC 0x01C0 /* Counter Control mask */
71#define MSR_P5_CESR_ES 0x003F /* Event Control mask */
72
73#define MSR_P5_CESR_SHIFT 16 /* Shift to get Counter 1 */
74#define MSR_P5_CESR_MASK (MSR_P5_CESR_PC|\
75 MSR_P5_CESR_CC|\
76 MSR_P5_CESR_ES) /* Mask Counter */
77
78#define MSR_P5_CESR_CC_CLOCK 0x0100 /* Clock Counting (otherwise Event) */
79#define MSR_P5_CESR_CC_DISABLE 0x0000 /* Disable counter */
80#define MSR_P5_CESR_CC_CPL012 0x0040 /* Count if the CPL == 0, 1, 2 */
81#define MSR_P5_CESR_CC_CPL3 0x0080 /* Count if the CPL == 3 */
82#define MSR_P5_CESR_CC_CPL 0x00C0 /* Count regardless of the CPL */
83
84#define MSR_P5_CESR_ES_DATA_READ 0x000000 /* Data Read */
85#define MSR_P5_CESR_ES_DATA_WRITE 0x000001 /* Data Write */
86#define MSR_P5_CESR_ES_DATA_RW 0x101000 /* Data Read or Write */
87#define MSR_P5_CESR_ES_DATA_TLB_MISS 0x000010 /* Data TLB Miss */
88#define MSR_P5_CESR_ES_DATA_READ_MISS 0x000011 /* Data Read Miss */
89#define MSR_P5_CESR_ES_DATA_WRITE_MISS 0x000100 /* Data Write Miss */
90#define MSR_P5_CESR_ES_DATA_RW_MISS 0x101001 /* Data Read or Write Miss */
91#define MSR_P5_CESR_ES_HIT_EM 0x000101 /* Write (hit) to M|E state */
92#define MSR_P5_CESR_ES_DATA_CACHE_WB 0x000110 /* Cache lines written back */
93#define MSR_P5_CESR_ES_EXTERNAL_SNOOP 0x000111 /* External Snoop */
94#define MSR_P5_CESR_ES_CACHE_SNOOP_HIT 0x001000 /* Data cache snoop hits */
95#define MSR_P5_CESR_ES_MEM_ACCESS_PIPE 0x001001 /* Mem. access in both pipes */
96#define MSR_P5_CESR_ES_BANK_CONFLICTS 0x001010 /* Bank conflicts */
97#define MSR_P5_CESR_ES_MISALIGNED 0x001011 /* Misaligned Memory or I/O */
98#define MSR_P5_CESR_ES_CODE_READ 0x001100 /* Code Read */
99#define MSR_P5_CESR_ES_CODE_TLB_MISS 0x001101 /* Code TLB miss */
100#define MSR_P5_CESR_ES_CODE_CACHE_MISS 0x001110 /* Code Cache miss */
101#define MSR_P5_CESR_ES_SEGMENT_LOADED 0x001111 /* Any segment reg. loaded */
102#define MSR_P5_CESR_ES_BRANCHE 0x010010 /* Branches */
103#define MSR_P5_CESR_ES_BTB_HIT 0x010011 /* BTB Hits */
104#define MSR_P5_CESR_ES_BRANCHE_BTB 0x010100 /* Taken branch or BTB Hit */
105#define MSR_P5_CESR_ES_PIPELINE_FLUSH 0x010101 /* Pipeline Flushes */
106#define MSR_P5_CESR_ES_INSTRUCTION 0x010110 /* Instruction executed */
107#define MSR_P5_CESR_ES_INSTRUCTION_V 0x010111 /* Inst. executed (v-pipe) */
108#define MSR_P5_CESR_ES_BUS_CYCLE 0x011000 /* Clocks while bus cycle */
109#define MSR_P5_CESR_ES_FULL_WRITE_BUF 0x011001 /* Clocks while full wrt buf. */
110#define MSR_P5_CESR_ES_DATA_MEM_READ 0x011010 /* Pipeline waiting for read */
111#define MSR_P5_CESR_ES_WRITE_EM 0x011011 /* Stall on write E|M state */
112#define MSR_P5_CESR_ES_LOCKED_CYCLE 0x011100 /* Locked bus cycles */
113#define MSR_P5_CESR_ES_IO_CYCLE 0x011101 /* I/O Read or Write cycles */
114#define MSR_P5_CESR_ES_NON_CACHEABLE 0x011110 /* Non-cacheable Mem. read */
115#define MSR_P5_CESR_ES_AGI 0x011111 /* Stall because of AGI */
116#define MSR_P5_CESR_ES_FLOP 0x100010 /* Floating Point operations */
117#define MSR_P5_CESR_ES_BREAK_DR0 0x100011 /* Breakpoint matches on DR0 */
118#define MSR_P5_CESR_ES_BREAK_DR1 0x100100 /* Breakpoint matches on DR1 */
119#define MSR_P5_CESR_ES_BREAK_DR2 0x100101 /* Breakpoint matches on DR2 */
120#define MSR_P5_CESR_ES_BREAK_DR3 0x100110 /* Breakpoint matches on DR3 */
121#define MSR_P5_CESR_ES_HARDWARE_IT 0x100111 /* Hardware interrupts */
122
123/*
124 * CR0
125 */
126#define CR0_PG 0x80000000 /* Enable paging */
127#define CR0_CD 0x40000000 /* i486: Cache disable */
128#define CR0_NW 0x20000000 /* i486: No write-through */
129#define CR0_AM 0x00040000 /* i486: Alignment check mask */
130#define CR0_WP 0x00010000 /* i486: Write-protect kernel access */
131#define CR0_NE 0x00000020 /* i486: Handle numeric exceptions */
132#define CR0_ET 0x00000010 /* Extension type is 80387 */
133 /* (not official) */
134#define CR0_TS 0x00000008 /* Task switch */
135#define CR0_EM 0x00000004 /* Emulate coprocessor */
136#define CR0_MP 0x00000002 /* Monitor coprocessor */
137#define CR0_PE 0x00000001 /* Enable protected mode */
138
139/*
140 * CR4
141 */
55e303ae
A
142#define CR4_FXS 0x00000200 /* SSE/SSE2 OS supports FXSave */
143#define CR4_XMM 0x00000400 /* SSE/SSE2 instructions supported in OS */
91447636 144#define CR4_PGE 0x00000080 /* p6: Page Global Enable */
1c79356b 145#define CR4_MCE 0x00000040 /* p5: Machine Check Exceptions */
91447636 146#define CR4_PAE 0x00000020 /* p5: Physical Address Extensions */
1c79356b
A
147#define CR4_PSE 0x00000010 /* p5: Page Size Extensions */
148#define CR4_DE 0x00000008 /* p5: Debugging Extensions */
149#define CR4_TSD 0x00000004 /* p5: Time Stamp Disable */
150#define CR4_PVI 0x00000002 /* p5: Protected-mode Virtual Interrupts */
151#define CR4_VME 0x00000001 /* p5: Virtual-8086 Mode Extensions */
152
153#ifndef ASSEMBLER
91447636
A
154
155#include <sys/cdefs.h>
156__BEGIN_DECLS
1c79356b
A
157
158#define set_ts() \
159 set_cr0(get_cr0() | CR0_TS)
1c79356b 160
91447636 161static inline unsigned int get_cr0(void)
1c79356b
A
162{
163 register unsigned int cr0;
164 __asm__ volatile("mov %%cr0, %0" : "=r" (cr0));
165 return(cr0);
166}
167
91447636 168static inline void set_cr0(unsigned int value)
1c79356b
A
169{
170 __asm__ volatile("mov %0, %%cr0" : : "r" (value));
171}
172
91447636 173static inline unsigned int get_cr2(void)
1c79356b
A
174{
175 register unsigned int cr2;
176 __asm__ volatile("mov %%cr2, %0" : "=r" (cr2));
177 return(cr2);
178}
179
91447636 180static inline unsigned int get_cr3(void)
1c79356b
A
181{
182 register unsigned int cr3;
183 __asm__ volatile("mov %%cr3, %0" : "=r" (cr3));
184 return(cr3);
185}
186
91447636 187static inline void set_cr3(unsigned int value)
1c79356b
A
188{
189 __asm__ volatile("mov %0, %%cr3" : : "r" (value));
190}
1c79356b 191
91447636
A
192/* Implemented in locore: */
193extern uint32_t get_cr4(void);
194extern void set_cr4(uint32_t);
195
196static inline void clear_ts(void)
1c79356b
A
197{
198 __asm__ volatile("clts");
199}
200
91447636 201static inline unsigned short get_tr(void)
1c79356b
A
202{
203 unsigned short seg;
204 __asm__ volatile("str %0" : "=rm" (seg));
205 return(seg);
206}
207
91447636 208static inline void set_tr(unsigned int seg)
1c79356b
A
209{
210 __asm__ volatile("ltr %0" : : "rm" ((unsigned short)(seg)));
211}
212
91447636 213static inline unsigned short get_ldt(void)
1c79356b
A
214{
215 unsigned short seg;
216 __asm__ volatile("sldt %0" : "=rm" (seg));
217 return(seg);
218}
219
91447636 220static inline void set_ldt(unsigned int seg)
1c79356b
A
221{
222 __asm__ volatile("lldt %0" : : "rm" ((unsigned short)(seg)));
223}
224
91447636 225static inline void flush_tlb(void)
1c79356b
A
226{
227 unsigned long cr3_temp;
228 __asm__ volatile("movl %%cr3, %0; movl %0, %%cr3" : "=r" (cr3_temp) :: "memory");
229}
230
91447636
A
231static inline void wbinvd(void)
232{
233 __asm__ volatile("wbinvd");
234}
235
236static inline void invlpg(unsigned long addr)
1c79356b
A
237{
238 __asm__ volatile("invlpg (%0)" :: "r" (addr) : "memory");
239}
55e303ae
A
240
241/*
242 * Access to machine-specific registers (available on 586 and better only)
243 * Note: the rd* operations modify the parameters directly (without using
244 * pointer indirection), this allows gcc to optimize better
245 */
246
247#define rdmsr(msr,lo,hi) \
248 __asm__ volatile("rdmsr" : "=a" (lo), "=d" (hi) : "c" (msr))
249
250#define wrmsr(msr,lo,hi) \
251 __asm__ volatile("wrmsr" : : "c" (msr), "a" (lo), "d" (hi))
252
253#define rdtsc(lo,hi) \
254 __asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi))
255
256#define write_tsc(lo,hi) wrmsr(0x10, lo, hi)
257
258#define rdpmc(counter,lo,hi) \
259 __asm__ volatile("rdpmc" : "=a" (lo), "=d" (hi) : "c" (counter))
260
91447636 261static inline uint64_t rdmsr64(uint32_t msr)
55e303ae
A
262{
263 uint64_t ret;
264 __asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr));
265 return ret;
266}
267
91447636 268static inline void wrmsr64(uint32_t msr, uint64_t val)
55e303ae
A
269{
270 __asm__ volatile("wrmsr" : : "c" (msr), "A" (val));
271}
272
91447636 273static inline uint64_t rdtsc64(void)
55e303ae
A
274{
275 uint64_t ret;
276 __asm__ volatile("rdtsc" : "=A" (ret));
277 return ret;
278}
91447636
A
279
280/*
281 * rdmsr_carefully() returns 0 when the MSR has been read successfully,
282 * or non-zero (1) if the MSR does not exist.
283 * The implementation is in locore.s.
284 */
285extern int rdmsr_carefully(uint32_t msr, uint32_t *lo, uint32_t *hi);
286
287__END_DECLS
288
1c79356b
A
289#endif /* ASSEMBLER */
290
55e303ae
A
291#define MSR_IA32_P5_MC_ADDR 0
292#define MSR_IA32_P5_MC_TYPE 1
293#define MSR_IA32_PLATFORM_ID 0x17
294#define MSR_IA32_EBL_CR_POWERON 0x2a
295
296#define MSR_IA32_APIC_BASE 0x1b
297#define MSR_IA32_APIC_BASE_BSP (1<<8)
298#define MSR_IA32_APIC_BASE_ENABLE (1<<11)
299#define MSR_IA32_APIC_BASE_BASE (0xfffff<<12)
300
301#define MSR_IA32_UCODE_WRITE 0x79
302#define MSR_IA32_UCODE_REV 0x8b
303
304#define MSR_IA32_PERFCTR0 0xc1
305#define MSR_IA32_PERFCTR1 0xc2
306
307#define MSR_IA32_BBL_CR_CTL 0x119
308
309#define MSR_IA32_MCG_CAP 0x179
310#define MSR_IA32_MCG_STATUS 0x17a
311#define MSR_IA32_MCG_CTL 0x17b
312
313#define MSR_IA32_EVNTSEL0 0x186
314#define MSR_IA32_EVNTSEL1 0x187
315
91447636
A
316#define MSR_IA32_MISC_ENABLE 0x1a0
317
55e303ae
A
318#define MSR_IA32_DEBUGCTLMSR 0x1d9
319#define MSR_IA32_LASTBRANCHFROMIP 0x1db
320#define MSR_IA32_LASTBRANCHTOIP 0x1dc
321#define MSR_IA32_LASTINTFROMIP 0x1dd
322#define MSR_IA32_LASTINTTOIP 0x1de
323
91447636
A
324#define MSR_IA32_CR_PAT 0x277
325
55e303ae
A
326#define MSR_IA32_MC0_CTL 0x400
327#define MSR_IA32_MC0_STATUS 0x401
328#define MSR_IA32_MC0_ADDR 0x402
329#define MSR_IA32_MC0_MISC 0x403
330
91447636
A
331#define MSR_IA32_MTRRCAP 0xfe
332#define MSR_IA32_MTRR_DEF_TYPE 0x2ff
333#define MSR_IA32_MTRR_PHYSBASE(n) (0x200 + 2*(n))
334#define MSR_IA32_MTRR_PHYSMASK(n) (0x200 + 2*(n) + 1)
335#define MSR_IA32_MTRR_FIX64K_00000 0x250
336#define MSR_IA32_MTRR_FIX16K_80000 0x258
337#define MSR_IA32_MTRR_FIX16K_A0000 0x259
338#define MSR_IA32_MTRR_FIX4K_C0000 0x268
339#define MSR_IA32_MTRR_FIX4K_C8000 0x269
340#define MSR_IA32_MTRR_FIX4K_D0000 0x26a
341#define MSR_IA32_MTRR_FIX4K_D8000 0x26b
342#define MSR_IA32_MTRR_FIX4K_E0000 0x26c
343#define MSR_IA32_MTRR_FIX4K_E8000 0x26d
344#define MSR_IA32_MTRR_FIX4K_F0000 0x26e
345#define MSR_IA32_MTRR_FIX4K_F8000 0x26f
346
1c79356b 347#endif /* _I386_PROC_REG_H_ */