xref: /openbsd/sys/arch/i386/include/cpu.h (revision 78b63d65)
1 /*	$OpenBSD: cpu.h,v 1.40 2001/12/08 02:24:06 art Exp $	*/
2 /*	$NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $	*/
3 
4 /*-
5  * Copyright (c) 1990 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * William Jolitz.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the University of
22  *	California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *	@(#)cpu.h	5.4 (Berkeley) 5/9/91
40  */
41 
42 #ifndef _I386_CPU_H_
43 #define _I386_CPU_H_
44 
45 /*
46  * Definitions unique to i386 cpu support.
47  */
48 #include <machine/psl.h>
49 #include <machine/frame.h>
50 #include <machine/segments.h>
51 
52 /*
53  * definitions of cpu-dependent requirements
54  * referenced in generic code
55  */
56 #define	cpu_swapin(p)			/* nothing */
57 
58 /*
59  * Arguments to hardclock, softclock and statclock
60  * encapsulate the previous machine state in an opaque
61  * clockframe; for now, use generic intrframe.
62  *
63  * XXX intrframe has a lot of gunk we don't need.
64  */
65 #define clockframe intrframe
66 
67 #define	CLKF_USERMODE(frame)	USERMODE((frame)->if_cs, (frame)->if_eflags)
68 #define	CLKF_BASEPRI(frame)	((frame)->if_ppl == 0)
69 #define	CLKF_PC(frame)		((frame)->if_eip)
70 #define	CLKF_INTR(frame)	(IDXSEL((frame)->if_cs) == GICODE_SEL)
71 
72 /*
73  * Preempt the current process if in interrupt from user mode,
74  * or after the current trap/syscall if in system mode.
75  */
76 int	want_resched;		/* resched() was called */
77 #define	need_resched()		(want_resched = 1, setsoftast())
78 
79 /*
80  * Give a profiling tick to the current process when the user profiling
81  * buffer pages are invalid.  On the i386, request an ast to send us
82  * through trap(), marking the proc as needing a profiling tick.
83  */
84 #define	need_proftick(p)	((p)->p_flag |= P_OWEUPC, setsoftast())
85 
86 /*
87  * Notify the current process (p) that it has a signal pending,
88  * process as soon as possible.
89  */
90 #define	signotify(p)		setsoftast()
91 
92 /*
93  * We need a machine-independent name for this.
94  */
95 #define	DELAY(x)		delay(x)
96 void	delay __P((int));
97 
98 #if defined(I586_CPU) || defined(I686_CPU)
99 /*
100  * High resolution clock support (Pentium only)
101  */
102 void	calibrate_cyclecounter __P((void));
103 #ifndef	HZ
104 extern u_quad_t pentium_base_tsc;
105 #define CPU_CLOCKUPDATE(otime, ntime)					\
106 	do {								\
107 		if (pentium_mhz) {					\
108 			__asm __volatile("cli\n"			\
109 					 "movl (%3), %%eax\n"		\
110 					 "movl %%eax, (%2)\n"		\
111 					 "movl 4(%3), %%eax\n"		\
112 					 "movl %%eax, 4(%2)\n"		\
113 					 ".byte 0xf, 0x31\n"		\
114 					 "sti\n"			\
115 					 "#%0 %1 %2 %3"			\
116 					 : "=m" (*otime),		\
117 					 "=A" (pentium_base_tsc)	\
118 					 : "c" (otime), "b" (ntime));	\
119 		}							\
120 		else {							\
121 			*(otime) = *(ntime);				\
122 		}							\
123 	} while (0)
124 #endif
125 #endif
126 
127 /*
128  * pull in #defines for kinds of processors
129  */
130 #include <machine/cputypes.h>
131 
132 struct cpu_nocpuid_nameclass {
133 	int cpu_vendor;
134 	const char *cpu_vendorname;
135 	const char *cpu_name;
136 	int cpu_class;
137 	void (*cpu_setup) __P((const char *, int, int));
138 };
139 
140 struct cpu_cpuid_nameclass {
141 	const char *cpu_id;
142 	int cpu_vendor;
143 	const char *cpu_vendorname;
144 	struct cpu_cpuid_family {
145 		int cpu_class;
146 		const char *cpu_models[CPU_MAXMODEL+2];
147 		void (*cpu_setup) __P((const char *, int, int));
148 	} cpu_family[CPU_MAXFAMILY - CPU_MINFAMILY + 1];
149 };
150 
151 struct cpu_cpuid_feature {
152 	int feature_bit;
153 	const char *feature_name;
154 };
155 
156 #ifdef _KERNEL
157 extern int cpu;
158 extern int cpu_class;
159 extern int cpu_feature;
160 extern int cpu_apmwarn;
161 extern int cpu_apmhalt;
162 extern int cpuid_level;
163 extern const struct cpu_nocpuid_nameclass i386_nocpuid_cpus[];
164 extern const struct cpu_cpuid_nameclass i386_cpuid_cpus[];
165 
166 #if defined(I586_CPU) || defined(I686_CPU)
167 extern int pentium_mhz;
168 #endif
169 
170 #ifdef I586_CPU
171 /* F00F bug fix stuff for pentium cpu */
172 extern int cpu_f00f_bug;
173 void fix_f00f __P((void));
174 #endif
175 
176 /* dkcsum.c */
177 void	dkcsumattach __P((void));
178 
179 /* machdep.c */
180 void	dumpconf __P((void));
181 void	cpu_reset __P((void));
182 void	i386_proc0_tss_ldt_init __P((void));
183 
184 /* locore.s */
185 struct region_descriptor;
186 void	lgdt __P((struct region_descriptor *));
187 void	fillw __P((short, void *, size_t));
188 short	fusword __P((u_short *));
189 int	susword __P((u_short *t, u_short));
190 
191 struct pcb;
192 void	savectx __P((struct pcb *));
193 void	switch_exit __P((struct proc *));
194 void	proc_trampoline __P((void));
195 
196 /* clock.c */
197 void	initrtclock __P((void));
198 void	startrtclock __P((void));
199 void	rtcdrain __P((void *));
200 
201 /* npx.c */
202 void	npxdrop __P((void));
203 void	npxsave __P((void));
204 
205 #if defined(MATH_EMULATE) || defined(GPL_MATH_EMULATE)
206 /* math_emulate.c */
207 int	math_emulate __P((struct trapframe *));
208 #endif
209 
210 #ifdef USER_LDT
211 /* sys_machdep.h */
212 void	i386_user_cleanup __P((struct pcb *));
213 int	i386_get_ldt __P((struct proc *, void *, register_t *));
214 int	i386_set_ldt __P((struct proc *, void *, register_t *));
215 #endif
216 
217 /* isa_machdep.c */
218 void	isa_defaultirq __P((void));
219 int	isa_nmi __P((void));
220 
221 /* pmap.c */
222 void	pmap_bootstrap __P((vm_offset_t));
223 
224 /* vm_machdep.c */
225 int	kvtop __P((caddr_t));
226 
227 #ifdef VM86
228 /* vm86.c */
229 void	vm86_gpfault __P((struct proc *, int));
230 #endif /* VM86 */
231 
232 #ifdef GENERIC
233 /* swapgeneric.c */
234 void	setconf __P((void));
235 #endif /* GENERIC */
236 
237 #endif /* _KERNEL */
238 
239 /*
240  * CTL_MACHDEP definitions.
241  */
242 #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
243 #define	CPU_BIOS		2	/* BIOS variables */
244 #define	CPU_BLK2CHR		3	/* convert blk maj into chr one */
245 #define	CPU_CHR2BLK		4	/* convert chr maj into blk one */
246 #define CPU_ALLOWAPERTURE	5	/* allow mmap of /dev/xf86 */
247 #define CPU_CPUVENDOR		6	/* cpuid vendor string */
248 #define CPU_CPUID		7	/* cpuid */
249 #define CPU_CPUFEATURE		8	/* cpuid features */
250 #define CPU_APMWARN		9	/* APM battery warning percentage */
251 #define CPU_KBDRESET		10	/* keyboard reset under pcvt */
252 #define CPU_APMHALT		11	/* halt -p hack */
253 #define	CPU_MAXID		12	/* number of valid machdep ids */
254 
255 #define	CTL_MACHDEP_NAMES { \
256 	{ 0, 0 }, \
257 	{ "console_device", CTLTYPE_STRUCT }, \
258 	{ "bios", CTLTYPE_INT }, \
259 	{ "blk2chr", CTLTYPE_STRUCT }, \
260 	{ "chr2blk", CTLTYPE_STRUCT }, \
261 	{ "allowaperture", CTLTYPE_INT }, \
262 	{ "cpuvendor", CTLTYPE_STRING }, \
263 	{ "cpuid", CTLTYPE_INT }, \
264 	{ "cpufeature", CTLTYPE_INT }, \
265 	{ "apmwarn", CTLTYPE_INT }, \
266 	{ "kbdreset", CTLTYPE_INT }, \
267 	{ "apmhalt", CTLTYPE_INT }, \
268 }
269 
270 #endif /* !_I386_CPU_H_ */
271