Home | History | Annotate | Line # | Download | only in include
      1  1.185       mrg /*	$NetBSD: cpu.h,v 1.185 2023/09/04 20:58:52 mrg Exp $	*/
      2   1.24       cgd 
      3    1.1       cgd /*-
      4    1.1       cgd  * Copyright (c) 1990 The Regents of the University of California.
      5    1.1       cgd  * All rights reserved.
      6    1.1       cgd  *
      7    1.1       cgd  * This code is derived from software contributed to Berkeley by
      8    1.1       cgd  * William Jolitz.
      9    1.1       cgd  *
     10    1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11    1.1       cgd  * modification, are permitted provided that the following conditions
     12    1.1       cgd  * are met:
     13    1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14    1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15    1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16    1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17    1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18  1.103       agc  * 3. Neither the name of the University nor the names of its contributors
     19    1.1       cgd  *    may be used to endorse or promote products derived from this software
     20    1.1       cgd  *    without specific prior written permission.
     21    1.1       cgd  *
     22    1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23    1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24    1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25    1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26    1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27    1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28    1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29    1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30    1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31    1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32    1.1       cgd  * SUCH DAMAGE.
     33    1.1       cgd  *
     34   1.24       cgd  *	@(#)cpu.h	5.4 (Berkeley) 5/9/91
     35    1.1       cgd  */
     36    1.1       cgd 
     37   1.14   mycroft #ifndef _I386_CPU_H_
     38   1.14   mycroft #define _I386_CPU_H_
     39   1.14   mycroft 
     40  1.173        ad #include <x86/cpu.h>
     41   1.82      fvdl 
     42  1.174        ad #ifdef _KERNEL
     43  1.174        ad 
     44  1.176     pooka #if defined(__GNUC__) && !defined(_MODULE)
     45  1.146        ad static struct cpu_info *x86_curcpu(void);
     46  1.146        ad static lwp_t *x86_curlwp(void);
     47  1.105      yamt 
     48  1.185       mrg /*
     49  1.185       mrg  * XXXGCC12 has:
     50  1.185       mrg  * ./machine/cpu.h:57:9: error: array subscript 0 is outside array bounds of 'struct cpu_info * const[0]' [-Werror=array-bounds]
     51  1.185       mrg  *    56 |         __asm("movq %%gs:%1, %0" :
     52  1.185       mrg  */
     53  1.185       mrg #pragma GCC push_options
     54  1.185       mrg #pragma GCC diagnostic ignored "-Warray-bounds"
     55  1.185       mrg 
     56  1.183       ryo __inline __always_inline static struct cpu_info * __unused
     57  1.146        ad x86_curcpu(void)
     58  1.105      yamt {
     59  1.105      yamt 	struct cpu_info *ci;
     60  1.105      yamt 
     61  1.184  riastrad 	__asm("movl %%fs:%1, %0" :
     62  1.105      yamt 	    "=r" (ci) :
     63  1.105      yamt 	    "m"
     64  1.115      yamt 	    (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_self)));
     65  1.105      yamt 	return ci;
     66  1.105      yamt }
     67  1.105      yamt 
     68  1.175        ad __inline static lwp_t * __attribute__ ((const))
     69  1.146        ad x86_curlwp(void)
     70  1.146        ad {
     71  1.146        ad 	lwp_t *l;
     72  1.146        ad 
     73  1.184  riastrad 	__asm("movl %%fs:%1, %0" :
     74  1.146        ad 	    "=r" (l) :
     75  1.146        ad 	    "m"
     76  1.146        ad 	    (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp)));
     77  1.146        ad 	return l;
     78  1.146        ad }
     79  1.185       mrg 
     80  1.185       mrg #pragma GCC pop_options
     81  1.185       mrg 
     82  1.185       mrg #endif	/* __GNUC__ && !_MODULE */
     83    1.1       cgd 
     84  1.181    cherry #ifdef XENPV
     85  1.180    cherry #define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)
     86  1.180    cherry #define CLKF_PC(frame)		(curcpu()->ci_xen_clockf_pc)
     87  1.181    cherry #else /* XENPV */
     88  1.179      maxv #define	CLKF_USERMODE(frame)	USERMODE((frame)->cf_if.if_cs)
     89  1.118      cube #define	CLKF_PC(frame)		((frame)->cf_if.if_eip)
     90  1.181    cherry #endif /* XENPV */
     91  1.130      yamt #define	CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
     92   1.95   thorpej #define	LWP_PC(l)		((l)->l_md.md_regs->tf_eip)
     93   1.12   mycroft 
     94  1.178    cherry #ifdef PAE
     95  1.178    cherry void cpu_alloc_l3_page(struct cpu_info *);
     96  1.178    cherry #endif /* PAE */
     97  1.178    cherry 
     98  1.174        ad #endif	/* _KERNEL */
     99  1.174        ad 
    100   1.14   mycroft #endif /* !_I386_CPU_H_ */
    101