11.72Smrg/*	$NetBSD: cpu.h,v 1.72 2023/09/04 20:58:52 mrg 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.72Smrg/*
521.72Smrg * XXXGCC12 has:
531.72Smrg * ./machine/cpu.h:57:9: error: array subscript 0 is outside array bounds of 'struct cpu_info * const[0]' [-Werror=array-bounds]
541.72Smrg *    56 |         __asm("movq %%gs:%1, %0" :
551.72Smrg */
561.72Smrg#pragma GCC push_options
571.72Smrg#pragma GCC diagnostic ignored "-Warray-bounds"
581.72Smrg
591.70Sryo__inline __always_inline static struct cpu_info * __unused __nomsan
601.27Sadx86_curcpu(void)
611.27Sad{
621.27Sad	struct cpu_info *ci;
631.27Sad
641.71Sriastrad	__asm("movq %%gs:%1, %0" :
651.27Sad	    "=r" (ci) :
661.27Sad	    "m"
671.27Sad	    (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_self)));
681.27Sad	return ci;
691.27Sad}
701.27Sad
711.67Smaxv__inline static lwp_t * __unused __nomsan __attribute__ ((const))
721.27Sadx86_curlwp(void)
731.27Sad{
741.27Sad	lwp_t *l;
751.27Sad
761.71Sriastrad	__asm("movq %%gs:%1, %0" :
771.27Sad	    "=r" (l) :
781.27Sad	    "m"
791.27Sad	    (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp)));
801.27Sad	return l;
811.27Sad}
821.65Smaxv
831.72Smrg#pragma GCC pop_options
841.72Smrg
851.59Spooka#endif	/* __GNUC__ && !_MODULE */
861.27Sad
871.64Scherry#ifdef XENPV
881.63Scherry#define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)
891.63Scherry#define CLKF_PC(frame)		(curcpu()->ci_xen_clockf_pc)
901.64Scherry#else /* XENPV */
911.61Smaxv#define	CLKF_USERMODE(frame)	USERMODE((frame)->cf_if.if_tf.tf_cs)
921.37Sdsl#define CLKF_PC(frame)		((frame)->cf_if.if_tf.tf_rip)
931.64Scherry#endif /* XENPV */
941.25Sad#define CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
951.1Sfvdl#define LWP_PC(l)		((l)->l_md.md_regs->tf_rip)
961.1Sfvdl
971.69Srilligvoid *cpu_uarea_alloc(bool);
981.68Smaxvbool cpu_uarea_free(void *);
991.68Smaxv
1001.56Sad#endif	/* _KERNEL */
1011.56Sad
1021.58Smrg#else	/*	__x86_64__	*/
1031.58Smrg
1041.58Smrg#include <i386/cpu.h>
1051.58Smrg
1061.58Smrg#endif	/*	__x86_64__	*/
1071.58Smrg
1081.1Sfvdl#endif /* !_AMD64_CPU_H_ */
109