cpu.h revision 302408
145940Sobrien/*-
245135Sobrien * Copyright (c) 1990 The Regents of the University of California.
345135Sobrien * All rights reserved.
445135Sobrien *
545135Sobrien * This code is derived from software contributed to Berkeley by
645135Sobrien * William Jolitz.
745135Sobrien *
845135Sobrien * Redistribution and use in source and binary forms, with or without
945135Sobrien * modification, are permitted provided that the following conditions
1045135Sobrien * are met:
1145135Sobrien * 1. Redistributions of source code must retain the above copyright
1245135Sobrien *    notice, this list of conditions and the following disclaimer.
1345135Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1445135Sobrien *    notice, this list of conditions and the following disclaimer in the
1545135Sobrien *    documentation and/or other materials provided with the distribution.
1645135Sobrien * 4. Neither the name of the University nor the names of its contributors
1745135Sobrien *    may be used to endorse or promote products derived from this software
1845135Sobrien *    without specific prior written permission.
1945135Sobrien *
2045135Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2145135Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2245135Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2345135Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2445135Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2545135Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2645135Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2745135Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2845135Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2945135Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3045277Sobrien * SUCH DAMAGE.
3145135Sobrien *
3245135Sobrien *	from: @(#)cpu.h	5.4 (Berkeley) 5/9/91
3345135Sobrien * $FreeBSD: stable/11/sys/i386/include/cpu.h 267526 2014-06-16 08:43:03Z royger $
3445135Sobrien */
3545135Sobrien
3645135Sobrien#ifndef _MACHINE_CPU_H_
3745135Sobrien#define	_MACHINE_CPU_H_
3845940Sobrien
3945135Sobrien/*
4045135Sobrien * Definitions unique to i386 cpu support.
4145135Sobrien */
4245135Sobrien#include <machine/psl.h>
4345135Sobrien#include <machine/frame.h>
4445135Sobrien#include <machine/segments.h>
4545135Sobrien
4645135Sobrien#define	cpu_exec(p)	/* nothing */
4745135Sobrien#define	cpu_swapin(p)	/* nothing */
4845135Sobrien#define	cpu_getstack(td)		((td)->td_frame->tf_esp)
4945135Sobrien#define	cpu_setstack(td, ap)		((td)->td_frame->tf_esp = (ap))
5045135Sobrien#define	cpu_spinwait()			ia32_pause()
5145135Sobrien
5245135Sobrien#define	TRAPF_USERMODE(framep) \
5345135Sobrien	((ISPL((framep)->tf_cs) == SEL_UPL) || ((framep)->tf_eflags & PSL_VM))
5445135Sobrien#define	TRAPF_PC(framep)	((framep)->tf_eip)
5545135Sobrien
5645135Sobrien#ifdef _KERNEL
5745940Sobrien/*
5845135Sobrien * Struct containing pointers to CPU management functions whose
5945135Sobrien * implementation is run time selectable.  Selection can be made,
6045135Sobrien * for example, based on detection of a particular CPU variant or
6145135Sobrien * hypervisor environment.
6245135Sobrien */
6345317Sobrienstruct cpu_ops {
6445317Sobrien	void (*cpu_init)(void);
6545474Sbde	void (*cpu_resume)(void);
6645135Sobrien};
6745458Sobrien
6845458Sobrienextern struct	cpu_ops cpu_ops;
6945458Sobrienextern char	btext[];
7045458Sobrienextern char	etext[];
7145458Sobrien
7245135Sobrienvoid	cpu_halt(void);
7345670Sobrienvoid	cpu_reset(void);
7445670Sobrienvoid	fork_trampoline(void);
7545670Sobrienvoid	swi_vm(void *);
7645670Sobrien
7745458Sobrien/*
7845670Sobrien * Return contents of in-cpu fast counter as a sort of "bogo-time"
7945135Sobrien * for random-harvesting purposes.
8045135Sobrien */
8145135Sobrienstatic __inline uint64_t
8245135Sobrienget_cyclecount(void)
8345135Sobrien{
8445135Sobrien
8545277Sobrien	return (cpu_ticks());
8645135Sobrien}
8745135Sobrien
8845135Sobrien#endif
8945135Sobrien
9045135Sobrien#endif /* !_MACHINE_CPU_H_ */
9145135Sobrien