xref: /freebsd/sys/amd64/include/cpu.h (revision 4090154b9e6175090e42d3e5fcccfbc6d690eeb1)
15b81b6b3SRodney W. Grimes /*-
25b81b6b3SRodney W. Grimes  * Copyright (c) 1990 The Regents of the University of California.
35b81b6b3SRodney W. Grimes  * All rights reserved.
45b81b6b3SRodney W. Grimes  *
55b81b6b3SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
65b81b6b3SRodney W. Grimes  * William Jolitz.
75b81b6b3SRodney W. Grimes  *
85b81b6b3SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
95b81b6b3SRodney W. Grimes  * modification, are permitted provided that the following conditions
105b81b6b3SRodney W. Grimes  * are met:
115b81b6b3SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
125b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
135b81b6b3SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
145b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
155b81b6b3SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
165b81b6b3SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
175b81b6b3SRodney W. Grimes  *    must display the following acknowledgement:
185b81b6b3SRodney W. Grimes  *	This product includes software developed by the University of
195b81b6b3SRodney W. Grimes  *	California, Berkeley and its contributors.
205b81b6b3SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
215b81b6b3SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
225b81b6b3SRodney W. Grimes  *    without specific prior written permission.
235b81b6b3SRodney W. Grimes  *
245b81b6b3SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
255b81b6b3SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
265b81b6b3SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
275b81b6b3SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
285b81b6b3SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
295b81b6b3SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
305b81b6b3SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
315b81b6b3SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
325b81b6b3SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
335b81b6b3SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
345b81b6b3SRodney W. Grimes  * SUCH DAMAGE.
355b81b6b3SRodney W. Grimes  *
3609f07fb0SRodney W. Grimes  *	from: @(#)cpu.h	5.4 (Berkeley) 5/9/91
374090154bSBruce Evans  *	$Id: cpu.h,v 1.33 1997/08/30 02:51:58 kato Exp $
385b81b6b3SRodney W. Grimes  */
395b81b6b3SRodney W. Grimes 
406e393973SGarrett Wollman #ifndef _MACHINE_CPU_H_
41e4b7e53dSBruce Evans #define	_MACHINE_CPU_H_
426e393973SGarrett Wollman 
435b81b6b3SRodney W. Grimes /*
445b81b6b3SRodney W. Grimes  * Definitions unique to i386 cpu support.
455b81b6b3SRodney W. Grimes  */
4648a09cf2SJohn Dyson #include <machine/psl.h>
47f540b106SGarrett Wollman #include <machine/frame.h>
48f540b106SGarrett Wollman #include <machine/segments.h>
495b81b6b3SRodney W. Grimes 
505b81b6b3SRodney W. Grimes /*
51662f9a69SKATO Takenori  * Architecture dependent constant for i386 based machines.
52662f9a69SKATO Takenori  */
53662f9a69SKATO Takenori #ifdef PC98
54662f9a69SKATO Takenori /* NEC PC-9801/9821 series and compatibles. */
55662f9a69SKATO Takenori #define	MACHINE_ARCH	"pc-98"
56662f9a69SKATO Takenori #else
57662f9a69SKATO Takenori /* IBM-PC compatibles. */
58662f9a69SKATO Takenori #define	MACHINE_ARCH	"ibm-pc"
59662f9a69SKATO Takenori #endif
60662f9a69SKATO Takenori 
61662f9a69SKATO Takenori /*
625b81b6b3SRodney W. Grimes  * definitions of cpu-dependent requirements
635b81b6b3SRodney W. Grimes  * referenced in generic code
645b81b6b3SRodney W. Grimes  */
655b81b6b3SRodney W. Grimes #undef	COPY_SIGCODE		/* don't copy sigcode above user stack in exec */
665b81b6b3SRodney W. Grimes 
675b81b6b3SRodney W. Grimes #define	cpu_exec(p)	/* nothing */
6826f9a767SRodney W. Grimes #define cpu_swapin(p)	/* nothing */
6978966e20SBruce Evans #define cpu_setstack(p, ap)		((p)->p_md.md_regs[SP] = (ap))
7078966e20SBruce Evans #define cpu_set_init_frame(p, fp)	((p)->p_md.md_regs = (fp))
715b81b6b3SRodney W. Grimes 
7248a09cf2SJohn Dyson #define	CLKF_USERMODE(framep) \
7340d50994SPhilippe Charnier 	((ISPL((framep)->cf_cs) == SEL_UPL) || (framep->cf_eflags & PSL_VM))
7448a09cf2SJohn Dyson 
75b39b673dSBruce Evans #define CLKF_INTR(framep)	(intr_nesting_level >= 2)
7691290462SBruce Evans #if 0
77c342b9faSBruce Evans /*
78c342b9faSBruce Evans  * XXX splsoftclock() is very broken and barely worth fixing.  It doesn't
79c342b9faSBruce Evans  * turn off the clock bit in imen or in the icu.  (This is not a serious
80c342b9faSBruce Evans  * problem at 100 Hz but it is serious at 16000 Hz for pcaudio.  softclock()
81c342b9faSBruce Evans  * can take more than 62.5 usec so clock interrupts are lost.)  It doesn't
82c342b9faSBruce Evans  * check for pending interrupts being unmasked.  clkintr() and Xintr0()
83c342b9faSBruce Evans  * assume that the ipl is high when hardclock() returns.  Our SWI_AST
84c342b9faSBruce Evans  * handling is efficient enough that little is gained by calling
85c342b9faSBruce Evans  * softclock() directly.
86c342b9faSBruce Evans  */
8726f9a767SRodney W. Grimes #define	CLKF_BASEPRI(framep)	(((framep)->cf_ppl & ~SWI_AST_MASK) == 0)
88c342b9faSBruce Evans #else
89c342b9faSBruce Evans #define	CLKF_BASEPRI(framep)	(0)
90c342b9faSBruce Evans #endif
9126f9a767SRodney W. Grimes #define	CLKF_PC(framep)		((framep)->cf_eip)
925b81b6b3SRodney W. Grimes 
935b81b6b3SRodney W. Grimes /*
945b81b6b3SRodney W. Grimes  * Preempt the current process if in interrupt from user mode,
955b81b6b3SRodney W. Grimes  * or after the current trap/syscall if in system mode.
965b81b6b3SRodney W. Grimes  */
97d2306226SDavid Greenman #define	need_resched()	{ want_resched = 1; aston(); }
985b81b6b3SRodney W. Grimes 
995b81b6b3SRodney W. Grimes /*
10079df6d85SBruce Evans  * Arrange to handle pending profiling ticks before returning to user mode.
10179df6d85SBruce Evans  *
10279df6d85SBruce Evans  * XXX this is now poorly named and implemented.  It used to handle only a
10379df6d85SBruce Evans  * single tick and the P_OWEUPC flag served as a counter.  Now there is a
10479df6d85SBruce Evans  * counter in the proc table and flag isn't really necessary.
1055b81b6b3SRodney W. Grimes  */
10626f9a767SRodney W. Grimes #define	need_proftick(p)	{ (p)->p_flag |= P_OWEUPC; aston(); }
1075b81b6b3SRodney W. Grimes 
1085b81b6b3SRodney W. Grimes /*
1095b81b6b3SRodney W. Grimes  * Notify the current process (p) that it has a signal pending,
1105b81b6b3SRodney W. Grimes  * process as soon as possible.
1115b81b6b3SRodney W. Grimes  */
1125b81b6b3SRodney W. Grimes #define	signotify(p)	aston()
1135b81b6b3SRodney W. Grimes 
114d2306226SDavid Greenman #define aston()	setsoftast()
115d2306226SDavid Greenman #define astoff()
1165b81b6b3SRodney W. Grimes 
1175b81b6b3SRodney W. Grimes /*
11809f07fb0SRodney W. Grimes  * pull in #defines for kinds of processors
1195b81b6b3SRodney W. Grimes  */
120e4b7e53dSBruce Evans #include <machine/cputypes.h>
1215b81b6b3SRodney W. Grimes 
12209f07fb0SRodney W. Grimes struct cpu_nameclass {
12309f07fb0SRodney W. Grimes 	char *cpu_name;
12409f07fb0SRodney W. Grimes 	int  cpu_class;
12509f07fb0SRodney W. Grimes };
12609f07fb0SRodney W. Grimes 
12726f9a767SRodney W. Grimes /*
12826f9a767SRodney W. Grimes  * CTL_MACHDEP definitions.
12926f9a767SRodney W. Grimes  */
13026f9a767SRodney W. Grimes #define CPU_CONSDEV		1	/* dev_t: console terminal device */
131fe0d5f43SAndrey A. Chernov #define	CPU_ADJKERNTZ		2	/* int:	timezone offset	(seconds) */
132f80d8a2eSAndrey A. Chernov #define	CPU_DISRTCSET		3	/* int: disable resettodr() call */
1337a2dada5SPoul-Henning Kamp #define CPU_BOOTINFO		4	/* struct: bootinfo */
134fe0d5f43SAndrey A. Chernov #define	CPU_WALLCLOCK		5	/* int:	indicates wall CMOS clock */
135fe0d5f43SAndrey A. Chernov #define	CPU_MAXID		6	/* number of valid machdep ids */
13626f9a767SRodney W. Grimes 
13726f9a767SRodney W. Grimes #define CTL_MACHDEP_NAMES { \
13826f9a767SRodney W. Grimes 	{ 0, 0 }, \
13926f9a767SRodney W. Grimes 	{ "console_device", CTLTYPE_STRUCT }, \
140dd067f08SAndrey A. Chernov 	{ "adjkerntz", CTLTYPE_INT }, \
141f80d8a2eSAndrey A. Chernov 	{ "disable_rtc_set", CTLTYPE_INT }, \
1427a2dada5SPoul-Henning Kamp 	{ "bootinfo", CTLTYPE_STRUCT }, \
143fe0d5f43SAndrey A. Chernov 	{ "wall_cmos_clock", CTLTYPE_INT }, \
14426f9a767SRodney W. Grimes }
14526f9a767SRodney W. Grimes 
14609f07fb0SRodney W. Grimes #ifdef KERNEL
1474090154bSBruce Evans extern char	btext[];
14809f07fb0SRodney W. Grimes extern int	cpu;
14909f07fb0SRodney W. Grimes extern int	cpu_class;
1504090154bSBruce Evans extern char	etext[];
151b39b673dSBruce Evans extern u_char	intr_nesting_level;
152c342b9faSBruce Evans extern int	want_resched;	/* resched was called */
153a2a1c95cSPeter Wemm 
154a2a1c95cSPeter Wemm void	fork_trampoline __P((void));
155a2a1c95cSPeter Wemm void	fork_return __P((struct proc *, struct trapframe));
156a2a1c95cSPeter Wemm void	cpu_set_fork_handler __P((struct proc *, void (*pc)(void *), void *));
15709f07fb0SRodney W. Grimes #endif
158e4b7e53dSBruce Evans 
159e4b7e53dSBruce Evans #endif /* !_MACHINE_CPU_H_ */
160