]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/linker_set.h
Add INTR_TYPE_AV so that we can get to the PI_AV priority in the ithread
[FreeBSD/FreeBSD.git] / sys / sys / linker_set.h
1 /*-
2  * Copyright (c) 1999 John D. Polstra
3  * Copyright (c) 1999,2001 Peter Wemm <peter@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29
30 #ifndef _SYS_LINKER_SET_H_
31 #define _SYS_LINKER_SET_H_
32
33 /*
34  * The following macros are used to declare global sets of objects, which
35  * are collected by the linker into a `linker_set' as defined below.
36  * For ELF, this is done by constructing a separate segment for each set.
37  * For a.out, it is done automatically by the linker.
38  */
39
40 #if defined(__ELF__)
41 /*
42  * Private macros, not to be used outside this header file.
43  */
44 /* this bit of h0h0magic brought to you by cpp */
45 #define __GLOBL(sym)    __GLOBL2(sym)
46 #define __GLOBL2(sym)   __asm(".globl " #sym)
47
48 #define __MAKE_SET(set, sym)                                            \
49         __GLOBL(__CONCAT(__start_set_,set));                            \
50         __GLOBL(__CONCAT(__stop_set_,set));                             \
51         static void const * const __set_##set##_sym_##sym               \
52         __attribute__((__section__("set_" #set),__unused__)) = &sym
53
54 /*
55  * Public macros.
56  */
57 #define TEXT_SET(set, sym)      __MAKE_SET(set, sym)
58 #define DATA_SET(set, sym)      __MAKE_SET(set, sym)
59 #define BSS_SET(set, sym)       __MAKE_SET(set, sym)
60 #define ABS_SET(set, sym)       __MAKE_SET(set, sym)
61 #define SET_ENTRY(set, sym)     __MAKE_SET(set, sym)
62
63 /*
64  * Initialize before referring to a give linker set
65  */
66 #define SET_DECLARE(set, ptype)                                         \
67         extern ptype *__CONCAT(__start_set_,set);                       \
68         extern ptype *__CONCAT(__stop_set_,set)
69
70 #define SET_BEGIN(set)                                                  \
71         (&__CONCAT(__start_set_,set))
72 #define SET_LIMIT(set)                                                  \
73         (&__CONCAT(__stop_set_,set))
74
75 #else   /* __ELF__ */
76
77 /*
78  * The old way.  This depends on GNU ld extensions that are not widely
79  * available outside of the a.out format.
80  *
81  * NB: the constants defined below must match those defined in
82  * ld/ld.h.  Since their calculation requires arithmetic, we
83  * can't name them symbolically (e.g., 23 is N_SETT | N_EXT).
84  *
85  * In the __MAKE_SET macro below, the line:
86  *   static void const * const __set_##set##_sym_##sym = &sym;
87  * is present only to prevent the compiler from producing bogus
88  * warnings about unused symbols.
89  */
90 /* Private macros */
91 #ifdef __UNDERSCORES__
92 #define __MAKE_SET(set, sym, type) \
93         static void const * const __set_##set##_sym_##sym = &sym;       \
94         __asm(".stabs \"_" #set "\", " #type ", 0, 0, _" #sym)
95 #else
96 #define __MAKE_SET(set, sym, type) \
97         static void const * const __set_##set##_sym_##sym = &sym;       \
98         __asm(".stabs \"" #set "\", " #type ", 0, 0, " #sym)
99 #endif
100
101 /* Public Macros */
102 #define TEXT_SET(set, sym)      __MAKE_SET(set, sym, 23)
103 #define DATA_SET(set, sym)      __MAKE_SET(set, sym, 25)
104 #define BSS_SET(set, sym)       __MAKE_SET(set, sym, 27)
105 #define ABS_SET(set, sym)       __MAKE_SET(set, sym, 21)
106 #define SET_ENTRY(set, sym)     error error must provide text/data type
107
108 #define SET_DECLARE(set, ptype)                                         \
109         extern struct  {                                                \
110                 int             ls_length;                              \
111                 ptype           *ls_items[1];                           \
112         } set
113
114 #define SET_BEGIN(set)                                                  \
115         (&((set).ls_items[0]))
116 #define SET_LIMIT(set)                                                  \
117         (&((set).ls_items[(set).ls_length]))
118
119 #endif  /* __ELF__ */
120
121 /*
122  * Iterate over all the elements of a set.
123  *
124  * Sets always contain addresses of things, and "pvar" points to words
125  * containing those addresses.  Thus is must be declared as "type **pvar",
126  * and the address of each set item is obtained inside the loop by "*pvar".
127  */
128 #define SET_FOREACH(pvar, set)                                          \
129         for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++)
130
131 #define SET_ITEM(set, i)                                                \
132         ((SET_BEGIN(set))[i])
133
134 /*
135  * Provide a count of the items in a set.
136  */
137 #define SET_COUNT(set)                                                  \
138         (SET_LIMIT(set) - SET_BEGIN(set))
139
140 #endif  /* _SYS_LINKER_SET_H_ */