xref: /illumos-gate/usr/src/uts/intel/asm/mmu.h (revision 7b209c2c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _ASM_MMU_H
27 #define	_ASM_MMU_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #if defined(__GNUC__) && !defined(__xpv)
38 
39 #if defined(__amd64)
40 
41 extern __inline__ ulong_t getcr3(void)
42 {
43 	uint64_t value;
44 
45 	__asm__ __volatile__(
46 	    "movq %%cr3, %0"
47 	    : "=r" (value));
48 	return (value);
49 }
50 
51 extern __inline__ void setcr3(ulong_t value)
52 {
53 	__asm__ __volatile__(
54 	    "movq %0, %%cr3"
55 	    : /* no output */
56 	    : "r" (value));
57 }
58 
59 extern __inline__ void reload_cr3(void)
60 {
61 	setcr3(getcr3());
62 }
63 
64 #elif defined(__i386)
65 
66 extern __inline__ ulong_t getcr3(void)
67 {
68 	uint32_t value;
69 
70 	__asm__ __volatile__(
71 	    "movl %%cr3, %0"
72 	    : "=r" (value));
73 	return (value);
74 }
75 
76 extern __inline__ void setcr3(ulong_t value)
77 {
78 	__asm__ __volatile__(
79 	    "movl %0, %%cr3"
80 	    : /* no output */
81 	    : "r" (value));
82 }
83 
84 extern __inline__ void reload_cr3(void)
85 {
86 	setcr3(getcr3());
87 }
88 
89 #endif
90 
91 #endif /* __GNUC__ && !__xpv */
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif	/* _ASM_MMU_H */
98