cpu.h revision 219672
168349Sobrien/*-
268349Sobrien * Copyright (c) 1990 The Regents of the University of California.
368349Sobrien * All rights reserved.
468349Sobrien *
568349Sobrien * This code is derived from software contributed to Berkeley by
668349Sobrien * William Jolitz.
768349Sobrien *
868349Sobrien * Redistribution and use in source and binary forms, with or without
968349Sobrien * modification, are permitted provided that the following conditions
1068349Sobrien * are met:
1168349Sobrien * 1. Redistributions of source code must retain the above copyright
1268349Sobrien *    notice, this list of conditions and the following disclaimer.
1368349Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1468349Sobrien *    notice, this list of conditions and the following disclaimer in the
1568349Sobrien *    documentation and/or other materials provided with the distribution.
1668349Sobrien * 4. Neither the name of the University nor the names of its contributors
1768349Sobrien *    may be used to endorse or promote products derived from this software
1868349Sobrien *    without specific prior written permission.
1968349Sobrien *
2068349Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2168349Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2268349Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2368349Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2468349Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2568349Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2668349Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2768349Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2868349Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2968349Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3068349Sobrien * SUCH DAMAGE.
3168349Sobrien *
3268349Sobrien *	from: @(#)cpu.h	5.4 (Berkeley) 5/9/91
3368349Sobrien * $FreeBSD: head/sys/i386/include/cpu.h 219672 2011-03-15 17:14:26Z jkim $
3468349Sobrien */
3568349Sobrien
3668349Sobrien#ifndef _MACHINE_CPU_H_
3768349Sobrien#define	_MACHINE_CPU_H_
3868349Sobrien
3968349Sobrien/*
4068349Sobrien * Definitions unique to i386 cpu support.
4168349Sobrien */
4268349Sobrien#include <machine/psl.h>
4368349Sobrien#include <machine/frame.h>
4468349Sobrien#include <machine/segments.h>
4568349Sobrien
4668349Sobrien#define	cpu_exec(p)	/* nothing */
4768349Sobrien#define	cpu_swapin(p)	/* nothing */
4868349Sobrien#define	cpu_getstack(td)		((td)->td_frame->tf_esp)
4968349Sobrien#define	cpu_setstack(td, ap)		((td)->td_frame->tf_esp = (ap))
5068349Sobrien#define	cpu_spinwait()			ia32_pause()
5168349Sobrien
5268349Sobrien#define	TRAPF_USERMODE(framep) \
5368349Sobrien	((ISPL((framep)->tf_cs) == SEL_UPL) || ((framep)->tf_eflags & PSL_VM))
5468349Sobrien#define	TRAPF_PC(framep)	((framep)->tf_eip)
5568349Sobrien
5668349Sobrien#ifdef _KERNEL
5768349Sobrienextern char	btext[];
5868349Sobrienextern char	etext[];
5968349Sobrienextern int	tsc_present;
6068349Sobrien
6168349Sobrienvoid	cpu_halt(void);
6268349Sobrienvoid	cpu_reset(void);
6368349Sobrienvoid	fork_trampoline(void);
6468349Sobrienvoid	swi_vm(void *);
6568349Sobrien
6668349Sobrien/*
6768349Sobrien * Return contents of in-cpu fast counter as a sort of "bogo-time"
6868349Sobrien * for random-harvesting purposes.
6968349Sobrien */
7068349Sobrienstatic __inline uint64_t
7168349Sobrienget_cyclecount(void)
7268349Sobrien{
7368349Sobrien	struct bintime bt;
7468349Sobrien
7568349Sobrien	binuptime(&bt);
7668349Sobrien	return ((uint64_t)bt.sec << 56 | bt.frac >> 8);
7768349Sobrien}
7868349Sobrien
7968349Sobrien#endif
8068349Sobrien
8168349Sobrien#endif /* !_MACHINE_CPU_H_ */
8268349Sobrien