Blame view
include/linker_lists.h
7.78 KB
83d290c56 SPDX: Convert all... |
1 |
/* SPDX-License-Identifier: GPL-2.0+ */ |
42ebaae3a common: Implement... |
2 3 4 5 6 7 |
/* * include/linker_lists.h * * Implementation of linker-generated arrays * * Copyright (C) 2012 Marek Vasut <marex@denx.de> |
42ebaae3a common: Implement... |
8 |
*/ |
ef123c525 Refactor linker-g... |
9 |
|
babb4440c kernel-doc: fix s... |
10 11 |
#ifndef __LINKER_LISTS_H__ #define __LINKER_LISTS_H__ |
dc7cb46f9 linker_lists: inc... |
12 |
#include <linux/compiler.h> |
ef123c525 Refactor linker-g... |
13 |
/* |
d72fd7b34 linker_lists: rem... |
14 |
* There is no use in including this from ASM files. |
ef123c525 Refactor linker-g... |
15 16 17 18 19 20 |
* So just don't define anything when included from ASM. */ #if !defined(__ASSEMBLY__) /** |
7e378b8bf Fix incorrect com... |
21 |
* llsym() - Access a linker-generated array entry |
72538f4c3 linker_lists: Add... |
22 23 24 25 26 27 28 29 30 |
* @_type: Data type of the entry * @_name: Name of the entry * @_list: name of the list. Should contain only characters allowed * in a C variable name! */ #define llsym(_type, _name, _list) \ ((_type *)&_u_boot_list_2_##_list##_2_##_name) /** |
42ebaae3a common: Implement... |
31 32 33 |
* ll_entry_declare() - Declare linker-generated array entry * @_type: Data type of the entry * @_name: Name of the entry |
ef123c525 Refactor linker-g... |
34 35 |
* @_list: name of the list. Should contain only characters allowed * in a C variable name! |
42ebaae3a common: Implement... |
36 37 38 39 40 41 |
* * This macro declares a variable that is placed into a linker-generated * array. This is a basic building block for more advanced use of linker- * generated arrays. The user is expected to build their own macro wrapper * around this one. * |
ef123c525 Refactor linker-g... |
42 |
* A variable declared using this macro must be compile-time initialized. |
42ebaae3a common: Implement... |
43 44 |
* * Special precaution must be made when using this macro: |
42ebaae3a common: Implement... |
45 |
* |
ef123c525 Refactor linker-g... |
46 47 48 |
* 1) The _type must not contain the "static" keyword, otherwise the * entry is generated and can be iterated but is listed in the map * file and cannot be retrieved by name. |
42ebaae3a common: Implement... |
49 |
* |
ef123c525 Refactor linker-g... |
50 51 52 |
* 2) In case a section is declared that contains some array elements AND * a subsection of this section is declared and contains some elements, * it is imperative that the elements are of the same type. |
42ebaae3a common: Implement... |
53 |
* |
78a88f793 doc: Replace DocB... |
54 |
* 3) In case an outer section is declared that contains some array elements |
ef123c525 Refactor linker-g... |
55 |
* AND an inner subsection of this section is declared and contains some |
42ebaae3a common: Implement... |
56 57 58 59 |
* elements, then when traversing the outer section, even the elements of * the inner sections are present in the array. * * Example: |
78a88f793 doc: Replace DocB... |
60 61 62 63 64 65 66 |
* * :: * * ll_entry_declare(struct my_sub_cmd, my_sub_cmd, cmd_sub) = { * .x = 3, * .y = 4, * }; |
42ebaae3a common: Implement... |
67 |
*/ |
ef123c525 Refactor linker-g... |
68 69 70 71 72 73 |
#define ll_entry_declare(_type, _name, _list) \ _type _u_boot_list_2_##_list##_2_##_name __aligned(4) \ __attribute__((unused, \ section(".u_boot_list_2_"#_list"_2_"#_name))) /** |
3fcc3af4d dm: linker_lists:... |
74 75 76 77 78 79 80 81 82 |
* ll_entry_declare_list() - Declare a list of link-generated array entries * @_type: Data type of each entry * @_name: Name of the entry * @_list: name of the list. Should contain only characters allowed * in a C variable name! * * This is like ll_entry_declare() but creates multiple entries. It should * be assigned to an array. * |
78a88f793 doc: Replace DocB... |
83 84 85 86 87 88 89 |
* :: * * ll_entry_declare_list(struct my_sub_cmd, my_sub_cmd, cmd_sub) = { * { .x = 3, .y = 4 }, * { .x = 8, .y = 2 }, * { .x = 1, .y = 7 } * }; |
3fcc3af4d dm: linker_lists:... |
90 91 92 93 94 |
*/ #define ll_entry_declare_list(_type, _name, _list) \ _type _u_boot_list_2_##_list##_2_##_name[] __aligned(4) \ __attribute__((unused, \ section(".u_boot_list_2_"#_list"_2_"#_name))) |
78a88f793 doc: Replace DocB... |
95 |
/* |
ef123c525 Refactor linker-g... |
96 97 98 99 100 101 102 |
* We need a 0-byte-size type for iterator symbols, and the compiler * does not allow defining objects of C type 'void'. Using an empty * struct is allowed by the compiler, but causes gcc versions 4.4 and * below to complain about aliasing. Therefore we use the next best * thing: zero-sized arrays, which are both 0-byte-size and exempt from * aliasing warnings. */ |
42ebaae3a common: Implement... |
103 104 105 106 |
/** * ll_entry_start() - Point to first entry of linker-generated array * @_type: Data type of the entry |
ef123c525 Refactor linker-g... |
107 |
* @_list: Name of the list in which this entry is placed |
42ebaae3a common: Implement... |
108 |
* |
78a88f793 doc: Replace DocB... |
109 |
* This function returns ``(_type *)`` pointer to the very first entry of a |
42ebaae3a common: Implement... |
110 |
* linker-generated array placed into subsection of .u_boot_list section |
ef123c525 Refactor linker-g... |
111 112 113 114 |
* specified by _list argument. * * Since this macro defines an array start symbol, its leftmost index * must be 2 and its rightmost index must be 1. |
42ebaae3a common: Implement... |
115 116 |
* * Example: |
78a88f793 doc: Replace DocB... |
117 118 119 120 |
* * :: * * struct my_sub_cmd *msc = ll_entry_start(struct my_sub_cmd, cmd_sub); |
42ebaae3a common: Implement... |
121 |
*/ |
ef123c525 Refactor linker-g... |
122 123 124 125 126 127 |
#define ll_entry_start(_type, _list) \ ({ \ static char start[0] __aligned(4) __attribute__((unused, \ section(".u_boot_list_2_"#_list"_1"))); \ (_type *)&start; \ }) |
42ebaae3a common: Implement... |
128 129 |
/** |
ef123c525 Refactor linker-g... |
130 |
* ll_entry_end() - Point after last entry of linker-generated array |
42ebaae3a common: Implement... |
131 |
* @_type: Data type of the entry |
ef123c525 Refactor linker-g... |
132 |
* @_list: Name of the list in which this entry is placed |
42ebaae3a common: Implement... |
133 134 |
* (with underscores instead of dots) * |
78a88f793 doc: Replace DocB... |
135 |
* This function returns ``(_type *)`` pointer after the very last entry of |
ef123c525 Refactor linker-g... |
136 137 138 139 140 141 142 |
* a linker-generated array placed into subsection of .u_boot_list * section specified by _list argument. * * Since this macro defines an array end symbol, its leftmost index * must be 2 and its rightmost index must be 3. * * Example: |
78a88f793 doc: Replace DocB... |
143 144 145 146 |
* * :: * * struct my_sub_cmd *msc = ll_entry_end(struct my_sub_cmd, cmd_sub); |
ef123c525 Refactor linker-g... |
147 148 149 |
*/ #define ll_entry_end(_type, _list) \ ({ \ |
7e378b8bf Fix incorrect com... |
150 |
static char end[0] __aligned(4) __attribute__((unused, \ |
ef123c525 Refactor linker-g... |
151 152 153 154 155 156 157 158 |
section(".u_boot_list_2_"#_list"_3"))); \ (_type *)&end; \ }) /** * ll_entry_count() - Return the number of elements in linker-generated array * @_type: Data type of the entry * @_list: Name of the list of which the number of elements is computed * |
42ebaae3a common: Implement... |
159 |
* This function returns the number of elements of a linker-generated array |
ef123c525 Refactor linker-g... |
160 |
* placed into subsection of .u_boot_list section specified by _list |
42ebaae3a common: Implement... |
161 162 163 |
* argument. The result is of an unsigned int type. * * Example: |
78a88f793 doc: Replace DocB... |
164 165 166 167 168 169 170 171 172 |
* * :: * * int i; * const unsigned int count = ll_entry_count(struct my_sub_cmd, cmd_sub); * struct my_sub_cmd *msc = ll_entry_start(struct my_sub_cmd, cmd_sub); * for (i = 0; i < count; i++, msc++) * printf("Entry %i, x=%i y=%i ", i, msc->x, msc->y); |
42ebaae3a common: Implement... |
173 |
*/ |
ef123c525 Refactor linker-g... |
174 |
#define ll_entry_count(_type, _list) \ |
42ebaae3a common: Implement... |
175 |
({ \ |
ef123c525 Refactor linker-g... |
176 177 178 |
_type *start = ll_entry_start(_type, _list); \ _type *end = ll_entry_end(_type, _list); \ unsigned int _ll_result = end - start; \ |
42ebaae3a common: Implement... |
179 180 |
_ll_result; \ }) |
42ebaae3a common: Implement... |
181 182 183 184 |
/** * ll_entry_get() - Retrieve entry from linker-generated array by name * @_type: Data type of the entry * @_name: Name of the entry |
ef123c525 Refactor linker-g... |
185 |
* @_list: Name of the list in which this entry is placed |
42ebaae3a common: Implement... |
186 |
* |
7e378b8bf Fix incorrect com... |
187 188 |
* This function returns a pointer to a particular entry in linker-generated * array identified by the subsection of u_boot_list where the entry resides |
42ebaae3a common: Implement... |
189 190 191 |
* and it's name. * * Example: |
78a88f793 doc: Replace DocB... |
192 193 194 195 196 197 198 199 200 |
* * :: * * ll_entry_declare(struct my_sub_cmd, my_sub_cmd, cmd_sub) = { * .x = 3, * .y = 4, * }; * ... * struct my_sub_cmd *c = ll_entry_get(struct my_sub_cmd, my_sub_cmd, cmd_sub); |
42ebaae3a common: Implement... |
201 |
*/ |
ef123c525 Refactor linker-g... |
202 |
#define ll_entry_get(_type, _name, _list) \ |
42ebaae3a common: Implement... |
203 |
({ \ |
ef123c525 Refactor linker-g... |
204 205 |
extern _type _u_boot_list_2_##_list##_2_##_name; \ _type *_ll_result = \ |
7e378b8bf Fix incorrect com... |
206 |
&_u_boot_list_2_##_list##_2_##_name; \ |
42ebaae3a common: Implement... |
207 208 |
_ll_result; \ }) |
ef123c525 Refactor linker-g... |
209 210 211 212 |
/** * ll_start() - Point to first entry of first linker-generated array * @_type: Data type of the entry * |
78a88f793 doc: Replace DocB... |
213 |
* This function returns ``(_type *)`` pointer to the very first entry of |
ef123c525 Refactor linker-g... |
214 215 216 217 218 219 |
* the very first linker-generated array. * * Since this macro defines the start of the linker-generated arrays, * its leftmost index must be 1. * * Example: |
78a88f793 doc: Replace DocB... |
220 221 222 223 |
* * :: * * struct my_sub_cmd *msc = ll_start(struct my_sub_cmd); |
ef123c525 Refactor linker-g... |
224 225 226 227 228 229 230 231 232 |
*/ #define ll_start(_type) \ ({ \ static char start[0] __aligned(4) __attribute__((unused, \ section(".u_boot_list_1"))); \ (_type *)&start; \ }) /** |
7e378b8bf Fix incorrect com... |
233 |
* ll_end() - Point after last entry of last linker-generated array |
ef123c525 Refactor linker-g... |
234 235 |
* @_type: Data type of the entry * |
78a88f793 doc: Replace DocB... |
236 |
* This function returns ``(_type *)`` pointer after the very last entry of |
ef123c525 Refactor linker-g... |
237 238 239 240 241 242 |
* the very last linker-generated array. * * Since this macro defines the end of the linker-generated arrays, * its leftmost index must be 3. * * Example: |
78a88f793 doc: Replace DocB... |
243 244 245 246 |
* * :: * * struct my_sub_cmd *msc = ll_end(struct my_sub_cmd); |
ef123c525 Refactor linker-g... |
247 248 249 |
*/ #define ll_end(_type) \ ({ \ |
7e378b8bf Fix incorrect com... |
250 |
static char end[0] __aligned(4) __attribute__((unused, \ |
ef123c525 Refactor linker-g... |
251 252 253 254 255 |
section(".u_boot_list_3"))); \ (_type *)&end; \ }) #endif /* __ASSEMBLY__ */ |
42ebaae3a common: Implement... |
256 |
#endif /* __LINKER_LISTS_H__ */ |