]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/proc_reg.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
30 * Mach Operating System
31 * Copyright (c) 1991,1990 Carnegie Mellon University
32 * All Rights Reserved.
34 * Permission to use, copy, modify and distribute this software and its
35 * documentation is hereby granted, provided that both the copyright
36 * notice and this permission notice appear in all copies of the
37 * software, derivative works or modified versions, and any portions
38 * thereof, and that both notices appear in supporting documentation.
40 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
41 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
42 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
44 * Carnegie Mellon requests users of this software to return to
46 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
47 * School of Computer Science
48 * Carnegie Mellon University
49 * Pittsburgh PA 15213-3890
51 * any improvements or extensions that they make and grant Carnegie Mellon
52 * the rights to redistribute these changes.
59 * Processor registers for i386 and i486.
61 #ifndef _I386_PROC_REG_H_
62 #define _I386_PROC_REG_H_
65 * Model Specific Registers
67 #define MSR_P5_TSC 0x10 /* Time Stamp Register */
68 #define MSR_P5_CESR 0x11 /* Control and Event Select Register */
69 #define MSR_P5_CTR0 0x12 /* Counter #0 */
70 #define MSR_P5_CTR1 0x13 /* Counter #1 */
72 #define MSR_P5_CESR_PC 0x0200 /* Pin Control */
73 #define MSR_P5_CESR_CC 0x01C0 /* Counter Control mask */
74 #define MSR_P5_CESR_ES 0x003F /* Event Control mask */
76 #define MSR_P5_CESR_SHIFT 16 /* Shift to get Counter 1 */
77 #define MSR_P5_CESR_MASK (MSR_P5_CESR_PC|\
79 MSR_P5_CESR_ES) /* Mask Counter */
81 #define MSR_P5_CESR_CC_CLOCK 0x0100 /* Clock Counting (otherwise Event) */
82 #define MSR_P5_CESR_CC_DISABLE 0x0000 /* Disable counter */
83 #define MSR_P5_CESR_CC_CPL012 0x0040 /* Count if the CPL == 0, 1, 2 */
84 #define MSR_P5_CESR_CC_CPL3 0x0080 /* Count if the CPL == 3 */
85 #define MSR_P5_CESR_CC_CPL 0x00C0 /* Count regardless of the CPL */
87 #define MSR_P5_CESR_ES_DATA_READ 0x000000 /* Data Read */
88 #define MSR_P5_CESR_ES_DATA_WRITE 0x000001 /* Data Write */
89 #define MSR_P5_CESR_ES_DATA_RW 0x101000 /* Data Read or Write */
90 #define MSR_P5_CESR_ES_DATA_TLB_MISS 0x000010 /* Data TLB Miss */
91 #define MSR_P5_CESR_ES_DATA_READ_MISS 0x000011 /* Data Read Miss */
92 #define MSR_P5_CESR_ES_DATA_WRITE_MISS 0x000100 /* Data Write Miss */
93 #define MSR_P5_CESR_ES_DATA_RW_MISS 0x101001 /* Data Read or Write Miss */
94 #define MSR_P5_CESR_ES_HIT_EM 0x000101 /* Write (hit) to M|E state */
95 #define MSR_P5_CESR_ES_DATA_CACHE_WB 0x000110 /* Cache lines written back */
96 #define MSR_P5_CESR_ES_EXTERNAL_SNOOP 0x000111 /* External Snoop */
97 #define MSR_P5_CESR_ES_CACHE_SNOOP_HIT 0x001000 /* Data cache snoop hits */
98 #define MSR_P5_CESR_ES_MEM_ACCESS_PIPE 0x001001 /* Mem. access in both pipes */
99 #define MSR_P5_CESR_ES_BANK_CONFLICTS 0x001010 /* Bank conflicts */
100 #define MSR_P5_CESR_ES_MISALIGNED 0x001011 /* Misaligned Memory or I/O */
101 #define MSR_P5_CESR_ES_CODE_READ 0x001100 /* Code Read */
102 #define MSR_P5_CESR_ES_CODE_TLB_MISS 0x001101 /* Code TLB miss */
103 #define MSR_P5_CESR_ES_CODE_CACHE_MISS 0x001110 /* Code Cache miss */
104 #define MSR_P5_CESR_ES_SEGMENT_LOADED 0x001111 /* Any segment reg. loaded */
105 #define MSR_P5_CESR_ES_BRANCHE 0x010010 /* Branches */
106 #define MSR_P5_CESR_ES_BTB_HIT 0x010011 /* BTB Hits */
107 #define MSR_P5_CESR_ES_BRANCHE_BTB 0x010100 /* Taken branch or BTB Hit */
108 #define MSR_P5_CESR_ES_PIPELINE_FLUSH 0x010101 /* Pipeline Flushes */
109 #define MSR_P5_CESR_ES_INSTRUCTION 0x010110 /* Instruction executed */
110 #define MSR_P5_CESR_ES_INSTRUCTION_V 0x010111 /* Inst. executed (v-pipe) */
111 #define MSR_P5_CESR_ES_BUS_CYCLE 0x011000 /* Clocks while bus cycle */
112 #define MSR_P5_CESR_ES_FULL_WRITE_BUF 0x011001 /* Clocks while full wrt buf. */
113 #define MSR_P5_CESR_ES_DATA_MEM_READ 0x011010 /* Pipeline waiting for read */
114 #define MSR_P5_CESR_ES_WRITE_EM 0x011011 /* Stall on write E|M state */
115 #define MSR_P5_CESR_ES_LOCKED_CYCLE 0x011100 /* Locked bus cycles */
116 #define MSR_P5_CESR_ES_IO_CYCLE 0x011101 /* I/O Read or Write cycles */
117 #define MSR_P5_CESR_ES_NON_CACHEABLE 0x011110 /* Non-cacheable Mem. read */
118 #define MSR_P5_CESR_ES_AGI 0x011111 /* Stall because of AGI */
119 #define MSR_P5_CESR_ES_FLOP 0x100010 /* Floating Point operations */
120 #define MSR_P5_CESR_ES_BREAK_DR0 0x100011 /* Breakpoint matches on DR0 */
121 #define MSR_P5_CESR_ES_BREAK_DR1 0x100100 /* Breakpoint matches on DR1 */
122 #define MSR_P5_CESR_ES_BREAK_DR2 0x100101 /* Breakpoint matches on DR2 */
123 #define MSR_P5_CESR_ES_BREAK_DR3 0x100110 /* Breakpoint matches on DR3 */
124 #define MSR_P5_CESR_ES_HARDWARE_IT 0x100111 /* Hardware interrupts */
129 #define CR0_PG 0x80000000 /* Enable paging */
130 #define CR0_CD 0x40000000 /* i486: Cache disable */
131 #define CR0_NW 0x20000000 /* i486: No write-through */
132 #define CR0_AM 0x00040000 /* i486: Alignment check mask */
133 #define CR0_WP 0x00010000 /* i486: Write-protect kernel access */
134 #define CR0_NE 0x00000020 /* i486: Handle numeric exceptions */
135 #define CR0_ET 0x00000010 /* Extension type is 80387 */
137 #define CR0_TS 0x00000008 /* Task switch */
138 #define CR0_EM 0x00000004 /* Emulate coprocessor */
139 #define CR0_MP 0x00000002 /* Monitor coprocessor */
140 #define CR0_PE 0x00000001 /* Enable protected mode */
145 #define CR4_MCE 0x00000040 /* p5: Machine Check Exceptions */
146 #define CR4_PSE 0x00000010 /* p5: Page Size Extensions */
147 #define CR4_DE 0x00000008 /* p5: Debugging Extensions */
148 #define CR4_TSD 0x00000004 /* p5: Time Stamp Disable */
149 #define CR4_PVI 0x00000002 /* p5: Protected-mode Virtual Interrupts */
150 #define CR4_VME 0x00000001 /* p5: Virtual-8086 Mode Extensions */
153 extern unsigned int get_cr0(void);
156 extern unsigned int get_cr2(void);
157 extern unsigned int get_cr3(void);
160 extern unsigned int get_cr4(void);
165 set_cr0(get_cr0() | CR0_TS)
166 extern void clear_ts(void);
168 extern unsigned short get_tr(void);
172 extern unsigned short get_ldt(void);
176 extern __inline__
unsigned int get_cr0(void)
178 register unsigned int cr0
;
179 __asm__
volatile("mov %%cr0, %0" : "=r" (cr0
));
183 extern __inline__
void set_cr0(unsigned int value
)
185 __asm__
volatile("mov %0, %%cr0" : : "r" (value
));
188 extern __inline__
unsigned int get_cr2(void)
190 register unsigned int cr2
;
191 __asm__
volatile("mov %%cr2, %0" : "=r" (cr2
));
195 #if NCPUS > 1 && AT386
197 * get_cr3 and set_cr3 are more complicated for the MPs. cr3 is where
198 * the cpu number gets stored. The MP versions live in locore.s
200 #else /* NCPUS > 1 && AT386 */
201 extern __inline__
unsigned int get_cr3(void)
203 register unsigned int cr3
;
204 __asm__
volatile("mov %%cr3, %0" : "=r" (cr3
));
208 extern __inline__
void set_cr3(unsigned int value
)
210 __asm__
volatile("mov %0, %%cr3" : : "r" (value
));
212 #endif /* NCPUS > 1 && AT386 */
214 extern __inline__
void clear_ts(void)
216 __asm__
volatile("clts");
219 extern __inline__
unsigned short get_tr(void)
222 __asm__
volatile("str %0" : "=rm" (seg
));
226 extern __inline__
void set_tr(unsigned int seg
)
228 __asm__
volatile("ltr %0" : : "rm" ((unsigned short)(seg
)));
231 extern __inline__
unsigned short get_ldt(void)
234 __asm__
volatile("sldt %0" : "=rm" (seg
));
238 extern __inline__
void set_ldt(unsigned int seg
)
240 __asm__
volatile("lldt %0" : : "rm" ((unsigned short)(seg
)));
243 extern __inline__
void flush_tlb(void)
245 unsigned long cr3_temp
;
246 __asm__
volatile("movl %%cr3, %0; movl %0, %%cr3" : "=r" (cr3_temp
) :: "memory");
249 extern __inline__
void invlpg(unsigned long addr
)
251 __asm__
volatile("invlpg (%0)" :: "r" (addr
) : "memory");
253 #endif /* __GNUC__ */
254 #endif /* ASSEMBLER */
256 #endif /* _I386_PROC_REG_H_ */