cpu.h revision 1.67
11.67Smaxv/*	$NetBSD: cpu.h,v 1.67 2019/12/08 11:53:54 maxv 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.65Smaxv
481.27Sadstatic struct cpu_info *x86_curcpu(void);
491.27Sadstatic lwp_t *x86_curlwp(void);
501.27Sad
511.67Smaxv__inline static struct cpu_info * __unused __nomsan
521.27Sadx86_curcpu(void)
531.27Sad{
541.27Sad	struct cpu_info *ci;
551.27Sad
561.27Sad	__asm volatile("movq %%gs:%1, %0" :
571.27Sad	    "=r" (ci) :
581.27Sad	    "m"
591.27Sad	    (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_self)));
601.27Sad	return ci;
611.27Sad}
621.27Sad
631.67Smaxv__inline static lwp_t * __unused __nomsan __attribute__ ((const))
641.27Sadx86_curlwp(void)
651.27Sad{
661.27Sad	lwp_t *l;
671.27Sad
681.27Sad	__asm volatile("movq %%gs:%1, %0" :
691.27Sad	    "=r" (l) :
701.27Sad	    "m"
711.27Sad	    (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp)));
721.27Sad	return l;
731.27Sad}
741.65Smaxv
751.59Spooka#endif	/* __GNUC__ && !_MODULE */
761.27Sad
771.64Scherry#ifdef XENPV
781.63Scherry#define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)
791.63Scherry#define CLKF_PC(frame)		(curcpu()->ci_xen_clockf_pc)
801.64Scherry#else /* XENPV */
811.61Smaxv#define	CLKF_USERMODE(frame)	USERMODE((frame)->cf_if.if_tf.tf_cs)
821.37Sdsl#define CLKF_PC(frame)		((frame)->cf_if.if_tf.tf_rip)
831.64Scherry#endif /* XENPV */
841.25Sad#define CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
851.1Sfvdl#define LWP_PC(l)		((l)->l_md.md_regs->tf_rip)
861.1Sfvdl
871.56Sad#endif	/* _KERNEL */
881.56Sad
891.58Smrg#else	/*	__x86_64__	*/
901.58Smrg
911.58Smrg#include <i386/cpu.h>
921.58Smrg
931.58Smrg#endif	/*	__x86_64__	*/
941.58Smrg
951.1Sfvdl#endif /* !_AMD64_CPU_H_ */
96