Browse Source

[tables] Incorporate table data type information into table definition

Eliminate the potential for mismatches between table names and the
table entry data type by incorporating the data type into the
definition of the table, rather than specifying it explicitly in each
table accessor method.
tags/v0.9.8
Michael Brown 16 years ago
parent
commit
3c68ff99ea

+ 2
- 2
src/core/resolv.c View File

@@ -217,7 +217,7 @@ static void resolv_mux_done ( struct resolv_interface *resolv,
217 217
 
218 218
 	/* Attempt next child resolver, if possible */
219 219
 	mux->resolver++;
220
-	if ( mux->resolver >= table_end ( struct resolver, RESOLVERS ) ) {
220
+	if ( mux->resolver >= table_end ( RESOLVERS ) ) {
221 221
 		DBGC ( mux, "RESOLV %p failed to resolve name\n", mux );
222 222
 		goto finished;
223 223
 	}
@@ -256,7 +256,7 @@ int resolv ( struct resolv_interface *resolv, const char *name,
256 256
 		return -ENOMEM;
257 257
 	resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
258 258
 	resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
259
-	mux->resolver = table_start ( struct resolver, RESOLVERS );
259
+	mux->resolver = table_start ( RESOLVERS );
260 260
 	memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
261 261
 	memcpy ( mux->name, name, name_len );
262 262
 

+ 2
- 3
src/hci/tui/settings_ui.c View File

@@ -78,7 +78,7 @@ struct setting_widget {
78 78
 };
79 79
 
80 80
 /** Number of registered configuration settings */
81
-#define NUM_SETTINGS table_num_entries ( struct setting, SETTINGS )
81
+#define NUM_SETTINGS table_num_entries ( SETTINGS )
82 82
 
83 83
 static void load_setting ( struct setting_widget *widget ) __nonnull;
84 84
 static int save_setting ( struct setting_widget *widget ) __nonnull;
@@ -219,8 +219,7 @@ static int edit_setting ( struct setting_widget *widget, int key ) {
219 219
 static void init_setting_index ( struct setting_widget *widget,
220 220
 				 struct settings *settings,
221 221
 				 unsigned int index ) {
222
-	struct setting *all_settings =
223
-		table_start ( struct setting, SETTINGS );
222
+	struct setting *all_settings = table_start ( SETTINGS );
224 223
 
225 224
 	init_setting ( widget, settings, &all_settings[index],
226 225
 		       ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );

+ 2
- 2
src/include/console.h View File

@@ -86,7 +86,7 @@ struct console_driver {
86 86
 };
87 87
 
88 88
 /** Console driver table */
89
-#define CONSOLES "consoles"
89
+#define CONSOLES __table ( struct console_driver, "consoles" )
90 90
 
91 91
 /**
92 92
  * Mark a <tt> struct console_driver </tt> as being part of the
@@ -105,7 +105,7 @@ struct console_driver {
105 105
  * @endcode
106 106
  *
107 107
  */
108
-#define __console_driver __table ( struct console_driver, CONSOLES, 01 )
108
+#define __console_driver __table_entry ( CONSOLES, 01 )
109 109
 
110 110
 /* Function prototypes */
111 111
 

+ 3
- 3
src/include/gpxe/arp.h View File

@@ -27,11 +27,11 @@ struct arp_net_protocol {
27 27
 };
28 28
 
29 29
 /** ARP protocol table */
30
-#define ARP_NET_PROTOCOLS "arp_net_protocols"
30
+#define ARP_NET_PROTOCOLS \
31
+	__table ( struct arp_net_protocol, "arp_net_protocols" )
31 32
 
32 33
 /** Declare an ARP protocol */
33
-#define __arp_net_protocol \
34
-	__table ( struct arp_net_protocol, ARP_NET_PROTOCOLS, 01 )
34
+#define __arp_net_protocol __table_entry ( ARP_NET_PROTOCOLS, 01 )
35 35
 
36 36
 extern struct net_protocol arp_protocol;
37 37
 

+ 2
- 2
src/include/gpxe/command.h View File

@@ -17,8 +17,8 @@ struct command {
17 17
 	int ( * exec ) ( int argc, char **argv );
18 18
 };
19 19
 
20
-#define COMMANDS "commands"
20
+#define COMMANDS __table ( struct command, "commands" )
21 21
 
22
-#define __command __table ( struct command, COMMANDS, 01 )
22
+#define __command __table_entry ( COMMANDS, 01 )
23 23
 
24 24
 #endif /* _GPXE_COMMAND_H */

+ 2
- 2
src/include/gpxe/device.h View File

@@ -103,9 +103,9 @@ struct root_driver {
103 103
 };
104 104
 
105 105
 /** Root device table */
106
-#define ROOT_DEVICES "root_devices"
106
+#define ROOT_DEVICES __table ( struct root_device, "root_devices" )
107 107
 
108 108
 /** Declare a root device */
109
-#define __root_device __table ( struct root_device, ROOT_DEVICES, 01 )
109
+#define __root_device __table_entry ( ROOT_DEVICES, 01 )
110 110
 
111 111
 #endif /* _GPXE_DEVICE_H */

+ 5
- 6
src/include/gpxe/efi/efi.h View File

@@ -55,11 +55,10 @@ struct efi_protocol {
55 55
 };
56 56
 
57 57
 /** EFI protocol table */
58
-#define EFI_PROTOCOLS "efi_protocols"
58
+#define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
59 59
 
60 60
 /** Declare an EFI protocol used by gPXE */
61
-#define __efi_protocol \
62
-	__table ( struct efi_protocol, EFI_PROTOCOLS, 01 )
61
+#define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
63 62
 
64 63
 /** Declare an EFI protocol to be required by gPXE
65 64
  *
@@ -90,11 +89,11 @@ struct efi_config_table {
90 89
 };
91 90
 
92 91
 /** EFI configuration table table */
93
-#define EFI_CONFIG_TABLES "efi_config_tables"
92
+#define EFI_CONFIG_TABLES \
93
+	__table ( struct efi_config_table, "efi_config_tables" )
94 94
 
95 95
 /** Declare an EFI configuration table used by gPXE */
96
-#define __efi_config_table \
97
-	__table ( struct efi_config_table, EFI_CONFIG_TABLES, 01 )
96
+#define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
98 97
 
99 98
 /** Declare an EFI configuration table to be used by gPXE
100 99
  *

+ 2
- 2
src/include/gpxe/eisa.h View File

@@ -80,10 +80,10 @@ struct eisa_driver {
80 80
 };
81 81
 
82 82
 /** EISA driver table */
83
-#define EISA_DRIVERS "eisa_drivers"
83
+#define EISA_DRIVERS __table ( struct eisa_driver, "eisa_drivers" )
84 84
 
85 85
 /** Declare an EISA driver */
86
-#define __eisa_driver __table ( struct eisa_driver, EISA_DRIVERS, 01 )
86
+#define __eisa_driver __table_entry ( EISA_DRIVERS, 01 )
87 87
 
88 88
 extern void eisa_device_enabled ( struct eisa_device *eisa, int enabled );
89 89
 

+ 2
- 2
src/include/gpxe/errortab.h View File

@@ -14,8 +14,8 @@ struct errortab {
14 14
 	const char *text;
15 15
 };
16 16
 
17
-#define ERRORTAB "errortab"
17
+#define ERRORTAB __table ( struct errortab, "errortab" )
18 18
 
19
-#define __errortab __table ( struct errortab, ERRORTAB, 01 )
19
+#define __errortab __table_entry ( ERRORTAB, 01 )
20 20
 
21 21
 #endif /* _GPXE_ERRORTAB_H */

+ 4
- 5
src/include/gpxe/features.h View File

@@ -51,10 +51,10 @@
51 51
 /** @} */
52 52
 
53 53
 /** DHCP feature table */
54
-#define DHCP_FEATURES "dhcp_features"
54
+#define DHCP_FEATURES __table ( uint8_t, "dhcp_features" )
55 55
 
56 56
 /** Declare a feature code for DHCP */
57
-#define __dhcp_feature __table ( uint8_t, DHCP_FEATURES, 01 )
57
+#define __dhcp_feature __table_entry ( DHCP_FEATURES, 01 )
58 58
 
59 59
 /** Construct a DHCP feature table entry */
60 60
 #define DHCP_FEATURE( feature_opt, ... )				    \
@@ -73,11 +73,10 @@ struct feature {
73 73
 };
74 74
 
75 75
 /** Named feature table */
76
-#define FEATURES "features"
76
+#define FEATURES __table ( struct feature, "features" )
77 77
 
78 78
 /** Declare a named feature */
79
-#define __feature_name( category )					    \
80
-	__table ( struct feature, FEATURES, category )
79
+#define __feature_name( category ) __table_entry ( FEATURES, category )
81 80
 
82 81
 /** Construct a named feature */
83 82
 #define FEATURE_NAME( category, text )					    \

+ 2
- 2
src/include/gpxe/gdbstub.h View File

@@ -45,9 +45,9 @@ struct gdb_transport {
45 45
 	void ( * send ) ( const char *buf, size_t len );
46 46
 };
47 47
 
48
-#define GDB_TRANSPORTS "gdb_transports"
48
+#define GDB_TRANSPORTS __table ( struct gdb_transport, "gdb_transports" )
49 49
 
50
-#define __gdb_transport __table ( struct gdb_transport, GDB_TRANSPORTS, 01 )
50
+#define __gdb_transport __table_entry ( GDB_TRANSPORTS, 01 )
51 51
 
52 52
 /**
53 53
  * Look up GDB transport by name

+ 2
- 3
src/include/gpxe/image.h View File

@@ -124,11 +124,10 @@ struct image_type {
124 124
 #define PROBE_PXE 03
125 125
 
126 126
 /** Executable or loadable image type table */
127
-#define IMAGE_TYPES "image_types"
127
+#define IMAGE_TYPES __table ( struct image_type, "image_types" )
128 128
 
129 129
 /** An executable or loadable image type */
130
-#define __image_type( probe_order ) \
131
-	__table ( struct image_type, IMAGE_TYPES, probe_order )
130
+#define __image_type( probe_order ) __table_entry ( IMAGE_TYPES, probe_order )
132 131
 
133 132
 extern struct list_head images;
134 133
 

+ 4
- 5
src/include/gpxe/init.h View File

@@ -14,11 +14,10 @@ struct init_fn {
14 14
 };
15 15
 
16 16
 /** Initialisation function table */
17
-#define INIT_FNS "init_fns"
17
+#define INIT_FNS __table ( struct init_fn, "init_fns" )
18 18
 
19 19
 /** Declare an initialisation functon */
20
-#define __init_fn( init_order ) \
21
-	__table ( struct init_fn, INIT_FNS, init_order )
20
+#define __init_fn( init_order ) __table_entry ( INIT_FNS, init_order )
22 21
 
23 22
 /** @defgroup initfn_order Initialisation function ordering
24 23
  * @{
@@ -53,11 +52,11 @@ struct startup_fn {
53 52
 };
54 53
 
55 54
 /** Startup/shutdown function table */
56
-#define STARTUP_FNS "startup_fns"
55
+#define STARTUP_FNS __table ( struct startup_fn, "startup_fns" )
57 56
 
58 57
 /** Declare a startup/shutdown function */
59 58
 #define __startup_fn( startup_order ) \
60
-	__table ( struct startup_fn, STARTUP_FNS, startup_order )
59
+	__table_entry ( STARTUP_FNS, startup_order )
61 60
 
62 61
 /** @defgroup startfn_order Startup/shutdown function ordering
63 62
  *

+ 2
- 2
src/include/gpxe/isa.h View File

@@ -59,10 +59,10 @@ struct isa_driver {
59 59
 };
60 60
 
61 61
 /** ISA driver table */
62
-#define ISA_DRIVERS "isa_drivers"
62
+#define ISA_DRIVERS __table ( struct isa_driver, "isa_drivers" )
63 63
 
64 64
 /** Declare an ISA driver */
65
-#define __isa_driver __table ( struct isa_driver, ISA_DRIVERS, 01 )
65
+#define __isa_driver __table_entry ( ISA_DRIVERS, 01 )
66 66
 
67 67
 /**
68 68
  * Set ISA driver-private data

+ 2
- 2
src/include/gpxe/isapnp.h View File

@@ -224,10 +224,10 @@ struct isapnp_driver {
224 224
 };
225 225
 
226 226
 /** ISAPnP driver table */
227
-#define ISAPNP_DRIVERS "isapnp_drivers"
227
+#define ISAPNP_DRIVERS __table ( struct isapnp_driver, "isapnp_drivers" )
228 228
 
229 229
 /** Declare an ISAPnP driver */
230
-#define __isapnp_driver __table ( struct isapnp_driver, ISAPNP_DRIVERS, 01 )
230
+#define __isapnp_driver __table_entry ( ISAPNP_DRIVERS, 01 )
231 231
 
232 232
 extern uint16_t isapnp_read_port;
233 233
 

+ 2
- 2
src/include/gpxe/mca.h View File

@@ -78,10 +78,10 @@ struct mca_driver {
78 78
 };
79 79
 
80 80
 /** MCA driver table */
81
-#define MCA_DRIVERS "mca_drivers"
81
+#define MCA_DRIVERS __table ( struct mca_driver, "mca_drivers" )
82 82
 
83 83
 /** Declare an MCA driver */
84
-#define __mca_driver __table ( struct mca_driver, MCA_DRIVERS, 01 )
84
+#define __mca_driver __table_entry ( MCA_DRIVERS, 01 )
85 85
 
86 86
 /**
87 87
  * Set MCA driver-private data

+ 4
- 4
src/include/gpxe/netdevice.h View File

@@ -280,16 +280,16 @@ struct net_device {
280 280
 #define NETDEV_LINK_UP 0x0002
281 281
 
282 282
 /** Link-layer protocol table */
283
-#define LL_PROTOCOLS "ll_protocols"
283
+#define LL_PROTOCOLS __table ( struct ll_protocol, "ll_protocols" )
284 284
 
285 285
 /** Declare a link-layer protocol */
286
-#define __ll_protocol  __table ( struct ll_protocol, LL_PROTOCOLS, 01 )
286
+#define __ll_protocol  __table_entry ( LL_PROTOCOLS, 01 )
287 287
 
288 288
 /** Network-layer protocol table */
289
-#define NET_PROTOCOLS "net_protocols"
289
+#define NET_PROTOCOLS __table ( struct net_protocol, "net_protocols" )
290 290
 
291 291
 /** Declare a network-layer protocol */
292
-#define __net_protocol __table ( struct net_protocol, NET_PROTOCOLS, 01 )
292
+#define __net_protocol __table_entry ( NET_PROTOCOLS, 01 )
293 293
 
294 294
 extern struct list_head net_devices;
295 295
 extern struct net_device_operations null_netdev_operations;

+ 4
- 4
src/include/gpxe/open.h View File

@@ -59,10 +59,10 @@ struct uri_opener {
59 59
 };
60 60
 
61 61
 /** URI opener table */
62
-#define URI_OPENERS "uri_openers"
62
+#define URI_OPENERS __table ( struct uri_opener, "uri_openers" )
63 63
 
64 64
 /** Register a URI opener */
65
-#define __uri_opener __table ( struct uri_opener, URI_OPENERS, 01 )
65
+#define __uri_opener __table_entry ( URI_OPENERS, 01 )
66 66
 
67 67
 /** A socket opener */
68 68
 struct socket_opener {
@@ -82,10 +82,10 @@ struct socket_opener {
82 82
 };
83 83
 
84 84
 /** Socket opener table */
85
-#define SOCKET_OPENERS "socket_openers"
85
+#define SOCKET_OPENERS __table ( struct socket_opener, "socket_openers" )
86 86
 
87 87
 /** Register a socket opener */
88
-#define __socket_opener __table ( struct socket_opener, SOCKET_OPENERS, 01 )
88
+#define __socket_opener __table_entry ( SOCKET_OPENERS, 01 )
89 89
 
90 90
 extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri );
91 91
 extern int xfer_open_uri_string ( struct xfer_interface *xfer,

+ 2
- 2
src/include/gpxe/pci.h View File

@@ -309,10 +309,10 @@ struct pci_driver {
309 309
 };
310 310
 
311 311
 /** PCI driver table */
312
-#define PCI_DRIVERS "pci_drivers"
312
+#define PCI_DRIVERS __table ( struct pci_driver, "pci_drivers" )
313 313
 
314 314
 /** Declare a PCI driver */
315
-#define __pci_driver __table ( struct pci_driver, PCI_DRIVERS, 01 )
315
+#define __pci_driver __table_entry ( PCI_DRIVERS, 01 )
316 316
 
317 317
 #define PCI_DEVFN( slot, func )		( ( (slot) << 3 ) | (func) )
318 318
 #define PCI_SLOT( devfn )		( ( (devfn) >> 3 ) & 0x1f )

+ 2
- 3
src/include/gpxe/process.h View File

@@ -64,7 +64,7 @@ process_init ( struct process *process,
64 64
 }
65 65
 
66 66
 /** Permanent process table */
67
-#define PERMANENT_PROCESSES "processes"
67
+#define PERMANENT_PROCESSES __table ( struct process, "processes" )
68 68
 
69 69
 /**
70 70
  * Declare a permanent process
@@ -72,7 +72,6 @@ process_init ( struct process *process,
72 72
  * Permanent processes will be automatically added to the process list
73 73
  * at initialisation time.
74 74
  */
75
-#define __permanent_process \
76
-	__table ( struct process, PERMANENT_PROCESSES, 01 )
75
+#define __permanent_process __table_entry ( PERMANENT_PROCESSES, 01 )
77 76
 
78 77
 #endif /* _GPXE_PROCESS_H */

+ 2
- 3
src/include/gpxe/resolv.h View File

@@ -150,11 +150,10 @@ struct resolver {
150 150
 #define RESOLV_NORMAL 02
151 151
 
152 152
 /** Resolvers table */
153
-#define RESOLVERS "resolvers"
153
+#define RESOLVERS __table ( struct resolver, "resolvers" )
154 154
 
155 155
 /** Register as a name resolver */
156
-#define __resolver( resolv_order ) \
157
-	__table ( struct resolver, RESOLVERS, resolv_order )
156
+#define __resolver( resolv_order ) __table_entry ( RESOLVERS, resolv_order )
158 157
 
159 158
 extern void resolv_done ( struct resolv_interface *resolv,
160 159
 			  struct sockaddr *sa, int rc );

+ 3
- 3
src/include/gpxe/sanboot.h View File

@@ -8,9 +8,9 @@ struct sanboot_protocol {
8 8
 	int ( * boot ) ( const char *root_path );
9 9
 };
10 10
 
11
-#define SANBOOT_PROTOCOLS "sanboot_protocols"
11
+#define SANBOOT_PROTOCOLS \
12
+	__table ( struct sanboot_protocol, "sanboot_protocols" )
12 13
 
13
-#define __sanboot_protocol \
14
-	__table ( struct sanboot_protocol, SANBOOT_PROTOCOLS, 01 )
14
+#define __sanboot_protocol __table_entry ( SANBOOT_PROTOCOLS, 01 )
15 15
 
16 16
 #endif /* _GPXE_SANBOOT_H */

+ 7
- 8
src/include/gpxe/settings.h View File

@@ -37,10 +37,10 @@ struct setting {
37 37
 };
38 38
 
39 39
 /** Configuration setting table */
40
-#define SETTINGS "settings"
40
+#define SETTINGS __table ( struct setting, "settings" )
41 41
 
42 42
 /** Declare a configuration setting */
43
-#define	__setting __table ( struct setting, SETTINGS, 01 )
43
+#define __setting __table_entry ( SETTINGS, 01 )
44 44
 
45 45
 /** Settings block operations */
46 46
 struct settings_operations {
@@ -127,11 +127,10 @@ struct setting_type {
127 127
 };
128 128
 
129 129
 /** Configuration setting type table */
130
-#define SETTING_TYPES "setting_types"
130
+#define SETTING_TYPES __table ( struct setting_type, "setting_types" )
131 131
 
132 132
 /** Declare a configuration setting type */
133
-#define	__setting_type \
134
-	__table ( struct setting_type, SETTING_TYPES, 01 )
133
+#define __setting_type __table_entry ( SETTING_TYPES, 01 )
135 134
 
136 135
 /**
137 136
  * A settings applicator
@@ -146,11 +145,11 @@ struct settings_applicator {
146 145
 };
147 146
 
148 147
 /** Settings applicator table */
149
-#define SETTINGS_APPLICATORS "settings_applicators"
148
+#define SETTINGS_APPLICATORS \
149
+	__table ( struct settings_applicator, "settings_applicators" )
150 150
 
151 151
 /** Declare a settings applicator */
152
-#define __settings_applicator \
153
-	__table ( struct settings_applicator, SETTINGS_APPLICATORS, 01 )
152
+#define __settings_applicator __table_entry ( SETTINGS_APPLICATORS, 01 )
154 153
 
155 154
 /**
156 155
  * A simple settings block

+ 112
- 48
src/include/gpxe/tables.h View File

@@ -98,7 +98,7 @@
98 98
  * The linker script takes care of assembling the tables for us.  All
99 99
  * our table sections have names of the format @c .tbl.NAME.NN where
100 100
  * @c NAME designates the data structure stored in the table (e.g. @c
101
- * init_fn) and @c NN is a two-digit decimal number used to impose an
101
+ * init_fns) and @c NN is a two-digit decimal number used to impose an
102 102
  * ordering upon the tables if required.  @c NN=00 is reserved for the
103 103
  * symbol indicating "table start", and @c NN=99 is reserved for the
104 104
  * symbol indicating "table end".
@@ -115,7 +115,9 @@
115 115
  *	void ( *frob ) ( void ); 	// The frobnicating function itself
116 116
  *   };
117 117
  *
118
- *   #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 )
118
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
119
+ *
120
+ *   #define __frobnicator __table_entry ( FROBNICATORS, 01 )
119 121
  *
120 122
  * @endcode
121 123
  *
@@ -149,7 +151,7 @@
149 151
  *   void frob_all ( void ) {
150 152
  *	struct frob *frob;
151 153
  *
152
- *	for_each_table ( frob, "frobnicators" ) {
154
+ *	for_each_table ( frob, FROBNICATORS ) {
153 155
  *         printf ( "Calling frobnicator \"%s\"\n", frob->name );
154 156
  *	   frob->frob ();
155 157
  *	}
@@ -165,97 +167,154 @@
165 167
 #define __attribute__( x )
166 168
 #endif
167 169
 
168
-#define __table_str( x ) #x
169
-#define __table_section( table, idx ) \
170
-	__section__ ( ".tbl." table "." __table_str ( idx ) )
170
+/**
171
+ * Declare a linker table
172
+ *
173
+ * @v type		Data type
174
+ * @v name		Table name
175
+ * @ret table		Linker table
176
+ */
177
+#define __table( type, name ) ( type, name )
171 178
 
172
-#define __table_section_start( table ) __table_section ( table, 00 )
173
-#define __table_section_end( table ) __table_section ( table, 99 )
179
+/**
180
+ * Get linker table data type
181
+ *
182
+ * @v table		Linker table
183
+ * @ret type		Data type
184
+ */
185
+#define __table_type( table ) __table_extract_type table
186
+#define __table_extract_type( type, name ) type
174 187
 
175
-#define __natural_alignment( type ) __aligned__ ( __alignof__ ( type ) )
188
+/**
189
+ * Get linker table name
190
+ *
191
+ * @v table		Linker table
192
+ * @ret name		Table name
193
+ */
194
+#define __table_name( table ) __table_extract_name table
195
+#define __table_extract_name( type, name ) name
176 196
 
177 197
 /**
178
- * Linker table entry.
198
+ * Get linker table section name
179 199
  *
180
- * Declares a data structure to be part of a linker table.  Use as
181
- * e.g.
200
+ * @v table		Linker table
201
+ * @v idx		Sub-table index
202
+ * @ret section		Section name
203
+ */
204
+#define __table_section( table, idx ) \
205
+	".tbl." __table_name ( table ) "." __table_str ( idx )
206
+#define __table_str( x ) #x
207
+
208
+/**
209
+ * Get linker table alignment
210
+ *
211
+ * @v table		Linker table
212
+ * @ret align		Alignment
213
+ */
214
+#define __table_alignment( table ) __alignof__ ( __table_type ( table ) )
215
+
216
+/**
217
+ * Declare a linker table entry
218
+ *
219
+ * @v table		Linker table
220
+ * @v idx		Sub-table index
221
+ *
222
+ * Example usage:
182 223
  *
183 224
  * @code
184 225
  *
185
- *   #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 )
226
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
227
+ *
228
+ *   #define __frobnicator __table_entry ( FROBNICATORS, 01 )
186 229
  *
187 230
  *   struct frobnicator my_frob __frobnicator = {
188 231
  *      ...
189 232
  *   };
190 233
  *
191 234
  * @endcode
192
- *
193 235
  */
194
-#define __table( type, table, idx )					\
195
-	__attribute__ (( __table_section ( table, idx ),		\
196
-			 __natural_alignment ( type ) ))
236
+#define __table_entry( table, idx )					\
237
+	__attribute__ (( __section__ ( __table_section ( table, idx ) )	\
238
+			 __aligned__ ( __table_alignment ( table ) ) ))
197 239
 
198 240
 /**
199
- * Start of linker table.
241
+ * Get start of linker table
242
+ *
243
+ * @v table		Linker table
244
+ * @ret start		Start of linker table
200 245
  *
201
- * Return the start of a linker table.  Use as e.g.
246
+ * Example usage:
202 247
  *
203 248
  * @code
204 249
  *
205
- *   struct frobnicator *frobs =
206
- *	table_start ( struct frobnicator, "frobnicators" );
250
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
207 251
  *
208
- * @endcode
252
+ *   struct frobnicator *frobs = table_start ( FROBNICATORS );
209 253
  *
254
+ * @endcode
210 255
  */
211
-#define table_start( type, table ) ( {					\
212
-	static type __table_start[0] __table ( type, table, 00 );	\
256
+#define table_start( table ) ( {					\
257
+	static __table_type ( table ) __table_start[0]			\
258
+		__table_entry ( table, 00 ); 				\
213 259
 	__table_start; } )
214 260
 
215 261
 /**
216
- * End of linker table.
262
+ * Get end of linker table
217 263
  *
218
- * Return the end of a linker table.  Use as e.g.
264
+ * @v table		Linker table
265
+ * @ret end		End of linker table
266
+ *
267
+ * Example usage:
219 268
  *
220 269
  * @code
221 270
  *
222
- *   struct frobnicator *frobs_end =
223
- *	table_end ( struct frobnicator, "frobnicators" );
271
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
224 272
  *
225
- * @endcode
273
+ *   struct frobnicator *frobs_end = table_end ( FROBNICATORS );
226 274
  *
275
+ * @endcode
227 276
  */
228
-#define table_end( type, table ) ( {					\
229
-	static type __table_end[0] __table ( type, table, 99 );		\
277
+#define table_end( table ) ( {						\
278
+	static __table_type ( table ) __table_end[0]			\
279
+		__table_entry ( table, 99 ); 				\
230 280
 	__table_end; } )
231 281
 
232 282
 /**
233
- * Calculate number of entries in linker table.
283
+ * Get number of entries in linker table
234 284
  *
235
- * Return the number of entries within a linker table.  Use as e.g.
285
+ * @v table		Linker table
286
+ * @ret num_entries	Number of entries in linker table
287
+ *
288
+ * Example usage:
236 289
  *
237 290
  * @code
238 291
  *
239
- *   unsigned int num_frobs =
240
- *	table_num_entries ( struct frobnicator, "frobnicators" );
292
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
293
+ *
294
+ *   unsigned int num_frobs = table_num_entries ( FROBNICATORS );
241 295
  *
242 296
  * @endcode
243 297
  *
244 298
  */
245
-#define table_num_entries( type, table )				\
246
-	( ( unsigned int ) ( table_end ( type, table ) -		\
247
-			     table_start ( type, table ) ) )
299
+#define table_num_entries( table )					\
300
+	( ( unsigned int ) ( table_end ( table ) -			\
301
+			     table_start ( table ) ) )
248 302
 
249 303
 /**
250
- * Iterate through all entries within a linker table.
304
+ * Iterate through all entries within a linker table
251 305
  *
252
- * Use as e.g.
306
+ * @v pointer		Entry pointer
307
+ * @v table		Linker table
308
+ *
309
+ * Example usage:
253 310
  *
254 311
  * @code
255 312
  *
313
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
314
+ *
256 315
  *   struct frobnicator *frob;
257 316
  *
258
- *   for_each_table_entry ( frob, "frobnicators" ) {
317
+ *   for_each_table_entry ( frob, FROBNICATORS ) {
259 318
  *     ...
260 319
  *   }
261 320
  *
@@ -263,20 +322,25 @@
263 322
  *
264 323
  */
265 324
 #define for_each_table_entry( pointer, table )				\
266
-	for ( pointer = table_start ( typeof ( * pointer ), table ) ;	\
267
-	      pointer < table_end ( typeof ( * pointer ), table ) ;	\
325
+	for ( pointer = table_start ( table ) ;				\
326
+	      pointer < table_end ( table ) ;				\
268 327
 	      pointer++ )
269 328
 
270 329
 /**
271
- * Iterate through all entries within a linker table in reverse order.
330
+ * Iterate through all entries within a linker table in reverse order
272 331
  *
273
- * Use as e.g.
332
+ * @v pointer		Entry pointer
333
+ * @v table		Linker table
334
+ *
335
+ * Example usage:
274 336
  *
275 337
  * @code
276 338
  *
339
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
340
+ *
277 341
  *   struct frobnicator *frob;
278 342
  *
279
- *   for_each_table_entry_reverse ( frob, "frobnicators" ) {
343
+ *   for_each_table_entry_reverse ( frob, FROBNICATORS ) {
280 344
  *     ...
281 345
  *   }
282 346
  *
@@ -284,8 +348,8 @@
284 348
  *
285 349
  */
286 350
 #define for_each_table_entry_reverse( pointer, table )			\
287
-	for ( pointer = table_end ( typeof ( * pointer ), table ) - 1 ;	\
288
-	      pointer >= table_start ( typeof ( * pointer ), table ) ;	\
351
+	for ( pointer = ( table_end ( table ) - 1 ) ;			\
352
+	      pointer >= table_start ( table ) ;			\
289 353
 	      pointer-- )
290 354
 
291 355
 #endif /* _GPXE_TABLES_H */

+ 5
- 6
src/include/gpxe/tcpip.h View File

@@ -99,18 +99,17 @@ struct tcpip_net_protocol {
99 99
 };
100 100
 
101 101
 /** TCP/IP transport-layer protocol table */
102
-#define TCPIP_PROTOCOLS "tcpip_protocols"
102
+#define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
103 103
 
104 104
 /** Declare a TCP/IP transport-layer protocol */
105
-#define	__tcpip_protocol \
106
-	__table ( struct tcpip_protocol, TCPIP_PROTOCOLS, 01 )
105
+#define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
107 106
 
108 107
 /** TCP/IP network-layer protocol table */
109
-#define TCPIP_NET_PROTOCOLS "tcpip_net_protocols"
108
+#define TCPIP_NET_PROTOCOLS \
109
+	__table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
110 110
 
111 111
 /** Declare a TCP/IP network-layer protocol */
112
-#define	__tcpip_net_protocol \
113
-	__table ( struct tcpip_net_protocol, TCPIP_NET_PROTOCOLS, 01 )
112
+#define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
114 113
 
115 114
 extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
116 115
 		      struct sockaddr_tcpip *st_src,

+ 2
- 2
src/net/udp/dhcp.c View File

@@ -900,8 +900,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
900 900
 	dhcppkt->dhcphdr->ciaddr = ciaddr;
901 901
 
902 902
 	/* Add options to identify the feature list */
903
-	dhcp_features = table_start ( uint8_t, DHCP_FEATURES );
904
-	dhcp_features_len = table_num_entries ( uint8_t, DHCP_FEATURES );
903
+	dhcp_features = table_start ( DHCP_FEATURES );
904
+	dhcp_features_len = table_num_entries ( DHCP_FEATURES );
905 905
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
906 906
 				    dhcp_features_len ) ) != 0 ) {
907 907
 		DBG ( "DHCP could not set features list option: %s\n",

Loading…
Cancel
Save