14Srgrimes/*- 24Srgrimes * Copyright (c) 1990 The Regents of the University of California. 34Srgrimes * All rights reserved. 44Srgrimes * 54Srgrimes * This code is derived from software contributed to Berkeley by 64Srgrimes * William Jolitz. 74Srgrimes * 84Srgrimes * Redistribution and use in source and binary forms, with or without 94Srgrimes * modification, are permitted provided that the following conditions 104Srgrimes * are met: 114Srgrimes * 1. Redistributions of source code must retain the above copyright 124Srgrimes * notice, this list of conditions and the following disclaimer. 134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 144Srgrimes * notice, this list of conditions and the following disclaimer in the 154Srgrimes * documentation and/or other materials provided with the distribution. 164Srgrimes * 4. Neither the name of the University nor the names of its contributors 174Srgrimes * may be used to endorse or promote products derived from this software 184Srgrimes * without specific prior written permission. 194Srgrimes * 204Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304Srgrimes * SUCH DAMAGE. 314Srgrimes * 32557Srgrimes * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91 3350477Speter * $FreeBSD$ 344Srgrimes */ 354Srgrimes 36719Swollman#ifndef _MACHINE_CPU_H_ 372866Sbde#define _MACHINE_CPU_H_ 38719Swollman 394Srgrimes/* 404Srgrimes * Definitions unique to i386 cpu support. 414Srgrimes */ 4227993Sdyson#include <machine/psl.h> 432056Swollman#include <machine/frame.h> 442056Swollman#include <machine/segments.h> 454Srgrimes 464Srgrimes#define cpu_exec(p) /* nothing */ 47133084Smux#define cpu_swapin(p) /* nothing */ 48114349Speter#define cpu_getstack(td) ((td)->td_frame->tf_rsp) 49133084Smux#define cpu_setstack(td, ap) ((td)->td_frame->tf_rsp = (ap)) 50133084Smux#define cpu_spinwait() ia32_pause() 514Srgrimes 5272276Sjhb#define TRAPF_USERMODE(framep) \ 53114349Speter (ISPL((framep)->tf_cs) == SEL_UPL) 54114349Speter#define TRAPF_PC(framep) ((framep)->tf_rip) 5572276Sjhb 56253750Savg#ifdef _KERNEL 57255331Sgibbs/* 58255331Sgibbs * Struct containing pointers to CPU management functions whose 59255331Sgibbs * implementation is run time selectable. Selection can be made, 60255331Sgibbs * for example, based on detection of a particular CPU variant or 61255331Sgibbs * hypervisor environment. 62255331Sgibbs */ 63255331Sgibbsstruct cpu_ops { 64255744Sgibbs void (*cpu_init)(void); 65255744Sgibbs void (*cpu_resume)(void); 66255331Sgibbs void (*ipi_vectored)(u_int, int); 67255331Sgibbs}; 68255331Sgibbs 69255331Sgibbsextern struct cpu_ops cpu_ops; 7030789Sbdeextern char btext[]; 7130789Sbdeextern char etext[]; 7224691Speter 73118990Smarcelvoid cpu_halt(void); 74118990Smarcelvoid cpu_reset(void); 7592761Salfredvoid fork_trampoline(void); 76118990Smarcelvoid swi_vm(void *); 7769003Smarkm 7869003Smarkm/* 7969003Smarkm * Return contents of in-cpu fast counter as a sort of "bogo-time" 80110368Sphk * for random-harvesting purposes. 8169003Smarkm */ 8269003Smarkmstatic __inline u_int64_t 8369003Smarkmget_cyclecount(void) 8469003Smarkm{ 8569003Smarkm 8669003Smarkm return (rdtsc()); 8769003Smarkm} 882866Sbde 8969003Smarkm#endif 9069003Smarkm 912866Sbde#endif /* !_MACHINE_CPU_H_ */ 92