xref: /freebsd/sys/amd64/include/cpu.h (revision 0b32ef71f9f154f4da5037bfcbb4916960d38452)
15b81b6b3SRodney W. Grimes /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
45b81b6b3SRodney W. Grimes  * Copyright (c) 1990 The Regents of the University of California.
55b81b6b3SRodney W. Grimes  * All rights reserved.
65b81b6b3SRodney W. Grimes  *
75b81b6b3SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
85b81b6b3SRodney W. Grimes  * William Jolitz.
95b81b6b3SRodney W. Grimes  *
105b81b6b3SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
115b81b6b3SRodney W. Grimes  * modification, are permitted provided that the following conditions
125b81b6b3SRodney W. Grimes  * are met:
135b81b6b3SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
145b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
155b81b6b3SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
165b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
175b81b6b3SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
195b81b6b3SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
205b81b6b3SRodney W. Grimes  *    without specific prior written permission.
215b81b6b3SRodney W. Grimes  *
225b81b6b3SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
235b81b6b3SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
245b81b6b3SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
255b81b6b3SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
265b81b6b3SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
275b81b6b3SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
285b81b6b3SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
295b81b6b3SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
305b81b6b3SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
315b81b6b3SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
325b81b6b3SRodney W. Grimes  * SUCH DAMAGE.
335b81b6b3SRodney W. Grimes  */
345b81b6b3SRodney W. Grimes 
356e393973SGarrett Wollman #ifndef _MACHINE_CPU_H_
36e4b7e53dSBruce Evans #define	_MACHINE_CPU_H_
376e393973SGarrett Wollman 
385b81b6b3SRodney W. Grimes /*
395b81b6b3SRodney W. Grimes  * Definitions unique to i386 cpu support.
405b81b6b3SRodney W. Grimes  */
4148a09cf2SJohn Dyson #include <machine/psl.h>
42f540b106SGarrett Wollman #include <machine/frame.h>
43f540b106SGarrett Wollman #include <machine/segments.h>
445b81b6b3SRodney W. Grimes 
455b81b6b3SRodney W. Grimes #define	cpu_exec(p)	/* nothing */
4626f9a767SRodney W. Grimes #define	cpu_swapin(p)	/* nothing */
47afa88623SPeter Wemm #define	cpu_getstack(td)		((td)->td_frame->tf_rsp)
48afa88623SPeter Wemm #define	cpu_setstack(td, ap)		((td)->td_frame->tf_rsp = (ap))
499f1b87f1SMaxime Henrion #define	cpu_spinwait()			ia32_pause()
505b81b6b3SRodney W. Grimes 
51142ba5f3SJohn Baldwin #define	TRAPF_USERMODE(framep) \
52afa88623SPeter Wemm 	(ISPL((framep)->tf_cs) == SEL_UPL)
53afa88623SPeter Wemm #define	TRAPF_PC(framep)	((framep)->tf_rip)
54142ba5f3SJohn Baldwin 
55a29cc9a3SAndriy Gapon #ifdef _KERNEL
56e44af46eSJustin T. Gibbs /*
57e44af46eSJustin T. Gibbs  * Struct containing pointers to CPU management functions whose
58e44af46eSJustin T. Gibbs  * implementation is run time selectable.  Selection can be made,
59e44af46eSJustin T. Gibbs  * for example, based on detection of a particular CPU variant or
60e44af46eSJustin T. Gibbs  * hypervisor environment.
61e44af46eSJustin T. Gibbs  */
62e44af46eSJustin T. Gibbs struct cpu_ops {
63566a5f50SJustin T. Gibbs 	void (*cpu_init)(void);
64566a5f50SJustin T. Gibbs 	void (*cpu_resume)(void);
65e44af46eSJustin T. Gibbs };
66e44af46eSJustin T. Gibbs 
67e44af46eSJustin T. Gibbs extern struct	cpu_ops cpu_ops;
68beb24065SJonathan T. Looney extern char	brwsection[];
694090154bSBruce Evans extern char	btext[];
70beb24065SJonathan T. Looney extern char	_end[];
714090154bSBruce Evans extern char	etext[];
72a2a1c95cSPeter Wemm 
73*0b32ef71SJoshua Rogers /* Suspend and resume hook for VMM. */
74*0b32ef71SJoshua Rogers extern	void (*vmm_suspend_p)(void);
7563e62d39SJohn Baldwin extern	void (*vmm_resume_p)(void);
7663e62d39SJohn Baldwin 
7726502503SMarcel Moolenaar void	cpu_halt(void);
787f7f6f85SJohn Baldwin void	cpu_lock_delay(void);
7926502503SMarcel Moolenaar void	cpu_reset(void);
80b63dc6adSAlfred Perlstein void	fork_trampoline(void);
8158550067SMark Murray 
8258550067SMark Murray /*
8358550067SMark Murray  * Return contents of in-cpu fast counter as a sort of "bogo-time"
84553ebddcSPoul-Henning Kamp  * for random-harvesting purposes.
8558550067SMark Murray  */
8658550067SMark Murray static __inline u_int64_t
get_cyclecount(void)8758550067SMark Murray get_cyclecount(void)
8858550067SMark Murray {
8958550067SMark Murray 
9058550067SMark Murray 	return (rdtsc());
9158550067SMark Murray }
9258550067SMark Murray 
933f102f58SMateusz Guzik #define MEMSET_EARLY_FUNC       memset_std
943f102f58SMateusz Guzik #define MEMCPY_EARLY_FUNC       memcpy_std
953f102f58SMateusz Guzik #define MEMMOVE_EARLY_FUNC      memmove_std
963f102f58SMateusz Guzik 
9709f07fb0SRodney W. Grimes #endif
98e4b7e53dSBruce Evans 
99e4b7e53dSBruce Evans #endif /* !_MACHINE_CPU_H_ */
100