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 * 3409f07fb0SRodney W. Grimes * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91 35c3aac50fSPeter Wemm * $FreeBSD$ 365b81b6b3SRodney W. Grimes */ 375b81b6b3SRodney W. Grimes 386e393973SGarrett Wollman #ifndef _MACHINE_CPU_H_ 39e4b7e53dSBruce Evans #define _MACHINE_CPU_H_ 406e393973SGarrett Wollman 415b81b6b3SRodney W. Grimes /* 425b81b6b3SRodney W. Grimes * Definitions unique to i386 cpu support. 435b81b6b3SRodney W. Grimes */ 4448a09cf2SJohn Dyson #include <machine/psl.h> 45f540b106SGarrett Wollman #include <machine/frame.h> 46f540b106SGarrett Wollman #include <machine/segments.h> 475b81b6b3SRodney W. Grimes 485b81b6b3SRodney W. Grimes #define cpu_exec(p) /* nothing */ 4926f9a767SRodney W. Grimes #define cpu_swapin(p) /* nothing */ 50afa88623SPeter Wemm #define cpu_getstack(td) ((td)->td_frame->tf_rsp) 51afa88623SPeter Wemm #define cpu_setstack(td, ap) ((td)->td_frame->tf_rsp = (ap)) 529f1b87f1SMaxime Henrion #define cpu_spinwait() ia32_pause() 535b81b6b3SRodney W. Grimes 54142ba5f3SJohn Baldwin #define TRAPF_USERMODE(framep) \ 55afa88623SPeter Wemm (ISPL((framep)->tf_cs) == SEL_UPL) 56afa88623SPeter Wemm #define TRAPF_PC(framep) ((framep)->tf_rip) 57142ba5f3SJohn Baldwin 58a29cc9a3SAndriy Gapon #ifdef _KERNEL 59e44af46eSJustin T. Gibbs /* 60e44af46eSJustin T. Gibbs * Struct containing pointers to CPU management functions whose 61e44af46eSJustin T. Gibbs * implementation is run time selectable. Selection can be made, 62e44af46eSJustin T. Gibbs * for example, based on detection of a particular CPU variant or 63e44af46eSJustin T. Gibbs * hypervisor environment. 64e44af46eSJustin T. Gibbs */ 65e44af46eSJustin T. Gibbs struct cpu_ops { 66566a5f50SJustin T. Gibbs void (*cpu_init)(void); 67566a5f50SJustin T. Gibbs void (*cpu_resume)(void); 68e44af46eSJustin T. Gibbs }; 69e44af46eSJustin T. Gibbs 70e44af46eSJustin T. Gibbs extern struct cpu_ops cpu_ops; 71beb24065SJonathan T. Looney extern char brwsection[]; 724090154bSBruce Evans extern char btext[]; 73beb24065SJonathan T. Looney extern char _end[]; 744090154bSBruce Evans extern char etext[]; 75a2a1c95cSPeter Wemm 7663e62d39SJohn Baldwin /* Resume hook for VMM. */ 7763e62d39SJohn Baldwin extern void (*vmm_resume_p)(void); 7863e62d39SJohn Baldwin 7926502503SMarcel Moolenaar void cpu_halt(void); 8026502503SMarcel Moolenaar void cpu_reset(void); 81b63dc6adSAlfred Perlstein void fork_trampoline(void); 8226502503SMarcel Moolenaar void swi_vm(void *); 8358550067SMark Murray 8458550067SMark Murray /* 8558550067SMark Murray * Return contents of in-cpu fast counter as a sort of "bogo-time" 86553ebddcSPoul-Henning Kamp * for random-harvesting purposes. 8758550067SMark Murray */ 8858550067SMark Murray static __inline u_int64_t 8958550067SMark Murray get_cyclecount(void) 9058550067SMark Murray { 9158550067SMark Murray 9258550067SMark Murray return (rdtsc()); 9358550067SMark Murray } 9458550067SMark Murray 95*3f102f58SMateusz Guzik #define MEMSET_EARLY_FUNC memset_std 96*3f102f58SMateusz Guzik #define MEMCPY_EARLY_FUNC memcpy_std 97*3f102f58SMateusz Guzik #define MEMMOVE_EARLY_FUNC memmove_std 98*3f102f58SMateusz Guzik 9909f07fb0SRodney W. Grimes #endif 100e4b7e53dSBruce Evans 101e4b7e53dSBruce Evans #endif /* !_MACHINE_CPU_H_ */ 102