Browse Source

[tables] Redefine methods for accessing linker tables

Intel's C compiler (icc) chokes on the zero-length arrays that we
currently use as part of the mechanism for accessing linker table
entries.  Abstract away the zero-length arrays, to make a port to icc
easier.

Introduce macros such as for_each_table_entry() to simplify the common
case of iterating over all entries in a linker table.

Represent table names as #defined string constants rather than
unquoted literals; this avoids visual confusion between table names
and C variable or type names, and also allows us to force a
compilation error in the event of incorrect table names.
tags/v0.9.8
Michael Brown 15 years ago
parent
commit
1266d7902b

+ 2
- 9
src/core/console.c View File

@@ -5,11 +5,6 @@
5 5
 
6 6
 /** @file */
7 7
 
8
-static struct console_driver console_drivers[0]
9
-	__table_start ( struct console_driver, console );
10
-static struct console_driver console_drivers_end[0]
11
-	__table_end ( struct console_driver, console );
12
-
13 8
 /**
14 9
  * Write a single character to each console device.
15 10
  *
@@ -28,8 +23,7 @@ void putchar ( int character ) {
28 23
 	if ( character == '\n' )
29 24
 		putchar ( '\r' );
30 25
 
31
-	for ( console = console_drivers; console < console_drivers_end ;
32
-	      console++ ) {
26
+	for_each_table_entry ( console, CONSOLES ) {
33 27
 		if ( ( ! console->disabled ) && console->putchar )
34 28
 			console->putchar ( character );
35 29
 	}
@@ -51,8 +45,7 @@ void putchar ( int character ) {
51 45
 static struct console_driver * has_input ( void ) {
52 46
 	struct console_driver *console;
53 47
 
54
-	for ( console = console_drivers; console < console_drivers_end ;
55
-	      console++ ) {
48
+	for_each_table_entry ( console, CONSOLES ) {
56 49
 		if ( ( ! console->disabled ) && console->iskey ) {
57 50
 			if ( console->iskey () )
58 51
 				return console;

+ 1
- 6
src/core/device.c View File

@@ -29,11 +29,6 @@
29 29
  *
30 30
  */
31 31
 
32
-static struct root_device root_devices[0]
33
-	__table_start ( struct root_device, root_devices );
34
-static struct root_device root_devices_end[0]
35
-	__table_end ( struct root_device, root_devices );
36
-
37 32
 /** Registered root devices */
38 33
 static LIST_HEAD ( devices );
39 34
 
@@ -77,7 +72,7 @@ static void probe_devices ( void ) {
77 72
 	struct root_device *rootdev;
78 73
 	int rc;
79 74
 
80
-	for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
75
+	for_each_table_entry ( rootdev, ROOT_DEVICES ) {
81 76
 		list_add ( &rootdev->dev.siblings, &devices );
82 77
 		INIT_LIST_HEAD ( &rootdev->dev.children );
83 78
 		if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )

+ 1
- 6
src/core/exec.c View File

@@ -34,11 +34,6 @@
34 34
  *
35 35
  */
36 36
 
37
-static struct command commands[0]
38
-	__table_start ( struct command, commands );
39
-static struct command commands_end[0]
40
-	__table_end ( struct command, commands );
41
-
42 37
 /* Avoid dragging in getopt.o unless a command really uses it */
43 38
 int optind;
44 39
 int nextchar;
@@ -78,7 +73,7 @@ int execv ( const char *command, char * const argv[] ) {
78 73
 	reset_getopt();
79 74
 
80 75
 	/* Hand off to command implementation */
81
-	for ( cmd = commands ; cmd < commands_end ; cmd++ ) {
76
+	for_each_table_entry ( cmd, COMMANDS ) {
82 77
 		if ( strcmp ( command, cmd->name ) == 0 )
83 78
 			return cmd->exec ( argc, ( char ** ) argv );
84 79
 	}

+ 2
- 5
src/core/gdbstub.c View File

@@ -54,10 +54,6 @@ struct gdbstub {
54 54
 	int len;                         /* length of payload */
55 55
 };
56 56
 
57
-/* Transports */
58
-static struct gdb_transport gdb_transport_start[0] __table_start ( struct gdb_transport, gdb_transports );
59
-static struct gdb_transport gdb_transport_end[0] __table_end ( struct gdb_transport, gdb_transports );
60
-
61 57
 /* Packet parser states */
62 58
 static void gdbstub_state_new ( struct gdbstub *stub, char ch );
63 59
 static void gdbstub_state_data ( struct gdbstub *stub, char ch );
@@ -387,7 +383,8 @@ void gdbstub_handler ( int signo, gdbreg_t *regs ) {
387 383
 
388 384
 struct gdb_transport *find_gdb_transport ( const char *name ) {
389 385
 	struct gdb_transport *trans;
390
-	for ( trans = gdb_transport_start; trans < gdb_transport_end; trans++ ) {
386
+
387
+	for_each_table_entry ( trans, GDB_TRANSPORTS ) {
391 388
 		if ( strcmp ( trans->name, name ) == 0 ) {
392 389
 			return trans;
393 390
 		}

+ 1
- 7
src/core/image.c View File

@@ -37,12 +37,6 @@
37 37
 /** List of registered images */
38 38
 struct list_head images = LIST_HEAD_INIT ( images );
39 39
 
40
-/** List of image types */
41
-static struct image_type image_types[0]
42
-	__table_start ( struct image_type, image_types );
43
-static struct image_type image_types_end[0]
44
-	__table_end ( struct image_type, image_types );
45
-
46 40
 /**
47 41
  * Free executable/loadable image
48 42
  *
@@ -219,7 +213,7 @@ int image_autoload ( struct image *image ) {
219 213
 		return image_load ( image );
220 214
 
221 215
 	/* Otherwise probe for a suitable type */
222
-	for ( type = image_types ; type < image_types_end ; type++ ) {
216
+	for_each_table_entry ( type, IMAGE_TYPES ) {
223 217
 		DBGC ( image, "IMAGE %p trying type %s\n", image, type->name );
224 218
 		rc = image_load_type ( image, type );
225 219
 		if ( image->type == NULL )

+ 4
- 19
src/core/init.c View File

@@ -25,18 +25,6 @@
25 25
  *
26 26
  */
27 27
 
28
-/** Registered initialisation functions */
29
-static struct init_fn init_fns[0]
30
-	__table_start ( struct init_fn, init_fns );
31
-static struct init_fn init_fns_end[0]
32
-	__table_end ( struct init_fn, init_fns );
33
-
34
-/** Registered startup/shutdown functions */
35
-static struct startup_fn startup_fns[0]
36
-	__table_start ( struct startup_fn, startup_fns );
37
-static struct startup_fn startup_fns_end[0]
38
-	__table_end ( struct startup_fn, startup_fns );
39
-
40 28
 /** "startup() has been called" flag */
41 29
 static int started = 0;
42 30
 
@@ -54,9 +42,8 @@ void initialise ( void ) {
54 42
 	struct init_fn *init_fn;
55 43
 
56 44
 	/* Call registered initialisation functions */
57
-	for ( init_fn = init_fns ; init_fn < init_fns_end ; init_fn++ ) {
45
+	for_each_table_entry ( init_fn, INIT_FNS )
58 46
 		init_fn->initialise ();
59
-	}
60 47
 }
61 48
 
62 49
 /**
@@ -73,8 +60,7 @@ void startup ( void ) {
73 60
 		return;
74 61
 
75 62
 	/* Call registered startup functions */
76
-	for ( startup_fn = startup_fns ; startup_fn < startup_fns_end ;
77
-	      startup_fn++ ) {
63
+	for_each_table_entry ( startup_fn, STARTUP_FNS ) {
78 64
 		if ( startup_fn->startup )
79 65
 			startup_fn->startup();
80 66
 	}
@@ -90,7 +76,7 @@ void startup ( void ) {
90 76
  * This function reverses the actions of startup(), and leaves gPXE in
91 77
  * a state ready to be removed from memory.  You may call startup()
92 78
  * again after calling shutdown().
93
-
79
+ *
94 80
  * Call this function only once, before either exiting main() or
95 81
  * starting up a non-returnable image.
96 82
  */
@@ -101,8 +87,7 @@ void shutdown ( int flags ) {
101 87
 		return;
102 88
 
103 89
 	/* Call registered shutdown functions (in reverse order) */
104
-	for ( startup_fn = startup_fns_end - 1 ; startup_fn >= startup_fns ;
105
-	      startup_fn-- ) {
90
+	for_each_table_entry_reverse ( startup_fn, STARTUP_FNS ) {
106 91
 		if ( startup_fn->shutdown )
107 92
 			startup_fn->shutdown ( flags );
108 93
 	}

+ 1
- 4
src/core/main.c View File

@@ -27,9 +27,6 @@ Literature dealing with the network protocols:
27 27
 #define BOLD	"\033[1m"
28 28
 #define CYAN	"\033[36m"
29 29
 
30
-static struct feature features[0] __table_start ( struct feature, features );
31
-static struct feature features_end[0] __table_end ( struct feature, features );
32
-
33 30
 /**
34 31
  * Main entry point
35 32
  *
@@ -61,7 +58,7 @@ __asmcall int main ( void ) {
61 58
 		 NORMAL " -- Open Source Boot Firmware -- "
62 59
 		 CYAN "http://etherboot.org" NORMAL "\n"
63 60
 		 "Features:" );
64
-	for ( feature = features ; feature < features_end ; feature++ )
61
+	for_each_table_entry ( feature, FEATURES )
65 62
 		printf ( " %s", feature->name );
66 63
 	printf ( "\n" );
67 64
 

+ 2
- 14
src/core/open.c View File

@@ -30,18 +30,6 @@
30 30
  *
31 31
  */
32 32
 
33
-/** Registered URI openers */
34
-static struct uri_opener uri_openers[0]
35
-	__table_start ( struct uri_opener, uri_openers );
36
-static struct uri_opener uri_openers_end[0]
37
-	__table_end ( struct uri_opener, uri_openers );
38
-
39
-/** Registered socket openers */
40
-static struct socket_opener socket_openers[0]
41
-	__table_start ( struct socket_opener, socket_openers );
42
-static struct socket_opener socket_openers_end[0]
43
-	__table_end ( struct socket_opener, socket_openers );
44
-
45 33
 /**
46 34
  * Open URI
47 35
  *
@@ -63,7 +51,7 @@ int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) {
63 51
 		return -ENOMEM;
64 52
 
65 53
 	/* Find opener which supports this URI scheme */
66
-	for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
54
+	for_each_table_entry ( opener, URI_OPENERS ) {
67 55
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
68 56
 			rc = opener->open ( xfer, resolved_uri );
69 57
 			goto done;
@@ -121,7 +109,7 @@ int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
121 109
 	       socket_semantics_name ( semantics ),
122 110
 	       socket_family_name ( peer->sa_family ) );
123 111
 
124
-	for ( opener = socket_openers; opener < socket_openers_end; opener++ ){
112
+	for_each_table_entry ( opener, SOCKET_OPENERS ) {
125 113
 		if ( ( opener->semantics == semantics ) &&
126 114
 		     ( opener->family == peer->sa_family ) ) {
127 115
 			return opener->open ( xfer, peer, local );

+ 1
- 8
src/core/process.c View File

@@ -31,12 +31,6 @@
31 31
 /** Process run queue */
32 32
 static LIST_HEAD ( run_queue );
33 33
 
34
-/** Registered permanent processes */
35
-static struct process processes[0]
36
-	__table_start ( struct process, processes );
37
-static struct process processes_end[0]
38
-	__table_end ( struct process, processes );
39
-
40 34
 /**
41 35
  * Add process to process list
42 36
  *
@@ -93,9 +87,8 @@ void step ( void ) {
93 87
 static void init_processes ( void ) {
94 88
 	struct process *process;
95 89
 
96
-	for ( process = processes ; process < processes_end ; process++ ) {
90
+	for_each_table_entry ( process, PERMANENT_PROCESSES )
97 91
 		process_add ( process );
98
-	}
99 92
 }
100 93
 
101 94
 /** Process initialiser */

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

@@ -150,12 +150,6 @@ struct resolver numeric_resolver __resolver ( RESOLV_NUMERIC ) = {
150 150
  ***************************************************************************
151 151
  */
152 152
 
153
-/** Registered name resolvers */
154
-static struct resolver resolvers[0]
155
-	__table_start ( struct resolver, resolvers );
156
-static struct resolver resolvers_end[0]
157
-	__table_end ( struct resolver, resolvers );
158
-
159 153
 /** A name resolution multiplexer */
160 154
 struct resolv_mux {
161 155
 	/** Reference counter */
@@ -223,7 +217,7 @@ static void resolv_mux_done ( struct resolv_interface *resolv,
223 217
 
224 218
 	/* Attempt next child resolver, if possible */
225 219
 	mux->resolver++;
226
-	if ( mux->resolver >= resolvers_end ) {
220
+	if ( mux->resolver >= table_end ( struct resolver, RESOLVERS ) ) {
227 221
 		DBGC ( mux, "RESOLV %p failed to resolve name\n", mux );
228 222
 		goto finished;
229 223
 	}
@@ -262,7 +256,7 @@ int resolv ( struct resolv_interface *resolv, const char *name,
262 256
 		return -ENOMEM;
263 257
 	resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
264 258
 	resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
265
-	mux->resolver = resolvers;
259
+	mux->resolver = table_start ( struct resolver, RESOLVERS );
266 260
 	memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
267 261
 	memcpy ( mux->name, name, name_len );
268 262
 

+ 3
- 22
src/core/settings.c View File

@@ -37,24 +37,6 @@
37 37
  *
38 38
  */
39 39
 
40
-/** Registered settings */
41
-static struct setting settings[0]
42
-	__table_start ( struct setting, settings );
43
-static struct setting settings_end[0]
44
-	__table_end ( struct setting, settings );
45
-
46
-/** Registered setting types */
47
-static struct setting_type setting_types[0]
48
-	__table_start ( struct setting_type, setting_types );
49
-static struct setting_type setting_types_end[0]
50
-	__table_end ( struct setting_type, setting_types );
51
-
52
-/** Registered settings applicators */
53
-static struct settings_applicator settings_applicators[0]
54
-	__table_start ( struct settings_applicator, settings_applicators );
55
-static struct settings_applicator settings_applicators_end[0]
56
-	__table_end ( struct settings_applicator, settings_applicators );
57
-
58 40
 /******************************************************************************
59 41
  *
60 42
  * Registered settings blocks
@@ -229,8 +211,7 @@ static int apply_settings ( void ) {
229 211
 	int rc;
230 212
 
231 213
 	/* Call all settings applicators */
232
-	for ( applicator = settings_applicators ;
233
-	      applicator < settings_applicators_end ; applicator++ ) {
214
+	for_each_table_entry ( applicator, SETTINGS_APPLICATORS ) {
234 215
 		if ( ( rc = applicator->apply() ) != 0 ) {
235 216
 			DBG ( "Could not apply settings using applicator "
236 217
 			      "%p: %s\n", applicator, strerror ( rc ) );
@@ -670,7 +651,7 @@ int storef_setting ( struct settings *settings, struct setting *setting,
670 651
 static struct setting * find_setting ( const char *name ) {
671 652
 	struct setting *setting;
672 653
 
673
-	for ( setting = settings ; setting < settings_end ; setting++ ) {
654
+	for_each_table_entry ( setting, SETTINGS ) {
674 655
 		if ( strcmp ( name, setting->name ) == 0 )
675 656
 			return setting;
676 657
 	}
@@ -686,7 +667,7 @@ static struct setting * find_setting ( const char *name ) {
686 667
 static struct setting_type * find_setting_type ( const char *name ) {
687 668
 	struct setting_type *type;
688 669
 
689
-	for ( type = setting_types ; type < setting_types_end ; type++ ) {
670
+	for_each_table_entry ( type, SETTING_TYPES ) {
690 671
 		if ( strcmp ( name, type->name ) == 0 )
691 672
 			return type;
692 673
 	}

+ 1
- 6
src/drivers/bus/eisa.c View File

@@ -7,11 +7,6 @@
7 7
 #include <unistd.h>
8 8
 #include <gpxe/eisa.h>
9 9
 
10
-static struct eisa_driver eisa_drivers[0]
11
-	__table_start ( struct eisa_driver, eisa_drivers );
12
-static struct eisa_driver eisa_drivers_end[0]
13
-	__table_end ( struct eisa_driver, eisa_drivers );
14
-
15 10
 static void eisabus_remove ( struct root_device *rootdev );
16 11
 
17 12
 /**
@@ -57,7 +52,7 @@ static int eisa_probe ( struct eisa_device *eisa ) {
57 52
 	      eisa->slot, eisa->vendor_id, eisa->prod_id,
58 53
 	      isa_id_string ( eisa->vendor_id, eisa->prod_id ), eisa->ioaddr );
59 54
 
60
-	for ( driver = eisa_drivers; driver < eisa_drivers_end; driver++ ) {
55
+	for_each_table_entry ( driver, EISA_DRIVERS ) {
61 56
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
62 57
 			id = &driver->ids[i];
63 58
 			if ( id->vendor_id != eisa->vendor_id )

+ 1
- 6
src/drivers/bus/isa.c View File

@@ -48,11 +48,6 @@ static isa_probe_addr_t isa_extra_probe_addrs[] = {
48 48
 	  isa_extra_probe_addrs[ (ioidx) + ISA_EXTRA_PROBE_ADDR_COUNT ] : \
49 49
 	  (driver)->probe_addrs[(ioidx)] )
50 50
 
51
-static struct isa_driver isa_drivers[0]
52
-	__table_start ( struct isa_driver, isa_drivers );
53
-static struct isa_driver isa_drivers_end[0]
54
-	__table_end ( struct isa_driver, isa_drivers );
55
-
56 51
 static void isabus_remove ( struct root_device *rootdev );
57 52
 
58 53
 /**
@@ -100,7 +95,7 @@ static int isabus_probe ( struct root_device *rootdev ) {
100 95
 	int ioidx;
101 96
 	int rc;
102 97
 
103
-	for ( driver = isa_drivers ; driver < isa_drivers_end ; driver++ ) {
98
+	for_each_table_entry ( driver, ISA_DRIVERS ) {
104 99
 		for ( ioidx = ISA_IOIDX_MIN ( driver ) ;
105 100
 		      ioidx <= ISA_IOIDX_MAX ( driver ) ; ioidx++ ) {
106 101
 			/* Allocate struct isa_device */

+ 1
- 6
src/drivers/bus/isapnp.c View File

@@ -72,11 +72,6 @@
72 72
  */
73 73
 uint16_t isapnp_read_port;
74 74
 
75
-static struct isapnp_driver isapnp_drivers[0]
76
-	__table_start ( struct isapnp_driver, isapnp_drivers );
77
-static struct isapnp_driver isapnp_drivers_end[0]
78
-	__table_end ( struct isapnp_driver, isapnp_drivers );
79
-
80 75
 static void isapnpbus_remove ( struct root_device *rootdev );
81 76
 
82 77
 /*
@@ -594,7 +589,7 @@ static int isapnp_probe ( struct isapnp_device *isapnp ) {
594 589
 	      isa_id_string ( isapnp->vendor_id, isapnp->prod_id ),
595 590
 	      isapnp->ioaddr, isapnp->irqno );
596 591
 
597
-	for ( driver = isapnp_drivers; driver < isapnp_drivers_end; driver++ ){
592
+	for_each_table_entry ( driver, ISAPNP_DRIVERS ) {
598 593
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
599 594
 			id = &driver->ids[i];
600 595
 			if ( id->vendor_id != isapnp->vendor_id )

+ 1
- 6
src/drivers/bus/mca.c View File

@@ -13,11 +13,6 @@
13 13
 #include <gpxe/io.h>
14 14
 #include <gpxe/mca.h>
15 15
 
16
-static struct mca_driver mca_drivers[0]
17
-	__table_start ( struct mca_driver, mca_drivers );
18
-static struct mca_driver mca_drivers_end[0]
19
-	__table_end ( struct mca_driver, mca_drivers );
20
-
21 16
 static void mcabus_remove ( struct root_device *rootdev );
22 17
 
23 18
 /**
@@ -41,7 +36,7 @@ static int mca_probe ( struct mca_device *mca ) {
41 36
 	      mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
42 37
 	      mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
43 38
 
44
-	for ( driver = mca_drivers; driver < mca_drivers_end; driver++ ){
39
+	for_each_table_entry ( driver, MCA_DRIVERS ) {
45 40
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
46 41
 			id = &driver->ids[i];
47 42
 			if ( id->id != MCA_ID ( mca ) )

+ 1
- 6
src/drivers/bus/pci.c View File

@@ -34,11 +34,6 @@
34 34
  *
35 35
  */
36 36
 
37
-static struct pci_driver pci_drivers[0]
38
-	__table_start ( struct pci_driver, pci_drivers );
39
-static struct pci_driver pci_drivers_end[0]
40
-	__table_end ( struct pci_driver, pci_drivers );
41
-
42 37
 static void pcibus_remove ( struct root_device *rootdev );
43 38
 
44 39
 /**
@@ -188,7 +183,7 @@ static int pci_probe ( struct pci_device *pci ) {
188 183
 	      PCI_FUNC ( pci->devfn ), pci->vendor, pci->device,
189 184
 	      pci->membase, pci->ioaddr, pci->irq );
190 185
 
191
-	for ( driver = pci_drivers ; driver < pci_drivers_end ; driver++ ) {
186
+	for_each_table_entry ( driver, PCI_DRIVERS ) {
192 187
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
193 188
 			id = &driver->ids[i];
194 189
 			if ( ( id->vendor != PCI_ANY_ID ) &&

+ 1
- 6
src/hci/shell.c View File

@@ -29,11 +29,6 @@
29 29
  *
30 30
  */
31 31
 
32
-static struct command commands[0]
33
-	__table_start ( struct command, commands );
34
-static struct command commands_end[0]
35
-	__table_end ( struct command, commands );
36
-
37 32
 /** The shell prompt string */
38 33
 static const char shell_prompt[] = "gPXE> ";
39 34
 
@@ -65,7 +60,7 @@ static int help_exec ( int argc __unused, char **argv __unused ) {
65 60
 	unsigned int hpos = 0;
66 61
 
67 62
 	printf ( "\nAvailable commands:\n\n" );
68
-	for ( command = commands ; command < commands_end ; command++ ) {
63
+	for_each_table_entry ( command, COMMANDS ) {
69 64
 		hpos += printf ( "  %s", command->name );
70 65
 		if ( hpos > ( 16 * 4 ) ) {
71 66
 			printf ( "\n" );

+ 1
- 7
src/hci/strerror.c View File

@@ -18,11 +18,6 @@
18 18
  *
19 19
  */
20 20
 
21
-static struct errortab errortab_start[0]
22
-	__table_start ( struct errortab, errortab );
23
-static struct errortab errortab_end[0]
24
-	__table_end ( struct errortab, errortab );
25
-
26 21
 /**
27 22
  * Find error description
28 23
  *
@@ -33,8 +28,7 @@ static struct errortab errortab_end[0]
33 28
 static struct errortab * find_error ( int errno, int mask ) {
34 29
 	struct errortab *errortab;
35 30
 
36
-	for ( errortab = errortab_start ; errortab < errortab_end ;
37
-	      errortab++ ) {
31
+	for_each_table_entry ( errortab, ERRORTAB ) {
38 32
 		if ( ( ( errortab->errno ^ errno ) & mask ) == 0 )
39 33
 			return errortab;
40 34
 	}

+ 5
- 6
src/hci/tui/settings_ui.c View File

@@ -77,12 +77,8 @@ struct setting_widget {
77 77
 	char value[256]; /* enough size for a DHCP string */
78 78
 };
79 79
 
80
-/** Registered configuration settings */
81
-static struct setting all_settings[0]
82
-	__table_start ( struct setting, settings );
83
-static struct setting all_settings_end[0]
84
-	__table_end ( struct setting, settings );
85
-#define NUM_SETTINGS ( ( unsigned ) ( all_settings_end - all_settings ) )
80
+/** Number of registered configuration settings */
81
+#define NUM_SETTINGS table_num_entries ( struct setting, SETTINGS )
86 82
 
87 83
 static void load_setting ( struct setting_widget *widget ) __nonnull;
88 84
 static int save_setting ( struct setting_widget *widget ) __nonnull;
@@ -223,6 +219,9 @@ static int edit_setting ( struct setting_widget *widget, int key ) {
223 219
 static void init_setting_index ( struct setting_widget *widget,
224 220
 				 struct settings *settings,
225 221
 				 unsigned int index ) {
222
+	struct setting *all_settings =
223
+		table_start ( struct setting, SETTINGS );
224
+
226 225
 	init_setting ( widget, settings, &all_settings[index],
227 226
 		       ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
228 227
 }

+ 4
- 1
src/include/console.h View File

@@ -85,6 +85,9 @@ struct console_driver {
85 85
 	int ( *iskey ) ( void );
86 86
 };
87 87
 
88
+/** Console driver table */
89
+#define CONSOLES "consoles"
90
+
88 91
 /**
89 92
  * Mark a <tt> struct console_driver </tt> as being part of the
90 93
  * console drivers table.
@@ -102,7 +105,7 @@ struct console_driver {
102 105
  * @endcode
103 106
  *
104 107
  */
105
-#define __console_driver __table ( struct console_driver, console, 01 )
108
+#define __console_driver __table ( struct console_driver, CONSOLES, 01 )
106 109
 
107 110
 /* Function prototypes */
108 111
 

+ 4
- 1
src/include/gpxe/arp.h View File

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

+ 3
- 1
src/include/gpxe/command.h View File

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

+ 4
- 1
src/include/gpxe/device.h View File

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

+ 8
- 2
src/include/gpxe/efi/efi.h View File

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

+ 4
- 1
src/include/gpxe/eisa.h View File

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

+ 3
- 1
src/include/gpxe/errortab.h View File

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

+ 8
- 2
src/include/gpxe/features.h View File

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

+ 3
- 1
src/include/gpxe/gdbstub.h View File

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

+ 4
- 1
src/include/gpxe/image.h View File

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

+ 8
- 2
src/include/gpxe/init.h View File

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

+ 4
- 1
src/include/gpxe/isa.h View File

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

+ 4
- 1
src/include/gpxe/isapnp.h View File

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

+ 4
- 1
src/include/gpxe/mca.h View File

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

+ 8
- 2
src/include/gpxe/netdevice.h View File

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

+ 8
- 2
src/include/gpxe/open.h View File

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

+ 4
- 1
src/include/gpxe/pci.h View File

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

+ 4
- 1
src/include/gpxe/process.h View File

@@ -63,6 +63,9 @@ process_init ( struct process *process,
63 63
 	process_add ( process );
64 64
 }
65 65
 
66
+/** Permanent process table */
67
+#define PERMANENT_PROCESSES "processes"
68
+
66 69
 /**
67 70
  * Declare a permanent process
68 71
  *
@@ -70,6 +73,6 @@ process_init ( struct process *process,
70 73
  * at initialisation time.
71 74
  */
72 75
 #define __permanent_process \
73
-	__table ( struct process, processes, 01 )
76
+	__table ( struct process, PERMANENT_PROCESSES, 01 )
74 77
 
75 78
 #endif /* _GPXE_PROCESS_H */

+ 4
- 1
src/include/gpxe/resolv.h View File

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

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

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

+ 12
- 3
src/include/gpxe/settings.h View File

@@ -36,8 +36,11 @@ struct setting {
36 36
 	unsigned int tag;
37 37
 };
38 38
 
39
+/** Configuration setting table */
40
+#define SETTINGS "settings"
41
+
39 42
 /** Declare a configuration setting */
40
-#define	__setting __table ( struct setting, settings, 01 )
43
+#define	__setting __table ( struct setting, SETTINGS, 01 )
41 44
 
42 45
 /** Settings block operations */
43 46
 struct settings_operations {
@@ -123,9 +126,12 @@ struct setting_type {
123 126
 			   char *buf, size_t len );
124 127
 };
125 128
 
129
+/** Configuration setting type table */
130
+#define SETTING_TYPES "setting_types"
131
+
126 132
 /** Declare a configuration setting type */
127 133
 #define	__setting_type \
128
-	__table ( struct setting_type, setting_types, 01 )
134
+	__table ( struct setting_type, SETTING_TYPES, 01 )
129 135
 
130 136
 /**
131 137
  * A settings applicator
@@ -139,9 +145,12 @@ struct settings_applicator {
139 145
 	int ( * apply ) ( void );
140 146
 };
141 147
 
148
+/** Settings applicator table */
149
+#define SETTINGS_APPLICATORS "settings_applicators"
150
+
142 151
 /** Declare a settings applicator */
143 152
 #define __settings_applicator \
144
-	__table ( struct settings_applicator, settings_applicators, 01 )
153
+	__table ( struct settings_applicator, SETTINGS_APPLICATORS, 01 )
145 154
 
146 155
 /**
147 156
  * A simple settings block

+ 81
- 19
src/include/gpxe/tables.h View File

@@ -115,7 +115,7 @@
115 115
  *	void ( *frob ) ( void ); 	// The frobnicating function itself
116 116
  *   };
117 117
  *
118
- *   #define __frobnicator __table ( frobnicators, 01 )
118
+ *   #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 )
119 119
  *
120 120
  * @endcode
121 121
  *
@@ -145,14 +145,11 @@
145 145
  *
146 146
  *   #include "frob.h"
147 147
  *
148
- *   static struct frob frob_start[0] __table_start ( frobnicators );
149
- *   static struct frob frob_end[0] __table_end ( frobnicators );
150
- *
151 148
  *   // Call all linked-in frobnicators
152 149
  *   void frob_all ( void ) {
153 150
  *	struct frob *frob;
154 151
  *
155
- *      for ( frob = frob_start ; frob < frob_end ; frob++ ) {
152
+ *	for_each_table ( frob, "frobnicators" ) {
156 153
  *         printf ( "Calling frobnicator \"%s\"\n", frob->name );
157 154
  *	   frob->frob ();
158 155
  *	}
@@ -170,7 +167,7 @@
170 167
 
171 168
 #define __table_str( x ) #x
172 169
 #define __table_section( table, idx ) \
173
-	__section__ ( ".tbl." __table_str ( table ) "." __table_str ( idx ) )
170
+	__section__ ( ".tbl." table "." __table_str ( idx ) )
174 171
 
175 172
 #define __table_section_start( table ) __table_section ( table, 00 )
176 173
 #define __table_section_end( table ) __table_section ( table, 99 )
@@ -185,45 +182,110 @@
185 182
  *
186 183
  * @code
187 184
  *
188
- *   struct my_foo __table ( foo, 01 ) = {
185
+ *   #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 )
186
+ *
187
+ *   struct frobnicator my_frob __frobnicator = {
189 188
  *      ...
190 189
  *   };
191 190
  *
192 191
  * @endcode
193 192
  *
194 193
  */
195
-#define __table( type, table, idx )				\
196
-	__attribute__ (( __table_section ( table, idx ),	\
194
+#define __table( type, table, idx )					\
195
+	__attribute__ (( __table_section ( table, idx ),		\
197 196
 			 __natural_alignment ( type ) ))
198 197
 
199 198
 /**
200
- * Linker table start marker.
199
+ * Start of linker table.
200
+ *
201
+ * Return the start of a linker table.  Use as e.g.
202
+ *
203
+ * @code
204
+ *
205
+ *   struct frobnicator *frobs =
206
+ *	table_start ( struct frobnicator, "frobnicators" );
207
+ *
208
+ * @endcode
209
+ *
210
+ */
211
+#define table_start( type, table ) ( {					\
212
+	static type __table_start[0] __table ( type, table, 00 );	\
213
+	__table_start; } )
214
+
215
+/**
216
+ * End of linker table.
217
+ *
218
+ * Return the end of a linker table.  Use as e.g.
219
+ *
220
+ * @code
221
+ *
222
+ *   struct frobnicator *frobs_end =
223
+ *	table_end ( struct frobnicator, "frobnicators" );
224
+ *
225
+ * @endcode
226
+ *
227
+ */
228
+#define table_end( type, table ) ( {					\
229
+	static type __table_end[0] __table ( type, table, 99 );		\
230
+	__table_end; } )
231
+
232
+/**
233
+ * Calculate number of entries in linker table.
234
+ *
235
+ * Return the number of entries within a linker table.  Use as e.g.
236
+ *
237
+ * @code
238
+ *
239
+ *   unsigned int num_frobs =
240
+ *	table_num_entries ( struct frobnicator, "frobnicators" );
241
+ *
242
+ * @endcode
243
+ *
244
+ */
245
+#define table_num_entries( type, table )				\
246
+	( ( unsigned int ) ( table_end ( type, table ) -		\
247
+			     table_start ( type, table ) ) )
248
+
249
+/**
250
+ * Iterate through all entries within a linker table.
201 251
  *
202
- * Declares a data structure (usually an empty data structure) to be
203
- * the start of a linker table.  Use as e.g.
252
+ * Use as e.g.
204 253
  *
205 254
  * @code
206 255
  *
207
- *   static struct foo_start[0] __table_start ( foo );
256
+ *   struct frobnicator *frob;
257
+ *
258
+ *   for_each_table_entry ( frob, "frobnicators" ) {
259
+ *     ...
260
+ *   }
208 261
  *
209 262
  * @endcode
210 263
  *
211 264
  */
212
-#define __table_start( type, table ) __table ( type, table, 00 )
265
+#define for_each_table_entry( pointer, table )				\
266
+	for ( pointer = table_start ( typeof ( * pointer ), table ) ;	\
267
+	      pointer < table_end ( typeof ( * pointer ), table ) ;	\
268
+	      pointer++ )
213 269
 
214 270
 /**
215
- * Linker table end marker.
271
+ * Iterate through all entries within a linker table in reverse order.
216 272
  *
217
- * Declares a data structure (usually an empty data structure) to be
218
- * the end of a linker table.  Use as e.g.
273
+ * Use as e.g.
219 274
  *
220 275
  * @code
221 276
  *
222
- *   static struct foo_end[0] __table_end ( foo );
277
+ *   struct frobnicator *frob;
278
+ *
279
+ *   for_each_table_entry_reverse ( frob, "frobnicators" ) {
280
+ *     ...
281
+ *   }
223 282
  *
224 283
  * @endcode
225 284
  *
226 285
  */
227
-#define __table_end( type, table ) __table ( type, table, 99 )
286
+#define for_each_table_entry_reverse( pointer, table )			\
287
+	for ( pointer = table_end ( typeof ( * pointer ), table ) - 1 ;	\
288
+	      pointer >= table_start ( typeof ( * pointer ), table ) ;	\
289
+	      pointer-- )
228 290
 
229 291
 #endif /* _GPXE_TABLES_H */

+ 8
- 2
src/include/gpxe/tcpip.h View File

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

+ 2
- 14
src/interface/efi/efi_init.c View File

@@ -26,18 +26,6 @@ EFI_HANDLE efi_image_handle;
26 26
 /** System table passed to entry point */
27 27
 EFI_SYSTEM_TABLE *efi_systab;
28 28
 
29
-/** Declared used EFI protocols */
30
-static struct efi_protocol efi_protocols[0] \
31
-	__table_start ( struct efi_protocol, efi_protocols );
32
-static struct efi_protocol efi_protocols_end[0] \
33
-	__table_end ( struct efi_protocol, efi_protocols );
34
-
35
-/** Declared used EFI configuration tables */
36
-static struct efi_config_table efi_config_tables[0] \
37
-	__table_start ( struct efi_config_table, efi_config_tables );
38
-static struct efi_config_table efi_config_tables_end[0] \
39
-	__table_end ( struct efi_config_table, efi_config_tables );
40
-
41 29
 /**
42 30
  * Look up EFI configuration table
43 31
  *
@@ -92,7 +80,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
92 80
 
93 81
 	/* Look up used protocols */
94 82
 	bs = systab->BootServices;
95
-	for ( prot = efi_protocols ; prot < efi_protocols_end ; prot++ ) {
83
+	for_each_table_entry ( prot, EFI_PROTOCOLS ) {
96 84
 		if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL,
97 85
 						    prot->protocol ) ) == 0 ) {
98 86
 			DBGC ( systab, "EFI protocol %s is at %p\n",
@@ -106,7 +94,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
106 94
 	}
107 95
 
108 96
 	/* Look up used configuration tables */
109
-	for ( tab = efi_config_tables ; tab < efi_config_tables_end ; tab++ ) {
97
+	for_each_table_entry ( tab, EFI_CONFIG_TABLES ) {
110 98
 		if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) {
111 99
 			DBGC ( systab, "EFI configuration table %s is at %p\n",
112 100
 			       uuid_ntoa ( &tab->u.uuid ), *(tab->table) );

+ 1
- 8
src/net/arp.c View File

@@ -36,12 +36,6 @@
36 36
  *
37 37
  */
38 38
 
39
-/** Registered ARP protocols */
40
-static struct arp_net_protocol arp_net_protocols[0]
41
-	__table_start ( struct arp_net_protocol, arp_net_protocols );
42
-static struct arp_net_protocol arp_net_protocols_end[0]
43
-	__table_end ( struct arp_net_protocol, arp_net_protocols );
44
-
45 39
 /** An ARP cache entry */
46 40
 struct arp_entry {
47 41
 	/** Network-layer protocol */
@@ -176,8 +170,7 @@ int arp_resolve ( struct net_device *netdev, struct net_protocol *net_protocol,
176 170
 static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) {
177 171
 	struct arp_net_protocol *arp_net_protocol;
178 172
 
179
-	for ( arp_net_protocol = arp_net_protocols ;
180
-	      arp_net_protocol < arp_net_protocols_end ; arp_net_protocol++ ) {
173
+	for_each_table_entry ( arp_net_protocol, ARP_NET_PROTOCOLS ) {
181 174
 		if ( arp_net_protocol->net_protocol->net_proto == net_proto ) {
182 175
 			return arp_net_protocol;
183 176
 		}

+ 1
- 8
src/net/netdevice.c View File

@@ -36,12 +36,6 @@
36 36
  *
37 37
  */
38 38
 
39
-/** Registered network-layer protocols */
40
-static struct net_protocol net_protocols[0]
41
-	__table_start ( struct net_protocol, net_protocols );
42
-static struct net_protocol net_protocols_end[0]
43
-	__table_end ( struct net_protocol, net_protocols );
44
-
45 39
 /** List of network devices */
46 40
 struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
47 41
 
@@ -538,8 +532,7 @@ int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
538 532
 	struct net_protocol *net_protocol;
539 533
 
540 534
 	/* Hand off to network-layer protocol, if any */
541
-	for ( net_protocol = net_protocols ; net_protocol < net_protocols_end ;
542
-	      net_protocol++ ) {
535
+	for_each_table_entry ( net_protocol, NET_PROTOCOLS ) {
543 536
 		if ( net_protocol->net_proto == net_proto ) {
544 537
 			return net_protocol->rx ( iobuf, netdev, ll_source );
545 538
 		}

+ 2
- 15
src/net/tcpip.c View File

@@ -14,18 +14,6 @@
14 14
  * TCP/IP transport-network layer interface
15 15
  */
16 16
 
17
-/** Registered network-layer protocols that support TCP/IP */
18
-static struct tcpip_net_protocol tcpip_net_protocols[0]
19
-	__table_start ( struct tcpip_net_protocol, tcpip_net_protocols );
20
-static struct tcpip_net_protocol tcpip_net_protocols_end[0]
21
-	__table_end ( struct tcpip_net_protocol, tcpip_net_protocols );
22
-
23
-/** Registered transport-layer protocols that support TCP/IP */
24
-static struct tcpip_protocol tcpip_protocols[0]
25
-	__table_start ( struct tcpip_protocol, tcpip_protocols );
26
-static struct tcpip_protocol tcpip_protocols_end[0]
27
-	__table_end ( struct tcpip_protocol, tcpip_protocols );
28
-
29 17
 /** Process a received TCP/IP packet
30 18
  *
31 19
  * @v iobuf		I/O buffer
@@ -48,7 +36,7 @@ int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
48 36
 	struct tcpip_protocol *tcpip;
49 37
 
50 38
 	/* Hand off packet to the appropriate transport-layer protocol */
51
-	for ( tcpip = tcpip_protocols; tcpip < tcpip_protocols_end; tcpip++ ) {
39
+	for_each_table_entry ( tcpip, TCPIP_PROTOCOLS ) {
52 40
 		if ( tcpip->tcpip_proto == tcpip_proto ) {
53 41
 			DBG ( "TCP/IP received %s packet\n", tcpip->name );
54 42
 			return tcpip->rx ( iobuf, st_src, st_dest, pshdr_csum );
@@ -76,8 +64,7 @@ int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol,
76 64
 	struct tcpip_net_protocol *tcpip_net;
77 65
 
78 66
 	/* Hand off packet to the appropriate network-layer protocol */
79
-	for ( tcpip_net = tcpip_net_protocols ;
80
-	      tcpip_net < tcpip_net_protocols_end ; tcpip_net++ ) {
67
+	for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
81 68
 		if ( tcpip_net->sa_family == st_dest->st_family ) {
82 69
 			DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
83 70
 			return tcpip_net->tx ( iobuf, tcpip_protocol, st_src,

+ 3
- 5
src/net/udp/dhcp.c View File

@@ -88,10 +88,6 @@ static uint8_t dhcp_request_options_data[] = {
88 88
 	DHCP_END
89 89
 };
90 90
 
91
-/** DHCP feature codes */
92
-static uint8_t dhcp_features[0] __table_start ( uint8_t, dhcp_features );
93
-static uint8_t dhcp_features_end[0] __table_end ( uint8_t, dhcp_features );
94
-
95 91
 /** Version number feature */
96 92
 FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
97 93
 
@@ -884,6 +880,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
884 880
 	struct dhcp_netdev_desc dhcp_desc;
885 881
 	struct dhcp_client_id client_id;
886 882
 	struct dhcp_client_uuid client_uuid;
883
+	uint8_t *dhcp_features;
887 884
 	size_t dhcp_features_len;
888 885
 	size_t ll_addr_len;
889 886
 	ssize_t len;
@@ -903,7 +900,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
903 900
 	dhcppkt->dhcphdr->ciaddr = ciaddr;
904 901
 
905 902
 	/* Add options to identify the feature list */
906
-	dhcp_features_len = ( dhcp_features_end - dhcp_features );
903
+	dhcp_features = table_start ( uint8_t, DHCP_FEATURES );
904
+	dhcp_features_len = table_num_entries ( uint8_t, DHCP_FEATURES );
907 905
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
908 906
 				    dhcp_features_len ) ) != 0 ) {
909 907
 		DBG ( "DHCP could not set features list option: %s\n",

+ 1
- 8
src/usr/autoboot.c View File

@@ -43,12 +43,6 @@
43 43
 /** Shutdown flags for exit */
44 44
 int shutdown_exit_flags = 0;
45 45
 
46
-/* SAN boot protocols */
47
-static struct sanboot_protocol sanboot_protocols[0] \
48
-	__table_start ( struct sanboot_protocol, sanboot_protocols );
49
-static struct sanboot_protocol sanboot_protocols_end[0] \
50
-	__table_end ( struct sanboot_protocol, sanboot_protocols );
51
-
52 46
 /**
53 47
  * Identify the boot network device
54 48
  *
@@ -124,8 +118,7 @@ int boot_root_path ( const char *root_path ) {
124 118
 	struct sanboot_protocol *sanboot;
125 119
 
126 120
 	/* Quick hack */
127
-	for ( sanboot = sanboot_protocols ;
128
-	      sanboot < sanboot_protocols_end ; sanboot++ ) {
121
+	for_each_table_entry ( sanboot, SANBOOT_PROTOCOLS ) {
129 122
 		if ( strncmp ( root_path, sanboot->prefix,
130 123
 			       strlen ( sanboot->prefix ) ) == 0 ) {
131 124
 			return sanboot->boot ( root_path );

Loading…
Cancel
Save