xref: /386bsd/usr/src/kernel/include/i386/cpu.h (revision dc8b130e)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * William Jolitz.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the University of
19  *	California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)cpu.h	5.4 (Berkeley) 5/9/91
37  */
38 
39 #ifndef _CPU_H_
40 #define _CPU_H_
41 /*
42  * Definitions unique to i386 cpu support.
43  */
44 #include "machine/frame.h"
45 
46 /*
47  * Selector priority, used by hardclock() to discover user/kernel mode.
48  */
49 #define	ISPL(s)	((s) & 3)	/* what is the priority level of a selector */
50 #define	SEL_KPL	0		/* kernel priority level */
51 #define	SEL_UPL	3		/* user priority level */
52 
53 /*
54  * definitions of cpu-dependent requirements
55  * referenced in generic code
56  */
57 
58 /* Thread create/destroy */
59 int cpu_tfork(struct proc *, struct proc *);
60 volatile void cpu_texit(struct proc *);
61 
62 /* POSIX specific cpu-dependant functions */
63 #define cpu_wait(p)			/* recover resources after exit() */
64 void cpu_execsetregs(struct proc *, caddr_t, caddr_t);	/* start program */
65 int cpu_signal(struct proc *, int, int);		/* issue a signal */
66 int cpu_signalreturn(struct proc *);			/* remove a signal */
67 int *cpu_ptracereg(struct proc *, int);	/* return address of a register */
68 
69 /* implementation dependant */
70 void cpu_startup(void);
71 void cpu_reset(void);
72 #define	inittodr(s)	/* sorry, no GMT todr, only localtime cmos clock */
73 extern int (*cpu_dna)(void *);
74 extern int (*cpu_dna_em)(void *);
75 
76 /*
77  * Arguments to hardclock, softclock and gatherstats
78  * encapsulate the previous machine state in an opaque
79  * clockframe.
80  */
81 struct clock_frame {
82 	int cf_ipm;	/* interrupt priority mask when clock interrupted */
83 	int cf_eip;	/* location in program when clock interrupted */
84 	int cf_cs;	/* code selector when clock interrupted */
85 };
86 typedef struct clock_frame clockframe;
87 
88 #define	CLKF_BASEPRI(fp)	((fp)->cf_ipm == 0)
89 #define	CLKF_USERMODE(fp)	(ISPL((fp)->cf_cs) == SEL_UPL)
90 #define	CLKF_PC(fp)		((fp)->cf_eip)
91 #define setsoftclock()		sclkpending++
92 #define setsoftnet()		netpending++
93 
94 #define	resettodr()			/* no todr to set */
95 
96 /*
97  * If in a process, force the process to reschedule and thus be
98  * preempted.
99  */
100 #define	need_resched() \
101 	if (curproc) curproc->p_md.md_flags |= MDP_AST | MDP_RESCHED
102 
103 /*
104  * Give a profiling tick to the current process from the softclock
105  * interrupt.
106  */
107 #define	profile_tick(p, fp) addupc((fp)->cf_eip, &(p)->p_stats->p_prof, 1)
108 
109 /*
110  * Notify the current process (p) that it has a signal pending,
111  * process as soon as possible.
112  */
113 #define	cpu_signotify(p)	(p)->p_md.md_flags |= MDP_AST
114 
115 extern int	sclkpending;	/* need to do a softclock() on return to basepri */
116 extern int	netpending;	/* need to do a netintr() on return to basepri */
117 extern volatile int	cpl;	/* current priority level(mask) of interrupt controller */
118 
119 /* global bit vector of options */
120 extern int	cpu_option;
121 
122 /* various processor dependant options, referenced during execution */
123 #define	CPU_386_KR	0x00000001	/* simulate kernel read protection */
124 #define	CPU_486_INVC	0x00000002	/* use instructions to invalidate cache on I/O */
125 #define	CPU_486_INVTLB	0x00000004	/* invalidate TLB cache by pages */
126 #define	CPU_486_NPXEXCP	0x00000008	/* npx exception instead of interrupt */
127 #define	CPU_486_ALIGN	0x00000010	/* align exception */
128 #define	CPU_PENT_WBACK	0x00000020	/* pentium write back cache */
129 #define	CPU_PENT_4MBPG	0x00000040	/* pentium 4MB pages */
130 
131 /* by default, a 386 should ... */
132 #define	CPU_386_DEFAULT		(CPU_386_KR)
133 
134 /* by default, a 486 should ... */
135 #define	CPU_486_DEFAULT		(CPU_486_NPXEXCP)
136 
137 /* by default, a pentium should ... */
138 #define	CPU_PENT_DEFAULT	(CPU_PENT_WBACK)
139 
140 /* which process context holds the coprocessor(NPX), if any */
141 extern struct	proc	*npxproc;
142 
143 #endif
144