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 $
29 #ifndef _MACHINE_GLOBALS_H_
30 #define _MACHINE_GLOBALS_H_
34 #define GLOBAL_LVALUE(name, type) \
35 (*(type *)_global_ptr_##name())
37 #define GLOBAL_RVALUE(name, type) \
38 ((type)_global_##name())
40 /* non-volatile version */
41 #define GLOBAL_LVALUE_NV(name, type) \
42 (*(type *)_global_ptr_##name##_nv())
44 #define GLOBAL_RVALUE_NV(name, type) \
45 ((type)_global_##name##_nv())
47 #define GLOBAL_FUNC(name) \
48 static __inline void *_global_ptr_##name(void) { \
50 __asm __volatile("movl $gd_" #name ",%0;" \
51 "addl %%fs:globaldata,%0" : "=r" (val)); \
54 static __inline void *_global_ptr_##name##_nv(void) { \
56 __asm("movl $gd_" #name ",%0;" \
57 "addl %%fs:globaldata,%0" : "=r" (val)); \
60 static __inline int _global_##name(void) { \
62 __asm __volatile("movl %%fs:gd_" #name ",%0" : "=r" (val)); \
65 static __inline int _global_##name##_nv(void) { \
67 __asm("movl %%fs:gd_" #name ",%0" : "=r" (val)); \
70 static __inline void _global_##name##_set(int val) { \
71 __asm __volatile("movl %0,%%fs:gd_" #name : : "r" (val)); \
73 static __inline void _global_##name##_set_nv(int val) { \
74 __asm("movl %0,%%fs:gd_" #name : : "r" (val)); \
77 #if defined(SMP) || defined(KLD_MODULE) || defined(ACTUALLY_LKM_NOT_KERNEL)
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.
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)
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)
96 #define currentldt GLOBAL_LVALUE(currentldt, int)
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, pt_entry_t *)
107 #define prv_CADDR1 GLOBAL_RVALUE(prv_CADDR1, caddr_t)
108 #define prv_CADDR2 GLOBAL_RVALUE(prv_CADDR2, caddr_t)
109 #define prv_CADDR3 GLOBAL_RVALUE(prv_CADDR3, caddr_t)
110 #define prv_PADDR1 GLOBAL_RVALUE(prv_PADDR1, unsigned *)
115 GLOBAL_FUNC(astpending)
118 GLOBAL_FUNC(common_tss)
119 GLOBAL_FUNC(switchtime)
120 GLOBAL_FUNC(switchticks)
122 GLOBAL_FUNC(common_tssd)
126 GLOBAL_FUNC(currentldt)
131 GLOBAL_FUNC(other_cpus)
132 GLOBAL_FUNC(inside_intr)
133 GLOBAL_FUNC(prv_CMAP1)
134 GLOBAL_FUNC(prv_CMAP2)
135 GLOBAL_FUNC(prv_CMAP3)
136 GLOBAL_FUNC(prv_PMAP1)
137 GLOBAL_FUNC(prv_CADDR1)
138 GLOBAL_FUNC(prv_CADDR2)
139 GLOBAL_FUNC(prv_CADDR3)
140 GLOBAL_FUNC(prv_PADDR1)
143 #define SET_CURPROC(x) (_global_curproc_set_nv((int)x))
147 #endif /* !_MACHINE_GLOBALS_H_ */