2 * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
26 * $FreeBSD: src/sys/i386/include/globals.h,v 1.5.2.1 2000/05/16 06:58:10 dillon Exp $
27 * $DragonFly: src/sys/platform/pc32/include/Attic/globals.h,v 1.2 2003/06/17 04:28:35 dillon Exp $
30 #ifndef _MACHINE_GLOBALS_H_
31 #define _MACHINE_GLOBALS_H_
35 #define GLOBAL_LVALUE(name, type) \
36 (*(type *)_global_ptr_##name())
38 #define GLOBAL_RVALUE(name, type) \
39 ((type)_global_##name())
41 /* non-volatile version */
42 #define GLOBAL_LVALUE_NV(name, type) \
43 (*(type *)_global_ptr_##name##_nv())
45 #define GLOBAL_RVALUE_NV(name, type) \
46 ((type)_global_##name##_nv())
48 #define GLOBAL_FUNC(name) \
49 static __inline void *_global_ptr_##name(void) { \
51 __asm __volatile("movl $gd_" #name ",%0;" \
52 "addl %%fs:globaldata,%0" : "=r" (val)); \
55 static __inline void *_global_ptr_##name##_nv(void) { \
57 __asm("movl $gd_" #name ",%0;" \
58 "addl %%fs:globaldata,%0" : "=r" (val)); \
61 static __inline int _global_##name(void) { \
63 __asm __volatile("movl %%fs:gd_" #name ",%0" : "=r" (val)); \
66 static __inline int _global_##name##_nv(void) { \
68 __asm("movl %%fs:gd_" #name ",%0" : "=r" (val)); \
71 static __inline void _global_##name##_set(int val) { \
72 __asm __volatile("movl %0,%%fs:gd_" #name : : "r" (val)); \
74 static __inline void _global_##name##_set_nv(int val) { \
75 __asm("movl %0,%%fs:gd_" #name : : "r" (val)); \
78 #if defined(SMP) || defined(KLD_MODULE) || defined(ACTUALLY_LKM_NOT_KERNEL)
80 * The following set of macros works for UP kernel as well, but for maximum
81 * performance we allow the global variables to be accessed directly. On the
82 * other hand, kernel modules should always use these macros to maintain
83 * portability between UP and SMP kernels.
85 #define curproc GLOBAL_RVALUE_NV(curproc, struct proc *)
86 #define curpcb GLOBAL_RVALUE_NV(curpcb, struct pcb *)
87 #define npxproc GLOBAL_LVALUE(npxproc, struct proc *)
88 #define common_tss GLOBAL_LVALUE(common_tss, struct i386tss)
89 #define switchtime GLOBAL_LVALUE(switchtime, struct timeval)
90 #define switchticks GLOBAL_LVALUE(switchticks, int)
92 #define common_tssd GLOBAL_LVALUE(common_tssd, struct segment_descriptor)
93 #define tss_gdt GLOBAL_LVALUE(tss_gdt, struct segment_descriptor *)
94 #define astpending GLOBAL_LVALUE(astpending, u_int)
97 #define currentldt GLOBAL_LVALUE(currentldt, int)
101 #define cpuid GLOBAL_RVALUE(cpuid, u_int)
102 #define other_cpus GLOBAL_LVALUE(other_cpus, u_int)
103 #define inside_intr GLOBAL_LVALUE(inside_intr, int)
104 #define prv_CMAP1 GLOBAL_LVALUE(prv_CMAP1, pt_entry_t *)
105 #define prv_CMAP2 GLOBAL_LVALUE(prv_CMAP2, pt_entry_t *)
106 #define prv_CMAP3 GLOBAL_LVALUE(prv_CMAP3, pt_entry_t *)
107 #define prv_PMAP1 GLOBAL_LVALUE(prv_PMAP1, pt_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, unsigned *)
116 GLOBAL_FUNC(astpending)
119 GLOBAL_FUNC(common_tss)
120 GLOBAL_FUNC(switchtime)
121 GLOBAL_FUNC(switchticks)
123 GLOBAL_FUNC(common_tssd)
127 GLOBAL_FUNC(currentldt)
132 GLOBAL_FUNC(other_cpus)
133 GLOBAL_FUNC(inside_intr)
134 GLOBAL_FUNC(prv_CMAP1)
135 GLOBAL_FUNC(prv_CMAP2)
136 GLOBAL_FUNC(prv_CMAP3)
137 GLOBAL_FUNC(prv_PMAP1)
138 GLOBAL_FUNC(prv_CADDR1)
139 GLOBAL_FUNC(prv_CADDR2)
140 GLOBAL_FUNC(prv_CADDR3)
141 GLOBAL_FUNC(prv_PADDR1)
144 #define SET_CURPROC(x) (_global_curproc_set_nv((int)x))
148 #endif /* !_MACHINE_GLOBALS_H_ */