1*95613c87Smrg /* $NetBSD: cpu.h,v 1.72 2023/09/04 20:58:52 mrg Exp $ */
281918bf8Sfvdl
381918bf8Sfvdl /*-
481918bf8Sfvdl * Copyright (c) 1990 The Regents of the University of California.
581918bf8Sfvdl * All rights reserved.
681918bf8Sfvdl *
781918bf8Sfvdl * This code is derived from software contributed to Berkeley by
881918bf8Sfvdl * William Jolitz.
981918bf8Sfvdl *
1081918bf8Sfvdl * Redistribution and use in source and binary forms, with or without
1181918bf8Sfvdl * modification, are permitted provided that the following conditions
1281918bf8Sfvdl * are met:
1381918bf8Sfvdl * 1. Redistributions of source code must retain the above copyright
1481918bf8Sfvdl * notice, this list of conditions and the following disclaimer.
1581918bf8Sfvdl * 2. Redistributions in binary form must reproduce the above copyright
1681918bf8Sfvdl * notice, this list of conditions and the following disclaimer in the
1781918bf8Sfvdl * documentation and/or other materials provided with the distribution.
18aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
1981918bf8Sfvdl * may be used to endorse or promote products derived from this software
2081918bf8Sfvdl * without specific prior written permission.
2181918bf8Sfvdl *
2281918bf8Sfvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2381918bf8Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2481918bf8Sfvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2581918bf8Sfvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2681918bf8Sfvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2781918bf8Sfvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2881918bf8Sfvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2981918bf8Sfvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3081918bf8Sfvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3181918bf8Sfvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3281918bf8Sfvdl * SUCH DAMAGE.
3381918bf8Sfvdl *
3481918bf8Sfvdl * @(#)cpu.h 5.4 (Berkeley) 5/9/91
3581918bf8Sfvdl */
3681918bf8Sfvdl
3781918bf8Sfvdl #ifndef _AMD64_CPU_H_
3881918bf8Sfvdl #define _AMD64_CPU_H_
3981918bf8Sfvdl
40433b5ddeSmrg #ifdef __x86_64__
41433b5ddeSmrg
42f674d967Sad #include <x86/cpu.h>
4381918bf8Sfvdl
449188c073Sad #ifdef _KERNEL
459188c073Sad
46d218bdeeSpooka #if defined(__GNUC__) && !defined(_MODULE)
4710c5b023Smaxv
489c412e0cSad static struct cpu_info *x86_curcpu(void);
499c412e0cSad static lwp_t *x86_curlwp(void);
509c412e0cSad
51*95613c87Smrg /*
52*95613c87Smrg * XXXGCC12 has:
53*95613c87Smrg * ./machine/cpu.h:57:9: error: array subscript 0 is outside array bounds of 'struct cpu_info * const[0]' [-Werror=array-bounds]
54*95613c87Smrg * 56 | __asm("movq %%gs:%1, %0" :
55*95613c87Smrg */
56*95613c87Smrg #pragma GCC push_options
57*95613c87Smrg #pragma GCC diagnostic ignored "-Warray-bounds"
58*95613c87Smrg
5933a78575Sryo __inline __always_inline static struct cpu_info * __unused __nomsan
x86_curcpu(void)609c412e0cSad x86_curcpu(void)
619c412e0cSad {
629c412e0cSad struct cpu_info *ci;
639c412e0cSad
64e0aed504Sriastradh __asm("movq %%gs:%1, %0" :
659c412e0cSad "=r" (ci) :
669c412e0cSad "m"
679c412e0cSad (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_self)));
689c412e0cSad return ci;
699c412e0cSad }
709c412e0cSad
71cbaecaa9Smaxv __inline static lwp_t * __unused __nomsan __attribute__ ((const))
x86_curlwp(void)729c412e0cSad x86_curlwp(void)
739c412e0cSad {
749c412e0cSad lwp_t *l;
759c412e0cSad
76e0aed504Sriastradh __asm("movq %%gs:%1, %0" :
779c412e0cSad "=r" (l) :
789c412e0cSad "m"
799c412e0cSad (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp)));
809c412e0cSad return l;
819c412e0cSad }
8210c5b023Smaxv
83*95613c87Smrg #pragma GCC pop_options
84*95613c87Smrg
85d218bdeeSpooka #endif /* __GNUC__ && !_MODULE */
869c412e0cSad
87427af037Scherry #ifdef XENPV
88cb2a219eScherry #define CLKF_USERMODE(frame) (curcpu()->ci_xen_clockf_usermode)
89cb2a219eScherry #define CLKF_PC(frame) (curcpu()->ci_xen_clockf_pc)
90427af037Scherry #else /* XENPV */
917ad103f4Smaxv #define CLKF_USERMODE(frame) USERMODE((frame)->cf_if.if_tf.tf_cs)
92a1e817b5Sdsl #define CLKF_PC(frame) ((frame)->cf_if.if_tf.tf_rip)
93427af037Scherry #endif /* XENPV */
94fbb58adaSad #define CLKF_INTR(frame) (curcpu()->ci_idepth > 0)
9581918bf8Sfvdl #define LWP_PC(l) ((l)->l_md.md_regs->tf_rip)
9681918bf8Sfvdl
975d43782cSmaxv void *cpu_uarea_alloc(bool);
985d43782cSmaxv bool cpu_uarea_free(void *);
995d43782cSmaxv
1009188c073Sad #endif /* _KERNEL */
1019188c073Sad
102433b5ddeSmrg #else /* __x86_64__ */
103433b5ddeSmrg
104433b5ddeSmrg #include <i386/cpu.h>
105433b5ddeSmrg
106433b5ddeSmrg #endif /* __x86_64__ */
107433b5ddeSmrg
10881918bf8Sfvdl #endif /* !_AMD64_CPU_H_ */
109