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. 16*fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 175b81b6b3SRodney W. Grimes * may be used to endorse or promote products derived from this software 185b81b6b3SRodney W. Grimes * without specific prior written permission. 195b81b6b3SRodney W. Grimes * 205b81b6b3SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 215b81b6b3SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 225b81b6b3SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 235b81b6b3SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 245b81b6b3SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 255b81b6b3SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 265b81b6b3SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 275b81b6b3SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 285b81b6b3SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 295b81b6b3SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 305b81b6b3SRodney W. Grimes * SUCH DAMAGE. 315b81b6b3SRodney W. Grimes * 3209f07fb0SRodney W. Grimes * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91 33c3aac50fSPeter Wemm * $FreeBSD$ 345b81b6b3SRodney W. Grimes */ 355b81b6b3SRodney W. Grimes 366e393973SGarrett Wollman #ifndef _MACHINE_CPU_H_ 37e4b7e53dSBruce Evans #define _MACHINE_CPU_H_ 386e393973SGarrett Wollman 395b81b6b3SRodney W. Grimes /* 405b81b6b3SRodney W. Grimes * Definitions unique to i386 cpu support. 415b81b6b3SRodney W. Grimes */ 4248a09cf2SJohn Dyson #include <machine/psl.h> 43f540b106SGarrett Wollman #include <machine/frame.h> 44f540b106SGarrett Wollman #include <machine/segments.h> 455b81b6b3SRodney W. Grimes 465b81b6b3SRodney W. Grimes #define cpu_exec(p) /* nothing */ 4726f9a767SRodney W. Grimes #define cpu_swapin(p) /* nothing */ 48afa88623SPeter Wemm #define cpu_getstack(td) ((td)->td_frame->tf_rsp) 49afa88623SPeter Wemm #define cpu_setstack(td, ap) ((td)->td_frame->tf_rsp = (ap)) 509f1b87f1SMaxime Henrion #define cpu_spinwait() ia32_pause() 515b81b6b3SRodney W. Grimes 52142ba5f3SJohn Baldwin #define TRAPF_USERMODE(framep) \ 53afa88623SPeter Wemm (ISPL((framep)->tf_cs) == SEL_UPL) 54afa88623SPeter Wemm #define TRAPF_PC(framep) ((framep)->tf_rip) 55142ba5f3SJohn Baldwin 56a29cc9a3SAndriy Gapon #ifdef _KERNEL 57e44af46eSJustin T. Gibbs /* 58e44af46eSJustin T. Gibbs * Struct containing pointers to CPU management functions whose 59e44af46eSJustin T. Gibbs * implementation is run time selectable. Selection can be made, 60e44af46eSJustin T. Gibbs * for example, based on detection of a particular CPU variant or 61e44af46eSJustin T. Gibbs * hypervisor environment. 62e44af46eSJustin T. Gibbs */ 63e44af46eSJustin T. Gibbs struct cpu_ops { 64566a5f50SJustin T. Gibbs void (*cpu_init)(void); 65566a5f50SJustin T. Gibbs void (*cpu_resume)(void); 66e44af46eSJustin T. Gibbs }; 67e44af46eSJustin T. Gibbs 68e44af46eSJustin T. Gibbs extern struct cpu_ops cpu_ops; 694090154bSBruce Evans extern char btext[]; 704090154bSBruce Evans extern char etext[]; 71a2a1c95cSPeter Wemm 7263e62d39SJohn Baldwin /* Resume hook for VMM. */ 7363e62d39SJohn Baldwin extern void (*vmm_resume_p)(void); 7463e62d39SJohn Baldwin 7526502503SMarcel Moolenaar void cpu_halt(void); 7626502503SMarcel Moolenaar void cpu_reset(void); 77b63dc6adSAlfred Perlstein void fork_trampoline(void); 7826502503SMarcel Moolenaar void swi_vm(void *); 7958550067SMark Murray 8058550067SMark Murray /* 8158550067SMark Murray * Return contents of in-cpu fast counter as a sort of "bogo-time" 82553ebddcSPoul-Henning Kamp * for random-harvesting purposes. 8358550067SMark Murray */ 8458550067SMark Murray static __inline u_int64_t 8558550067SMark Murray get_cyclecount(void) 8658550067SMark Murray { 8758550067SMark Murray 8858550067SMark Murray return (rdtsc()); 8958550067SMark Murray } 9058550067SMark Murray 9109f07fb0SRodney W. Grimes #endif 92e4b7e53dSBruce Evans 93e4b7e53dSBruce Evans #endif /* !_MACHINE_CPU_H_ */ 94