cpufunc.h revision 1.5 1 1.1 cgd /*
2 1.4 mycroft * Copyright (c) 1993 Charles Hannum.
3 1.4 mycroft * All rights reserved.
4 1.2 mycroft *
5 1.4 mycroft * Redistribution and use in source and binary forms, with or without
6 1.4 mycroft * modification, are permitted provided that the following conditions
7 1.4 mycroft * are met:
8 1.4 mycroft * 1. Redistributions of source code must retain the above copyright
9 1.4 mycroft * notice, this list of conditions and the following disclaimer.
10 1.4 mycroft * 2. Redistributions in binary form must reproduce the above copyright
11 1.4 mycroft * notice, this list of conditions and the following disclaimer in the
12 1.4 mycroft * documentation and/or other materials provided with the distribution.
13 1.4 mycroft * 3. All advertising materials mentioning features or use of this software
14 1.4 mycroft * must display the following acknowledgement:
15 1.4 mycroft * This product includes software developed by Charles Hannum.
16 1.4 mycroft * 4. The name of the author may not be used to endorse or promote products
17 1.5 jtc * derived from this software without specific prior written permission
18 1.4 mycroft *
19 1.4 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.4 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.4 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.4 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.4 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 1.4 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.4 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.4 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.4 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 1.4 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.4 mycroft *
30 1.5 jtc * $Id: cpufunc.h,v 1.5 1994/01/28 23:44:07 jtc Exp $
31 1.4 mycroft */
32 1.4 mycroft
33 1.4 mycroft /*
34 1.4 mycroft * Functions to provide access to i386-specific instructions.
35 1.1 cgd */
36 1.1 cgd
37 1.1 cgd #include <sys/cdefs.h>
38 1.1 cgd #include <sys/types.h>
39 1.1 cgd
40 1.1 cgd static __inline int bdb(void)
41 1.1 cgd {
42 1.1 cgd extern int bdb_exists;
43 1.1 cgd
44 1.1 cgd if (!bdb_exists)
45 1.1 cgd return (0);
46 1.4 mycroft __asm __volatile("int $3");
47 1.1 cgd return (1);
48 1.1 cgd }
49 1.1 cgd
50 1.1 cgd static __inline void
51 1.4 mycroft lidt(void *p)
52 1.4 mycroft {
53 1.4 mycroft __asm __volatile("lidt (%0)" : : "r" (p));
54 1.4 mycroft }
55 1.4 mycroft
56 1.4 mycroft static __inline void
57 1.4 mycroft lldt(u_short sel)
58 1.4 mycroft {
59 1.4 mycroft __asm __volatile("lldt %0" : : "r" (sel));
60 1.4 mycroft }
61 1.4 mycroft
62 1.4 mycroft static __inline void
63 1.4 mycroft ltr(u_short sel)
64 1.4 mycroft {
65 1.4 mycroft __asm __volatile("ltr %0" : : "r" (sel));
66 1.4 mycroft }
67 1.4 mycroft
68 1.4 mycroft static __inline void
69 1.4 mycroft tlbflush(void)
70 1.4 mycroft {
71 1.4 mycroft __asm __volatile("movl %%cr3,%%eax\n\tmovl %%eax,%%cr3" : : : "%eax");
72 1.4 mycroft }
73 1.4 mycroft
74 1.4 mycroft static __inline void
75 1.4 mycroft lcr0(u_int val)
76 1.4 mycroft {
77 1.4 mycroft __asm __volatile("movl %0,%%cr0" : : "r" (val));
78 1.4 mycroft }
79 1.4 mycroft
80 1.4 mycroft static __inline u_int
81 1.4 mycroft rcr0(void)
82 1.4 mycroft {
83 1.4 mycroft u_int val;
84 1.4 mycroft __asm __volatile("movl %%cr0,%0" : "=a" (val));
85 1.4 mycroft return val;
86 1.4 mycroft }
87 1.4 mycroft
88 1.4 mycroft static __inline u_int
89 1.4 mycroft rcr2(void)
90 1.4 mycroft {
91 1.4 mycroft u_int val;
92 1.4 mycroft __asm __volatile("movl %%cr2,%0" : "=a" (val));
93 1.4 mycroft return val;
94 1.4 mycroft }
95 1.4 mycroft
96 1.4 mycroft static __inline void
97 1.4 mycroft lcr3(u_int val)
98 1.4 mycroft {
99 1.4 mycroft __asm __volatile("movl %0,%%cr3" : : "r" (val));
100 1.4 mycroft }
101 1.4 mycroft
102 1.4 mycroft static __inline u_int
103 1.4 mycroft rcr3(void)
104 1.4 mycroft {
105 1.4 mycroft u_int val;
106 1.4 mycroft __asm __volatile("movl %%cr3,%0" : "=a" (val));
107 1.4 mycroft return val;
108 1.4 mycroft }
109 1.4 mycroft
110 1.4 mycroft #ifdef notyet
111 1.4 mycroft void setidt __P((int idx, /*XXX*/caddr_t func, int typ, int dpl));
112 1.4 mycroft #endif
113 1.4 mycroft
114 1.4 mycroft
115 1.4 mycroft /* XXXX ought to be in psl.h with spl() functions */
116 1.4 mycroft
117 1.4 mycroft static __inline void
118 1.1 cgd disable_intr(void)
119 1.1 cgd {
120 1.1 cgd __asm __volatile("cli");
121 1.1 cgd }
122 1.1 cgd
123 1.1 cgd static __inline void
124 1.1 cgd enable_intr(void)
125 1.1 cgd {
126 1.1 cgd __asm __volatile("sti");
127 1.1 cgd }
128 1.1 cgd
129