The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/include/globals.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org>
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  * $FreeBSD$
   27  */
   28 
   29 #ifndef _MACHINE_GLOBALS_H_
   30 #define _MACHINE_GLOBALS_H_
   31 
   32 #ifdef _KERNEL
   33 
   34 #define GLOBAL_LVALUE(name, type) \
   35         (*(type *)_global_ptr_##name())
   36         
   37 #define GLOBAL_RVALUE(name, type) \
   38         ((type)_global_##name())
   39 
   40 /* non-volatile version */
   41 #define GLOBAL_LVALUE_NV(name, type) \
   42         (*(type *)_global_ptr_##name##_nv())
   43         
   44 #define GLOBAL_RVALUE_NV(name, type) \
   45         ((type)_global_##name##_nv())
   46 
   47 #define GLOBAL_FUNC(name) \
   48         static __inline void *_global_ptr_##name(void) { \
   49                 void *val; \
   50                 __asm __volatile("movl $gd_" #name ",%0;" \
   51                         "addl %%fs:globaldata,%0" : "=r" (val)); \
   52                 return (val); \
   53         } \
   54         static __inline void *_global_ptr_##name##_nv(void) { \
   55                 void *val; \
   56                 __asm("movl $gd_" #name ",%0;" \
   57                         "addl %%fs:globaldata,%0" : "=r" (val)); \
   58                 return (val); \
   59         } \
   60         static __inline int _global_##name(void) { \
   61                 int val; \
   62                 __asm __volatile("movl %%fs:gd_" #name ",%0" : "=r" (val)); \
   63                 return (val); \
   64         } \
   65         static __inline int _global_##name##_nv(void) { \
   66                 int val; \
   67                 __asm("movl %%fs:gd_" #name ",%0" : "=r" (val)); \
   68                 return (val); \
   69         } \
   70         static __inline void _global_##name##_set(int val) { \
   71                 __asm __volatile("movl %0,%%fs:gd_" #name : : "r" (val)); \
   72         } \
   73         static __inline void _global_##name##_set_nv(int val) { \
   74                 __asm("movl %0,%%fs:gd_" #name : : "r" (val)); \
   75         }
   76 
   77 #if defined(SMP) || defined(KLD_MODULE) || defined(ACTUALLY_LKM_NOT_KERNEL)
   78 /*
   79  * The following set of macros works for UP kernel as well, but for maximum
   80  * performance we allow the global variables to be accessed directly. On the
   81  * other hand, kernel modules should always use these macros to maintain
   82  * portability between UP and SMP kernels.
   83  */
   84 #define curproc         GLOBAL_RVALUE_NV(curproc, struct proc *)
   85 #define curpcb          GLOBAL_RVALUE_NV(curpcb, struct pcb *)
   86 #define npxproc         GLOBAL_LVALUE(npxproc, struct proc *)
   87 #define common_tss      GLOBAL_LVALUE(common_tss, struct i386tss)
   88 #define switchtime      GLOBAL_LVALUE(switchtime, struct timeval)
   89 #define switchticks     GLOBAL_LVALUE(switchticks, int)
   90 
   91 #define common_tssd     GLOBAL_LVALUE(common_tssd, struct segment_descriptor)
   92 #define tss_gdt         GLOBAL_LVALUE(tss_gdt, struct segment_descriptor *)
   93 #define astpending      GLOBAL_LVALUE(astpending, u_int)
   94 
   95 #ifdef USER_LDT
   96 #define currentldt      GLOBAL_LVALUE(currentldt, int)
   97 #endif
   98 
   99 #ifdef SMP
  100 #define cpuid           GLOBAL_RVALUE(cpuid, u_int)
  101 #define other_cpus      GLOBAL_LVALUE(other_cpus, u_int)
  102 #define inside_intr     GLOBAL_LVALUE(inside_intr, int)
  103 #define prv_CMAP1       GLOBAL_LVALUE(prv_CMAP1, pt_entry_t *)
  104 #define prv_CMAP2       GLOBAL_LVALUE(prv_CMAP2, pt_entry_t *)
  105 #define prv_CMAP3       GLOBAL_LVALUE(prv_CMAP3, pt_entry_t *)
  106 #define prv_PMAP1       GLOBAL_LVALUE(prv_PMAP1, pd_entry_t *)
  107 #define prv_PMAP2       GLOBAL_LVALUE(prv_PMAP2, pd_entry_t *)
  108 #define prv_CADDR1      GLOBAL_RVALUE(prv_CADDR1, caddr_t)
  109 #define prv_CADDR2      GLOBAL_RVALUE(prv_CADDR2, caddr_t)
  110 #define prv_CADDR3      GLOBAL_RVALUE(prv_CADDR3, caddr_t)
  111 #define prv_PADDR1      GLOBAL_RVALUE(prv_PADDR1, pt_entry_t *)
  112 #define prv_PADDR2      GLOBAL_RVALUE(prv_PADDR2, pt_entry_t *)
  113 #endif
  114 #endif  /*UP kernel*/
  115 
  116 GLOBAL_FUNC(curproc)
  117 GLOBAL_FUNC(astpending)
  118 GLOBAL_FUNC(curpcb)
  119 GLOBAL_FUNC(npxproc)
  120 GLOBAL_FUNC(common_tss)
  121 GLOBAL_FUNC(switchtime)
  122 GLOBAL_FUNC(switchticks)
  123 
  124 GLOBAL_FUNC(common_tssd)
  125 GLOBAL_FUNC(tss_gdt)
  126 
  127 #ifdef USER_LDT
  128 GLOBAL_FUNC(currentldt)
  129 #endif
  130 
  131 #ifdef SMP
  132 GLOBAL_FUNC(cpuid)
  133 GLOBAL_FUNC(other_cpus)
  134 GLOBAL_FUNC(inside_intr)
  135 GLOBAL_FUNC(prv_CMAP1)
  136 GLOBAL_FUNC(prv_CMAP2)
  137 GLOBAL_FUNC(prv_CMAP3)
  138 GLOBAL_FUNC(prv_PMAP1)
  139 GLOBAL_FUNC(prv_PMAP2)
  140 GLOBAL_FUNC(prv_CADDR1)
  141 GLOBAL_FUNC(prv_CADDR2)
  142 GLOBAL_FUNC(prv_CADDR3)
  143 GLOBAL_FUNC(prv_PADDR1)
  144 GLOBAL_FUNC(prv_PADDR2)
  145 #endif
  146 
  147 #define SET_CURPROC(x)  (_global_curproc_set_nv((int)x))
  148 
  149 #endif  /* _KERNEL */
  150 
  151 #endif  /* !_MACHINE_GLOBALS_H_ */

Cache object: bd6fb2a4142f2c8b30e084cc9c0d3119


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.