15b81b6b3SRodney W. Grimes /*- 25b81b6b3SRodney W. Grimes * Copyright (c) 1990 The Regents of the University of California. 35b81b6b3SRodney W. Grimes * All rights reserved. 45b81b6b3SRodney W. Grimes * 55b81b6b3SRodney W. Grimes * This code is derived from software contributed to Berkeley by 65b81b6b3SRodney W. Grimes * William Jolitz. 75b81b6b3SRodney W. Grimes * 85b81b6b3SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 95b81b6b3SRodney W. Grimes * modification, are permitted provided that the following conditions 105b81b6b3SRodney W. Grimes * are met: 115b81b6b3SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 125b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 135b81b6b3SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 145b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 155b81b6b3SRodney W. Grimes * documentation and/or other materials provided with the distribution. 165b81b6b3SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 175b81b6b3SRodney W. Grimes * must display the following acknowledgement: 185b81b6b3SRodney W. Grimes * This product includes software developed by the University of 195b81b6b3SRodney W. Grimes * California, Berkeley and its contributors. 205b81b6b3SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 215b81b6b3SRodney W. Grimes * may be used to endorse or promote products derived from this software 225b81b6b3SRodney W. Grimes * without specific prior written permission. 235b81b6b3SRodney W. Grimes * 245b81b6b3SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 255b81b6b3SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 265b81b6b3SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 275b81b6b3SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 285b81b6b3SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 295b81b6b3SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 305b81b6b3SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 315b81b6b3SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 325b81b6b3SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 335b81b6b3SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 345b81b6b3SRodney W. Grimes * SUCH DAMAGE. 355b81b6b3SRodney W. Grimes * 3609f07fb0SRodney W. Grimes * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91 37c3aac50fSPeter Wemm * $FreeBSD$ 385b81b6b3SRodney W. Grimes */ 395b81b6b3SRodney W. Grimes 406e393973SGarrett Wollman #ifndef _MACHINE_CPU_H_ 41e4b7e53dSBruce Evans #define _MACHINE_CPU_H_ 426e393973SGarrett Wollman 435b81b6b3SRodney W. Grimes /* 445b81b6b3SRodney W. Grimes * Definitions unique to i386 cpu support. 455b81b6b3SRodney W. Grimes */ 4648a09cf2SJohn Dyson #include <machine/psl.h> 47f540b106SGarrett Wollman #include <machine/frame.h> 48f540b106SGarrett Wollman #include <machine/segments.h> 495b81b6b3SRodney W. Grimes 505b81b6b3SRodney W. Grimes /* 515b81b6b3SRodney W. Grimes * definitions of cpu-dependent requirements 525b81b6b3SRodney W. Grimes * referenced in generic code 535b81b6b3SRodney W. Grimes */ 545b81b6b3SRodney W. Grimes #undef COPY_SIGCODE /* don't copy sigcode above user stack in exec */ 555b81b6b3SRodney W. Grimes 565b81b6b3SRodney W. Grimes #define cpu_exec(p) /* nothing */ 5726f9a767SRodney W. Grimes #define cpu_swapin(p) /* nothing */ 58b40ce416SJulian Elischer #define cpu_getstack(td) ((td)->td_frame->tf_esp) 59b40ce416SJulian Elischer #define cpu_setstack(td, ap) ((td)->td_frame->tf_esp = (ap)) 605b81b6b3SRodney W. Grimes 61142ba5f3SJohn Baldwin #define TRAPF_USERMODE(framep) \ 62142ba5f3SJohn Baldwin ((ISPL((framep)->tf_cs) == SEL_UPL) || ((framep)->tf_eflags & PSL_VM)) 63142ba5f3SJohn Baldwin #define TRAPF_PC(framep) ((framep)->tf_eip) 64142ba5f3SJohn Baldwin 6548a09cf2SJohn Dyson #define CLKF_USERMODE(framep) \ 66142ba5f3SJohn Baldwin ((ISPL((framep)->cf_cs) == SEL_UPL) || ((framep)->cf_eflags & PSL_VM)) 6726f9a767SRodney W. Grimes #define CLKF_PC(framep) ((framep)->cf_eip) 685b81b6b3SRodney W. Grimes 695b81b6b3SRodney W. Grimes /* 7026f9a767SRodney W. Grimes * CTL_MACHDEP definitions. 7126f9a767SRodney W. Grimes */ 7226f9a767SRodney W. Grimes #define CPU_CONSDEV 1 /* dev_t: console terminal device */ 73fe0d5f43SAndrey A. Chernov #define CPU_ADJKERNTZ 2 /* int: timezone offset (seconds) */ 74f80d8a2eSAndrey A. Chernov #define CPU_DISRTCSET 3 /* int: disable resettodr() call */ 757a2dada5SPoul-Henning Kamp #define CPU_BOOTINFO 4 /* struct: bootinfo */ 76fe0d5f43SAndrey A. Chernov #define CPU_WALLCLOCK 5 /* int: indicates wall CMOS clock */ 77fe0d5f43SAndrey A. Chernov #define CPU_MAXID 6 /* number of valid machdep ids */ 7826f9a767SRodney W. Grimes 7926f9a767SRodney W. Grimes #define CTL_MACHDEP_NAMES { \ 8026f9a767SRodney W. Grimes { 0, 0 }, \ 8126f9a767SRodney W. Grimes { "console_device", CTLTYPE_STRUCT }, \ 82dd067f08SAndrey A. Chernov { "adjkerntz", CTLTYPE_INT }, \ 83f80d8a2eSAndrey A. Chernov { "disable_rtc_set", CTLTYPE_INT }, \ 847a2dada5SPoul-Henning Kamp { "bootinfo", CTLTYPE_STRUCT }, \ 85fe0d5f43SAndrey A. Chernov { "wall_cmos_clock", CTLTYPE_INT }, \ 8626f9a767SRodney W. Grimes } 8726f9a767SRodney W. Grimes 88664a31e4SPeter Wemm #ifdef _KERNEL 894090154bSBruce Evans extern char btext[]; 904090154bSBruce Evans extern char etext[]; 9112a586bbSBruce Evans extern u_int tsc_present; 92a2a1c95cSPeter Wemm 93b63dc6adSAlfred Perlstein void fork_trampoline(void); 9458550067SMark Murray 9558550067SMark Murray /* 9658550067SMark Murray * Return contents of in-cpu fast counter as a sort of "bogo-time" 9758550067SMark Murray * for non-critical timing. 9858550067SMark Murray */ 9958550067SMark Murray static __inline u_int64_t 10058550067SMark Murray get_cyclecount(void) 10158550067SMark Murray { 10258550067SMark Murray #if defined(I386_CPU) || defined(I486_CPU) 10358550067SMark Murray struct timespec tv; 10458550067SMark Murray 1054a3a2f07SMark Murray if (!tsc_present) { 10658550067SMark Murray nanotime(&tv); 10758550067SMark Murray return (tv.tv_sec * (u_int64_t)1000000000 + tv.tv_nsec); 10858550067SMark Murray } 10958550067SMark Murray #endif 11058550067SMark Murray return (rdtsc()); 11158550067SMark Murray } 11258550067SMark Murray 11309f07fb0SRodney W. Grimes #endif 114e4b7e53dSBruce Evans 115e4b7e53dSBruce Evans #endif /* !_MACHINE_CPU_H_ */ 116