cpu.h revision 1.60
11.60Schs/* $NetBSD: cpu.h,v 1.60 2012/01/21 16:48:56 chs Exp $ */ 21.1Sfvdl 31.1Sfvdl/*- 41.1Sfvdl * Copyright (c) 1990 The Regents of the University of California. 51.1Sfvdl * All rights reserved. 61.1Sfvdl * 71.1Sfvdl * This code is derived from software contributed to Berkeley by 81.1Sfvdl * William Jolitz. 91.1Sfvdl * 101.1Sfvdl * Redistribution and use in source and binary forms, with or without 111.1Sfvdl * modification, are permitted provided that the following conditions 121.1Sfvdl * are met: 131.1Sfvdl * 1. Redistributions of source code must retain the above copyright 141.1Sfvdl * notice, this list of conditions and the following disclaimer. 151.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 161.1Sfvdl * notice, this list of conditions and the following disclaimer in the 171.1Sfvdl * documentation and/or other materials provided with the distribution. 181.2Sagc * 3. Neither the name of the University nor the names of its contributors 191.1Sfvdl * may be used to endorse or promote products derived from this software 201.1Sfvdl * without specific prior written permission. 211.1Sfvdl * 221.1Sfvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231.1Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Sfvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Sfvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.1Sfvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Sfvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Sfvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Sfvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Sfvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Sfvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Sfvdl * SUCH DAMAGE. 331.1Sfvdl * 341.1Sfvdl * @(#)cpu.h 5.4 (Berkeley) 5/9/91 351.1Sfvdl */ 361.1Sfvdl 371.1Sfvdl#ifndef _AMD64_CPU_H_ 381.1Sfvdl#define _AMD64_CPU_H_ 391.1Sfvdl 401.58Smrg#ifdef __x86_64__ 411.58Smrg 421.55Sad#include <x86/cpu.h> 431.1Sfvdl 441.56Sad#ifdef _KERNEL 451.56Sad 461.59Spooka#if defined(__GNUC__) && !defined(_MODULE) 471.27Sadstatic struct cpu_info *x86_curcpu(void); 481.27Sadstatic lwp_t *x86_curlwp(void); 491.27Sad 501.38Sperry__inline static struct cpu_info * __unused 511.27Sadx86_curcpu(void) 521.27Sad{ 531.27Sad struct cpu_info *ci; 541.27Sad 551.27Sad __asm volatile("movq %%gs:%1, %0" : 561.27Sad "=r" (ci) : 571.27Sad "m" 581.27Sad (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_self))); 591.27Sad return ci; 601.27Sad} 611.27Sad 621.57Sad__inline static lwp_t * __unused __attribute__ ((const)) 631.27Sadx86_curlwp(void) 641.27Sad{ 651.27Sad lwp_t *l; 661.27Sad 671.27Sad __asm volatile("movq %%gs:%1, %0" : 681.27Sad "=r" (l) : 691.27Sad "m" 701.27Sad (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp))); 711.27Sad return l; 721.27Sad} 731.50Sad 741.50Sad__inline static void __unused 751.50Sadcpu_set_curpri(int pri) 761.50Sad{ 771.50Sad 781.50Sad __asm volatile( 791.50Sad "movl %1, %%gs:%0" : 801.50Sad "=m" (*(struct cpu_info *)offsetof(struct cpu_info, ci_schedstate.spc_curpriority)) : 811.50Sad "r" (pri) 821.50Sad ); 831.50Sad} 841.59Spooka#endif /* __GNUC__ && !_MODULE */ 851.27Sad 861.37Sdsl#define CLKF_USERMODE(frame) USERMODE((frame)->cf_if.if_tf.tf_cs, \ 871.37Sdsl (frame)->cf_if.if_tf.tf_rflags) 881.37Sdsl#define CLKF_PC(frame) ((frame)->cf_if.if_tf.tf_rip) 891.25Sad#define CLKF_INTR(frame) (curcpu()->ci_idepth > 0) 901.1Sfvdl#define LWP_PC(l) ((l)->l_md.md_regs->tf_rip) 911.1Sfvdl 921.60Schsvoid *cpu_uarea_alloc(bool); 931.60Schsbool cpu_uarea_free(void *); 941.60Schs 951.56Sad#endif /* _KERNEL */ 961.56Sad 971.58Smrg#else /* __x86_64__ */ 981.58Smrg 991.58Smrg#include <i386/cpu.h> 1001.58Smrg 1011.58Smrg#endif /* __x86_64__ */ 1021.58Smrg 1031.1Sfvdl#endif /* !_AMD64_CPU_H_ */ 104