cpu.h revision 267526
1139747Simp/*-
24Srgrimes * Copyright (c) 1990 The Regents of the University of California.
34Srgrimes * All rights reserved.
44Srgrimes *
58876Srgrimes * 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:
118876Srgrimes * 1. Redistributions of source code must retain the above copyright
128876Srgrimes *    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
158876Srgrimes *    documentation and/or other materials provided with the distribution.
164Srgrimes * 4. Neither the name of the University nor the names of its contributors
178876Srgrimes *    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
228876Srgrimes * 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 *
324Srgrimes *	from: @(#)cpu.h	5.4 (Berkeley) 5/9/91
33116176Sobrien * $FreeBSD: head/sys/i386/include/cpu.h 267526 2014-06-16 08:43:03Z royger $
34116176Sobrien */
35116176Sobrien
36116176Sobrien#ifndef _MACHINE_CPU_H_
372056Swollman#define	_MACHINE_CPU_H_
38174914Srwatson
3912734Sbde/*
402056Swollman * Definitions unique to i386 cpu support.
414Srgrimes */
424Srgrimes#include <machine/psl.h>
43174914Srwatson#include <machine/frame.h>
4412720Sphk#include <machine/segments.h>
454Srgrimes
4692756Salfred#define	cpu_exec(p)	/* nothing */
4792756Salfred#define	cpu_swapin(p)	/* nothing */
4892756Salfred#define	cpu_getstack(td)		((td)->td_frame->tf_esp)
4992756Salfred#define	cpu_setstack(td, ap)		((td)->td_frame->tf_esp = (ap))
502112Swollman#define	cpu_spinwait()			ia32_pause()
514Srgrimes
52273006Spfg#define	TRAPF_USERMODE(framep) \
534Srgrimes	((ISPL((framep)->tf_cs) == SEL_UPL) || ((framep)->tf_eflags & PSL_VM))
544Srgrimes#define	TRAPF_PC(framep)	((framep)->tf_eip)
554Srgrimes
564Srgrimes#ifdef _KERNEL
574Srgrimes/*
584Srgrimes * Struct containing pointers to CPU management functions whose
594Srgrimes * implementation is run time selectable.  Selection can be made,
604Srgrimes * for example, based on detection of a particular CPU variant or
614Srgrimes * hypervisor environment.
624Srgrimes */
634Srgrimesstruct cpu_ops {
64174914Srwatson	void (*cpu_init)(void);
65174914Srwatson	void (*cpu_resume)(void);
66174914Srwatson};
67174914Srwatson
68174914Srwatsonextern struct	cpu_ops cpu_ops;
69174914Srwatsonextern char	btext[];
70174914Srwatsonextern char	etext[];
71174914Srwatson
72174914Srwatsonvoid	cpu_halt(void);
73174914Srwatsonvoid	cpu_reset(void);
74174914Srwatsonvoid	fork_trampoline(void);
75174914Srwatsonvoid	swi_vm(void *);
76174914Srwatson
77174914Srwatson/*
78174914Srwatson * Return contents of in-cpu fast counter as a sort of "bogo-time"
79174914Srwatson * for random-harvesting purposes.
80174914Srwatson */
81174914Srwatsonstatic __inline uint64_t
82174914Srwatsonget_cyclecount(void)
83174914Srwatson{
84174914Srwatson
85174914Srwatson	return (cpu_ticks());
86174914Srwatson}
87174914Srwatson
88174914Srwatson#endif
89174914Srwatson
9012515Sphk#endif /* !_MACHINE_CPU_H_ */
914Srgrimes