cpu.h revision 81493
152400Sbillf/*- 252400Sbillf * Copyright (c) 1990 The Regents of the University of California. 352400Sbillf * All rights reserved. 452400Sbillf * 552400Sbillf * This code is derived from software contributed to Berkeley by 652400Sbillf * William Jolitz. 752400Sbillf * 8201765Sdougb * Redistribution and use in source and binary forms, with or without 973651Sdougb * modification, are permitted provided that the following conditions 1052400Sbillf * are met: 1152495Sbillf * 1. Redistributions of source code must retain the above copyright 1252400Sbillf * notice, this list of conditions and the following disclaimer. 1368507Sdougb * 2. Redistributions in binary form must reproduce the above copyright 1452400Sbillf * notice, this list of conditions and the following disclaimer in the 1552400Sbillf * documentation and/or other materials provided with the distribution. 1652533Sbillf * 3. All advertising materials mentioning features or use of this software 1752400Sbillf * must display the following acknowledgement: 18189992Sdougb * This product includes software developed by the University of 19189763Sdougb * California, Berkeley and its contributors. 2052400Sbillf * 4. Neither the name of the University nor the names of its contributors 2152400Sbillf * may be used to endorse or promote products derived from this software 2252400Sbillf * without specific prior written permission. 2352400Sbillf * 2452400Sbillf * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2552400Sbillf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2652400Sbillf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2767949Sdougb * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2891193Sdougb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29190320Sdougb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3091193Sdougb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31114501Sdougb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32189763Sdougb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33189763Sdougb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3452400Sbillf * SUCH DAMAGE. 3552400Sbillf * 3652400Sbillf * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91 3752400Sbillf * $FreeBSD: head/sys/amd64/include/cpu.h 81493 2001-08-10 22:53:32Z jhb $ 3852400Sbillf */ 39155309Srwatson 4067949Sdougb#ifndef _MACHINE_CPU_H_ 4152400Sbillf#define _MACHINE_CPU_H_ 4252400Sbillf 4352400Sbillf/* 4452400Sbillf * Definitions unique to i386 cpu support. 4552400Sbillf */ 4652400Sbillf#include <machine/psl.h> 4752400Sbillf#include <machine/frame.h> 4867859Sdougb#include <machine/segments.h> 4967949Sdougb#include <machine/globals.h> 5052400Sbillf 5152400Sbillf/* 5258910Salfred * definitions of cpu-dependent requirements 5358910Salfred * referenced in generic code 5458910Salfred */ 5567850Sdougb#undef COPY_SIGCODE /* don't copy sigcode above user stack in exec */ 5667850Sdougb 5767850Sdougb#define cpu_exec(p) /* nothing */ 5867850Sdougb#define cpu_swapin(p) /* nothing */ 5967850Sdougb#define cpu_getstack(p) ((p)->p_frame->tf_esp) 6067850Sdougb#define cpu_setstack(p, ap) ((p)->p_frame->tf_esp = (ap)) 6167850Sdougb 6267850Sdougb#define TRAPF_USERMODE(framep) \ 6367850Sdougb ((ISPL((framep)->tf_cs) == SEL_UPL) || ((framep)->tf_eflags & PSL_VM)) 6467850Sdougb#define TRAPF_PC(framep) ((framep)->tf_eip) 6567850Sdougb 6667850Sdougb#define CLKF_USERMODE(framep) \ 6767949Sdougb ((ISPL((framep)->cf_cs) == SEL_UPL) || ((framep)->cf_eflags & PSL_VM)) 6867850Sdougb#define CLKF_PC(framep) ((framep)->cf_eip) 6967850Sdougb 7067850Sdougb/* 7167850Sdougb * CTL_MACHDEP definitions. 7267850Sdougb */ 7367850Sdougb#define CPU_CONSDEV 1 /* dev_t: console terminal device */ 7467850Sdougb#define CPU_ADJKERNTZ 2 /* int: timezone offset (seconds) */ 7567850Sdougb#define CPU_DISRTCSET 3 /* int: disable resettodr() call */ 7667859Sdougb#define CPU_BOOTINFO 4 /* struct: bootinfo */ 7767859Sdougb#define CPU_WALLCLOCK 5 /* int: indicates wall CMOS clock */ 7858910Salfred#define CPU_MAXID 6 /* number of valid machdep ids */ 7967850Sdougb 8067850Sdougb#define CTL_MACHDEP_NAMES { \ 8167850Sdougb { 0, 0 }, \ 8267850Sdougb { "console_device", CTLTYPE_STRUCT }, \ 8367850Sdougb { "adjkerntz", CTLTYPE_INT }, \ 8467850Sdougb { "disable_rtc_set", CTLTYPE_INT }, \ 8567859Sdougb { "bootinfo", CTLTYPE_STRUCT }, \ 8667850Sdougb { "wall_cmos_clock", CTLTYPE_INT }, \ 8767859Sdougb} 8867850Sdougb 8967850Sdougb#ifdef _KERNEL 9067850Sdougbextern char btext[]; 9167850Sdougbextern char etext[]; 9267859Sdougbextern u_int tsc_present; 9367850Sdougb 9467850Sdougbvoid fork_trampoline __P((void)); 9567850Sdougb 9667850Sdougb/* 9767850Sdougb * Return contents of in-cpu fast counter as a sort of "bogo-time" 9867850Sdougb * for non-critical timing. 9967850Sdougb */ 10067850Sdougbstatic __inline u_int64_t 10167850Sdougbget_cyclecount(void) 10267850Sdougb{ 10367850Sdougb#if defined(I386_CPU) || defined(I486_CPU) 10467850Sdougb struct timespec tv; 10567850Sdougb 10667850Sdougb if (!tsc_present) { 10758910Salfred nanotime(&tv); 10858910Salfred return (tv.tv_sec * (u_int64_t)1000000000 + tv.tv_nsec); 10958910Salfred } 11058910Salfred#endif 11158910Salfred return (rdtsc()); 11258910Salfred} 11367850Sdougb 11458910Salfred#endif 11577323Sdougb 11677323Sdougb#endif /* !_MACHINE_CPU_H_ */ 11767949Sdougb