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
48 changed files with 239 additions and 264 deletions
  1. 2
    9
      src/core/console.c
  2. 1
    6
      src/core/device.c
  3. 1
    6
      src/core/exec.c
  4. 2
    5
      src/core/gdbstub.c
  5. 1
    7
      src/core/image.c
  6. 4
    19
      src/core/init.c
  7. 1
    4
      src/core/main.c
  8. 2
    14
      src/core/open.c
  9. 1
    8
      src/core/process.c
  10. 2
    8
      src/core/resolv.c
  11. 3
    22
      src/core/settings.c
  12. 1
    6
      src/drivers/bus/eisa.c
  13. 1
    6
      src/drivers/bus/isa.c
  14. 1
    6
      src/drivers/bus/isapnp.c
  15. 1
    6
      src/drivers/bus/mca.c
  16. 1
    6
      src/drivers/bus/pci.c
  17. 1
    6
      src/hci/shell.c
  18. 1
    7
      src/hci/strerror.c
  19. 5
    6
      src/hci/tui/settings_ui.c
  20. 4
    1
      src/include/console.h
  21. 4
    1
      src/include/gpxe/arp.h
  22. 3
    1
      src/include/gpxe/command.h
  23. 4
    1
      src/include/gpxe/device.h
  24. 8
    2
      src/include/gpxe/efi/efi.h
  25. 4
    1
      src/include/gpxe/eisa.h
  26. 3
    1
      src/include/gpxe/errortab.h
  27. 8
    2
      src/include/gpxe/features.h
  28. 3
    1
      src/include/gpxe/gdbstub.h
  29. 4
    1
      src/include/gpxe/image.h
  30. 8
    2
      src/include/gpxe/init.h
  31. 4
    1
      src/include/gpxe/isa.h
  32. 4
    1
      src/include/gpxe/isapnp.h
  33. 4
    1
      src/include/gpxe/mca.h
  34. 8
    2
      src/include/gpxe/netdevice.h
  35. 8
    2
      src/include/gpxe/open.h
  36. 4
    1
      src/include/gpxe/pci.h
  37. 4
    1
      src/include/gpxe/process.h
  38. 4
    1
      src/include/gpxe/resolv.h
  39. 3
    1
      src/include/gpxe/sanboot.h
  40. 12
    3
      src/include/gpxe/settings.h
  41. 81
    19
      src/include/gpxe/tables.h
  42. 8
    2
      src/include/gpxe/tcpip.h
  43. 2
    14
      src/interface/efi/efi_init.c
  44. 1
    8
      src/net/arp.c
  45. 1
    8
      src/net/netdevice.c
  46. 2
    15
      src/net/tcpip.c
  47. 3
    5
      src/net/udp/dhcp.c
  48. 1
    8
      src/usr/autoboot.c

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

5
 
5
 
6
 /** @file */
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
  * Write a single character to each console device.
9
  * Write a single character to each console device.
15
  *
10
  *
28
 	if ( character == '\n' )
23
 	if ( character == '\n' )
29
 		putchar ( '\r' );
24
 		putchar ( '\r' );
30
 
25
 
31
-	for ( console = console_drivers; console < console_drivers_end ;
32
-	      console++ ) {
26
+	for_each_table_entry ( console, CONSOLES ) {
33
 		if ( ( ! console->disabled ) && console->putchar )
27
 		if ( ( ! console->disabled ) && console->putchar )
34
 			console->putchar ( character );
28
 			console->putchar ( character );
35
 	}
29
 	}
51
 static struct console_driver * has_input ( void ) {
45
 static struct console_driver * has_input ( void ) {
52
 	struct console_driver *console;
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
 		if ( ( ! console->disabled ) && console->iskey ) {
49
 		if ( ( ! console->disabled ) && console->iskey ) {
57
 			if ( console->iskey () )
50
 			if ( console->iskey () )
58
 				return console;
51
 				return console;

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

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
 /** Registered root devices */
32
 /** Registered root devices */
38
 static LIST_HEAD ( devices );
33
 static LIST_HEAD ( devices );
39
 
34
 
77
 	struct root_device *rootdev;
72
 	struct root_device *rootdev;
78
 	int rc;
73
 	int rc;
79
 
74
 
80
-	for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
75
+	for_each_table_entry ( rootdev, ROOT_DEVICES ) {
81
 		list_add ( &rootdev->dev.siblings, &devices );
76
 		list_add ( &rootdev->dev.siblings, &devices );
82
 		INIT_LIST_HEAD ( &rootdev->dev.children );
77
 		INIT_LIST_HEAD ( &rootdev->dev.children );
83
 		if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
78
 		if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )

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

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
 /* Avoid dragging in getopt.o unless a command really uses it */
37
 /* Avoid dragging in getopt.o unless a command really uses it */
43
 int optind;
38
 int optind;
44
 int nextchar;
39
 int nextchar;
78
 	reset_getopt();
73
 	reset_getopt();
79
 
74
 
80
 	/* Hand off to command implementation */
75
 	/* Hand off to command implementation */
81
-	for ( cmd = commands ; cmd < commands_end ; cmd++ ) {
76
+	for_each_table_entry ( cmd, COMMANDS ) {
82
 		if ( strcmp ( command, cmd->name ) == 0 )
77
 		if ( strcmp ( command, cmd->name ) == 0 )
83
 			return cmd->exec ( argc, ( char ** ) argv );
78
 			return cmd->exec ( argc, ( char ** ) argv );
84
 	}
79
 	}

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

54
 	int len;                         /* length of payload */
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
 /* Packet parser states */
57
 /* Packet parser states */
62
 static void gdbstub_state_new ( struct gdbstub *stub, char ch );
58
 static void gdbstub_state_new ( struct gdbstub *stub, char ch );
63
 static void gdbstub_state_data ( struct gdbstub *stub, char ch );
59
 static void gdbstub_state_data ( struct gdbstub *stub, char ch );
387
 
383
 
388
 struct gdb_transport *find_gdb_transport ( const char *name ) {
384
 struct gdb_transport *find_gdb_transport ( const char *name ) {
389
 	struct gdb_transport *trans;
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
 		if ( strcmp ( trans->name, name ) == 0 ) {
388
 		if ( strcmp ( trans->name, name ) == 0 ) {
392
 			return trans;
389
 			return trans;
393
 		}
390
 		}

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

37
 /** List of registered images */
37
 /** List of registered images */
38
 struct list_head images = LIST_HEAD_INIT ( images );
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
  * Free executable/loadable image
41
  * Free executable/loadable image
48
  *
42
  *
219
 		return image_load ( image );
213
 		return image_load ( image );
220
 
214
 
221
 	/* Otherwise probe for a suitable type */
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
 		DBGC ( image, "IMAGE %p trying type %s\n", image, type->name );
217
 		DBGC ( image, "IMAGE %p trying type %s\n", image, type->name );
224
 		rc = image_load_type ( image, type );
218
 		rc = image_load_type ( image, type );
225
 		if ( image->type == NULL )
219
 		if ( image->type == NULL )

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

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
 /** "startup() has been called" flag */
28
 /** "startup() has been called" flag */
41
 static int started = 0;
29
 static int started = 0;
42
 
30
 
54
 	struct init_fn *init_fn;
42
 	struct init_fn *init_fn;
55
 
43
 
56
 	/* Call registered initialisation functions */
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
 		init_fn->initialise ();
46
 		init_fn->initialise ();
59
-	}
60
 }
47
 }
61
 
48
 
62
 /**
49
 /**
73
 		return;
60
 		return;
74
 
61
 
75
 	/* Call registered startup functions */
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
 		if ( startup_fn->startup )
64
 		if ( startup_fn->startup )
79
 			startup_fn->startup();
65
 			startup_fn->startup();
80
 	}
66
 	}
90
  * This function reverses the actions of startup(), and leaves gPXE in
76
  * This function reverses the actions of startup(), and leaves gPXE in
91
  * a state ready to be removed from memory.  You may call startup()
77
  * a state ready to be removed from memory.  You may call startup()
92
  * again after calling shutdown().
78
  * again after calling shutdown().
93
-
79
+ *
94
  * Call this function only once, before either exiting main() or
80
  * Call this function only once, before either exiting main() or
95
  * starting up a non-returnable image.
81
  * starting up a non-returnable image.
96
  */
82
  */
101
 		return;
87
 		return;
102
 
88
 
103
 	/* Call registered shutdown functions (in reverse order) */
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
 		if ( startup_fn->shutdown )
91
 		if ( startup_fn->shutdown )
107
 			startup_fn->shutdown ( flags );
92
 			startup_fn->shutdown ( flags );
108
 	}
93
 	}

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

27
 #define BOLD	"\033[1m"
27
 #define BOLD	"\033[1m"
28
 #define CYAN	"\033[36m"
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
  * Main entry point
31
  * Main entry point
35
  *
32
  *
61
 		 NORMAL " -- Open Source Boot Firmware -- "
58
 		 NORMAL " -- Open Source Boot Firmware -- "
62
 		 CYAN "http://etherboot.org" NORMAL "\n"
59
 		 CYAN "http://etherboot.org" NORMAL "\n"
63
 		 "Features:" );
60
 		 "Features:" );
64
-	for ( feature = features ; feature < features_end ; feature++ )
61
+	for_each_table_entry ( feature, FEATURES )
65
 		printf ( " %s", feature->name );
62
 		printf ( " %s", feature->name );
66
 	printf ( "\n" );
63
 	printf ( "\n" );
67
 
64
 

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

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
  * Open URI
34
  * Open URI
47
  *
35
  *
63
 		return -ENOMEM;
51
 		return -ENOMEM;
64
 
52
 
65
 	/* Find opener which supports this URI scheme */
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
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
55
 		if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) {
68
 			rc = opener->open ( xfer, resolved_uri );
56
 			rc = opener->open ( xfer, resolved_uri );
69
 			goto done;
57
 			goto done;
121
 	       socket_semantics_name ( semantics ),
109
 	       socket_semantics_name ( semantics ),
122
 	       socket_family_name ( peer->sa_family ) );
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
 		if ( ( opener->semantics == semantics ) &&
113
 		if ( ( opener->semantics == semantics ) &&
126
 		     ( opener->family == peer->sa_family ) ) {
114
 		     ( opener->family == peer->sa_family ) ) {
127
 			return opener->open ( xfer, peer, local );
115
 			return opener->open ( xfer, peer, local );

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

31
 /** Process run queue */
31
 /** Process run queue */
32
 static LIST_HEAD ( run_queue );
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
  * Add process to process list
35
  * Add process to process list
42
  *
36
  *
93
 static void init_processes ( void ) {
87
 static void init_processes ( void ) {
94
 	struct process *process;
88
 	struct process *process;
95
 
89
 
96
-	for ( process = processes ; process < processes_end ; process++ ) {
90
+	for_each_table_entry ( process, PERMANENT_PROCESSES )
97
 		process_add ( process );
91
 		process_add ( process );
98
-	}
99
 }
92
 }
100
 
93
 
101
 /** Process initialiser */
94
 /** Process initialiser */

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

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
 /** A name resolution multiplexer */
153
 /** A name resolution multiplexer */
160
 struct resolv_mux {
154
 struct resolv_mux {
161
 	/** Reference counter */
155
 	/** Reference counter */
223
 
217
 
224
 	/* Attempt next child resolver, if possible */
218
 	/* Attempt next child resolver, if possible */
225
 	mux->resolver++;
219
 	mux->resolver++;
226
-	if ( mux->resolver >= resolvers_end ) {
220
+	if ( mux->resolver >= table_end ( struct resolver, RESOLVERS ) ) {
227
 		DBGC ( mux, "RESOLV %p failed to resolve name\n", mux );
221
 		DBGC ( mux, "RESOLV %p failed to resolve name\n", mux );
228
 		goto finished;
222
 		goto finished;
229
 	}
223
 	}
262
 		return -ENOMEM;
256
 		return -ENOMEM;
263
 	resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
257
 	resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
264
 	resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
258
 	resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
265
-	mux->resolver = resolvers;
259
+	mux->resolver = table_start ( struct resolver, RESOLVERS );
266
 	memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
260
 	memcpy ( &mux->sa, sa, sizeof ( mux->sa ) );
267
 	memcpy ( mux->name, name, name_len );
261
 	memcpy ( mux->name, name, name_len );
268
 
262
 

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

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
  * Registered settings blocks
42
  * Registered settings blocks
229
 	int rc;
211
 	int rc;
230
 
212
 
231
 	/* Call all settings applicators */
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
 		if ( ( rc = applicator->apply() ) != 0 ) {
215
 		if ( ( rc = applicator->apply() ) != 0 ) {
235
 			DBG ( "Could not apply settings using applicator "
216
 			DBG ( "Could not apply settings using applicator "
236
 			      "%p: %s\n", applicator, strerror ( rc ) );
217
 			      "%p: %s\n", applicator, strerror ( rc ) );
670
 static struct setting * find_setting ( const char *name ) {
651
 static struct setting * find_setting ( const char *name ) {
671
 	struct setting *setting;
652
 	struct setting *setting;
672
 
653
 
673
-	for ( setting = settings ; setting < settings_end ; setting++ ) {
654
+	for_each_table_entry ( setting, SETTINGS ) {
674
 		if ( strcmp ( name, setting->name ) == 0 )
655
 		if ( strcmp ( name, setting->name ) == 0 )
675
 			return setting;
656
 			return setting;
676
 	}
657
 	}
686
 static struct setting_type * find_setting_type ( const char *name ) {
667
 static struct setting_type * find_setting_type ( const char *name ) {
687
 	struct setting_type *type;
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
 		if ( strcmp ( name, type->name ) == 0 )
671
 		if ( strcmp ( name, type->name ) == 0 )
691
 			return type;
672
 			return type;
692
 	}
673
 	}

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

7
 #include <unistd.h>
7
 #include <unistd.h>
8
 #include <gpxe/eisa.h>
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
 static void eisabus_remove ( struct root_device *rootdev );
10
 static void eisabus_remove ( struct root_device *rootdev );
16
 
11
 
17
 /**
12
 /**
57
 	      eisa->slot, eisa->vendor_id, eisa->prod_id,
52
 	      eisa->slot, eisa->vendor_id, eisa->prod_id,
58
 	      isa_id_string ( eisa->vendor_id, eisa->prod_id ), eisa->ioaddr );
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
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
56
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
62
 			id = &driver->ids[i];
57
 			id = &driver->ids[i];
63
 			if ( id->vendor_id != eisa->vendor_id )
58
 			if ( id->vendor_id != eisa->vendor_id )

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

48
 	  isa_extra_probe_addrs[ (ioidx) + ISA_EXTRA_PROBE_ADDR_COUNT ] : \
48
 	  isa_extra_probe_addrs[ (ioidx) + ISA_EXTRA_PROBE_ADDR_COUNT ] : \
49
 	  (driver)->probe_addrs[(ioidx)] )
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
 static void isabus_remove ( struct root_device *rootdev );
51
 static void isabus_remove ( struct root_device *rootdev );
57
 
52
 
58
 /**
53
 /**
100
 	int ioidx;
95
 	int ioidx;
101
 	int rc;
96
 	int rc;
102
 
97
 
103
-	for ( driver = isa_drivers ; driver < isa_drivers_end ; driver++ ) {
98
+	for_each_table_entry ( driver, ISA_DRIVERS ) {
104
 		for ( ioidx = ISA_IOIDX_MIN ( driver ) ;
99
 		for ( ioidx = ISA_IOIDX_MIN ( driver ) ;
105
 		      ioidx <= ISA_IOIDX_MAX ( driver ) ; ioidx++ ) {
100
 		      ioidx <= ISA_IOIDX_MAX ( driver ) ; ioidx++ ) {
106
 			/* Allocate struct isa_device */
101
 			/* Allocate struct isa_device */

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

72
  */
72
  */
73
 uint16_t isapnp_read_port;
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
 static void isapnpbus_remove ( struct root_device *rootdev );
75
 static void isapnpbus_remove ( struct root_device *rootdev );
81
 
76
 
82
 /*
77
 /*
594
 	      isa_id_string ( isapnp->vendor_id, isapnp->prod_id ),
589
 	      isa_id_string ( isapnp->vendor_id, isapnp->prod_id ),
595
 	      isapnp->ioaddr, isapnp->irqno );
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
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
593
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
599
 			id = &driver->ids[i];
594
 			id = &driver->ids[i];
600
 			if ( id->vendor_id != isapnp->vendor_id )
595
 			if ( id->vendor_id != isapnp->vendor_id )

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

13
 #include <gpxe/io.h>
13
 #include <gpxe/io.h>
14
 #include <gpxe/mca.h>
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
 static void mcabus_remove ( struct root_device *rootdev );
16
 static void mcabus_remove ( struct root_device *rootdev );
22
 
17
 
23
 /**
18
 /**
41
 	      mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
36
 	      mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
42
 	      mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
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
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
40
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
46
 			id = &driver->ids[i];
41
 			id = &driver->ids[i];
47
 			if ( id->id != MCA_ID ( mca ) )
42
 			if ( id->id != MCA_ID ( mca ) )

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

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
 static void pcibus_remove ( struct root_device *rootdev );
37
 static void pcibus_remove ( struct root_device *rootdev );
43
 
38
 
44
 /**
39
 /**
188
 	      PCI_FUNC ( pci->devfn ), pci->vendor, pci->device,
183
 	      PCI_FUNC ( pci->devfn ), pci->vendor, pci->device,
189
 	      pci->membase, pci->ioaddr, pci->irq );
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
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
187
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
193
 			id = &driver->ids[i];
188
 			id = &driver->ids[i];
194
 			if ( ( id->vendor != PCI_ANY_ID ) &&
189
 			if ( ( id->vendor != PCI_ANY_ID ) &&

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

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
 /** The shell prompt string */
32
 /** The shell prompt string */
38
 static const char shell_prompt[] = "gPXE> ";
33
 static const char shell_prompt[] = "gPXE> ";
39
 
34
 
65
 	unsigned int hpos = 0;
60
 	unsigned int hpos = 0;
66
 
61
 
67
 	printf ( "\nAvailable commands:\n\n" );
62
 	printf ( "\nAvailable commands:\n\n" );
68
-	for ( command = commands ; command < commands_end ; command++ ) {
63
+	for_each_table_entry ( command, COMMANDS ) {
69
 		hpos += printf ( "  %s", command->name );
64
 		hpos += printf ( "  %s", command->name );
70
 		if ( hpos > ( 16 * 4 ) ) {
65
 		if ( hpos > ( 16 * 4 ) ) {
71
 			printf ( "\n" );
66
 			printf ( "\n" );

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

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
  * Find error description
22
  * Find error description
28
  *
23
  *
33
 static struct errortab * find_error ( int errno, int mask ) {
28
 static struct errortab * find_error ( int errno, int mask ) {
34
 	struct errortab *errortab;
29
 	struct errortab *errortab;
35
 
30
 
36
-	for ( errortab = errortab_start ; errortab < errortab_end ;
37
-	      errortab++ ) {
31
+	for_each_table_entry ( errortab, ERRORTAB ) {
38
 		if ( ( ( errortab->errno ^ errno ) & mask ) == 0 )
32
 		if ( ( ( errortab->errno ^ errno ) & mask ) == 0 )
39
 			return errortab;
33
 			return errortab;
40
 	}
34
 	}

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

77
 	char value[256]; /* enough size for a DHCP string */
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
 static void load_setting ( struct setting_widget *widget ) __nonnull;
83
 static void load_setting ( struct setting_widget *widget ) __nonnull;
88
 static int save_setting ( struct setting_widget *widget ) __nonnull;
84
 static int save_setting ( struct setting_widget *widget ) __nonnull;
223
 static void init_setting_index ( struct setting_widget *widget,
219
 static void init_setting_index ( struct setting_widget *widget,
224
 				 struct settings *settings,
220
 				 struct settings *settings,
225
 				 unsigned int index ) {
221
 				 unsigned int index ) {
222
+	struct setting *all_settings =
223
+		table_start ( struct setting, SETTINGS );
224
+
226
 	init_setting ( widget, settings, &all_settings[index],
225
 	init_setting ( widget, settings, &all_settings[index],
227
 		       ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
226
 		       ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
228
 }
227
 }

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

85
 	int ( *iskey ) ( void );
85
 	int ( *iskey ) ( void );
86
 };
86
 };
87
 
87
 
88
+/** Console driver table */
89
+#define CONSOLES "consoles"
90
+
88
 /**
91
 /**
89
  * Mark a <tt> struct console_driver </tt> as being part of the
92
  * Mark a <tt> struct console_driver </tt> as being part of the
90
  * console drivers table.
93
  * console drivers table.
102
  * @endcode
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
 /* Function prototypes */
110
 /* Function prototypes */
108
 
111
 

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

26
 			  const void *net_addr );
26
 			  const void *net_addr );
27
 };
27
 };
28
 
28
 
29
+/** ARP protocol table */
30
+#define ARP_NET_PROTOCOLS "arp_net_protocols"
31
+
29
 /** Declare an ARP protocol */
32
 /** Declare an ARP protocol */
30
 #define __arp_net_protocol \
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
 extern struct net_protocol arp_protocol;
36
 extern struct net_protocol arp_protocol;
34
 
37
 

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

17
 	int ( * exec ) ( int argc, char **argv );
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
 #endif /* _GPXE_COMMAND_H */
24
 #endif /* _GPXE_COMMAND_H */

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

102
 	void ( * remove ) ( struct root_device *rootdev );
102
 	void ( * remove ) ( struct root_device *rootdev );
103
 };
103
 };
104
 
104
 
105
+/** Root device table */
106
+#define ROOT_DEVICES "root_devices"
107
+
105
 /** Declare a root device */
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
 #endif /* _GPXE_DEVICE_H */
111
 #endif /* _GPXE_DEVICE_H */

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

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

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

79
 	void ( * remove ) ( struct eisa_device *eisa );
79
 	void ( * remove ) ( struct eisa_device *eisa );
80
 };
80
 };
81
 
81
 
82
+/** EISA driver table */
83
+#define EISA_DRIVERS "eisa_drivers"
84
+
82
 /** Declare an EISA driver */
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
 extern void eisa_device_enabled ( struct eisa_device *eisa, int enabled );
88
 extern void eisa_device_enabled ( struct eisa_device *eisa, int enabled );
86
 
89
 

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

14
 	const char *text;
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
 #endif /* _GPXE_ERRORTAB_H */
21
 #endif /* _GPXE_ERRORTAB_H */

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

50
 
50
 
51
 /** @} */
51
 /** @} */
52
 
52
 
53
+/** DHCP feature table */
54
+#define DHCP_FEATURES "dhcp_features"
55
+
53
 /** Declare a feature code for DHCP */
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
 /** Construct a DHCP feature table entry */
59
 /** Construct a DHCP feature table entry */
57
 #define DHCP_FEATURE( feature_opt, ... )				    \
60
 #define DHCP_FEATURE( feature_opt, ... )				    \
69
 	char *name;
72
 	char *name;
70
 };
73
 };
71
 
74
 
75
+/** Named feature table */
76
+#define FEATURES "features"
77
+
72
 /** Declare a named feature */
78
 /** Declare a named feature */
73
 #define __feature_name( category )					    \
79
 #define __feature_name( category )					    \
74
-	__table ( struct feature, features, category )
80
+	__table ( struct feature, FEATURES, category )
75
 
81
 
76
 /** Construct a named feature */
82
 /** Construct a named feature */
77
 #define FEATURE_NAME( category, text )					    \
83
 #define FEATURE_NAME( category, text )					    \

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

45
 	void ( * send ) ( const char *buf, size_t len );
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
  * Look up GDB transport by name
53
  * Look up GDB transport by name

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

123
  */
123
  */
124
 #define PROBE_PXE 03
124
 #define PROBE_PXE 03
125
 
125
 
126
+/** Executable or loadable image type table */
127
+#define IMAGE_TYPES "image_types"
128
+
126
 /** An executable or loadable image type */
129
 /** An executable or loadable image type */
127
 #define __image_type( probe_order ) \
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
 extern struct list_head images;
133
 extern struct list_head images;
131
 
134
 

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

13
 	void ( * initialise ) ( void );
13
 	void ( * initialise ) ( void );
14
 };
14
 };
15
 
15
 
16
+/** Initialisation function table */
17
+#define INIT_FNS "init_fns"
18
+
16
 /** Declare an initialisation functon */
19
 /** Declare an initialisation functon */
17
 #define __init_fn( init_order ) \
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
 /** @defgroup initfn_order Initialisation function ordering
23
 /** @defgroup initfn_order Initialisation function ordering
21
  * @{
24
  * @{
49
 	void ( * shutdown ) ( int flags );
52
 	void ( * shutdown ) ( int flags );
50
 };
53
 };
51
 
54
 
55
+/** Startup/shutdown function table */
56
+#define STARTUP_FNS "startup_fns"
57
+
52
 /** Declare a startup/shutdown function */
58
 /** Declare a startup/shutdown function */
53
 #define __startup_fn( startup_order ) \
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
 /** @defgroup startfn_order Startup/shutdown function ordering
62
 /** @defgroup startfn_order Startup/shutdown function ordering
57
  *
63
  *

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

58
 	void ( * remove ) ( struct isa_device *isa );
58
 	void ( * remove ) ( struct isa_device *isa );
59
 };
59
 };
60
 
60
 
61
+/** ISA driver table */
62
+#define ISA_DRIVERS "isa_drivers"
63
+
61
 /** Declare an ISA driver */
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
  * Set ISA driver-private data
68
  * Set ISA driver-private data

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

223
 	void ( * remove ) ( struct isapnp_device *isapnp );
223
 	void ( * remove ) ( struct isapnp_device *isapnp );
224
 };
224
 };
225
 
225
 
226
+/** ISAPnP driver table */
227
+#define ISAPNP_DRIVERS "isapnp_drivers"
228
+
226
 /** Declare an ISAPnP driver */
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
 extern uint16_t isapnp_read_port;
232
 extern uint16_t isapnp_read_port;
230
 
233
 

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

77
 	void ( * remove ) ( struct mca_device *mca );
77
 	void ( * remove ) ( struct mca_device *mca );
78
 };
78
 };
79
 
79
 
80
+/** MCA driver table */
81
+#define MCA_DRIVERS "mca_drivers"
82
+
80
 /** Declare an MCA driver */
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
  * Set MCA driver-private data
87
  * Set MCA driver-private data

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

279
 /** Network device has link */
279
 /** Network device has link */
280
 #define NETDEV_LINK_UP 0x0002
280
 #define NETDEV_LINK_UP 0x0002
281
 
281
 
282
+/** Link-layer protocol table */
283
+#define LL_PROTOCOLS "ll_protocols"
284
+
282
 /** Declare a link-layer protocol */
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
 /** Declare a network-layer protocol */
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
 extern struct list_head net_devices;
294
 extern struct list_head net_devices;
289
 extern struct net_device_operations null_netdev_operations;
295
 extern struct net_device_operations null_netdev_operations;

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

58
 	int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
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
 /** Register a URI opener */
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
 /** A socket opener */
67
 /** A socket opener */
65
 struct socket_opener {
68
 struct socket_opener {
78
 			 struct sockaddr *local );
81
 			 struct sockaddr *local );
79
 };
82
 };
80
 
83
 
84
+/** Socket opener table */
85
+#define SOCKET_OPENERS "socket_openers"
86
+
81
 /** Register a socket opener */
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
 extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri );
90
 extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri );
85
 extern int xfer_open_uri_string ( struct xfer_interface *xfer,
91
 extern int xfer_open_uri_string ( struct xfer_interface *xfer,

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

308
 	void ( * remove ) ( struct pci_device *pci );
308
 	void ( * remove ) ( struct pci_device *pci );
309
 };
309
 };
310
 
310
 
311
+/** PCI driver table */
312
+#define PCI_DRIVERS "pci_drivers"
313
+
311
 /** Declare a PCI driver */
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
 #define PCI_DEVFN( slot, func )		( ( (slot) << 3 ) | (func) )
317
 #define PCI_DEVFN( slot, func )		( ( (slot) << 3 ) | (func) )
315
 #define PCI_SLOT( devfn )		( ( (devfn) >> 3 ) & 0x1f )
318
 #define PCI_SLOT( devfn )		( ( (devfn) >> 3 ) & 0x1f )

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

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

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

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

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

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

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

36
 	unsigned int tag;
36
 	unsigned int tag;
37
 };
37
 };
38
 
38
 
39
+/** Configuration setting table */
40
+#define SETTINGS "settings"
41
+
39
 /** Declare a configuration setting */
42
 /** Declare a configuration setting */
40
-#define	__setting __table ( struct setting, settings, 01 )
43
+#define	__setting __table ( struct setting, SETTINGS, 01 )
41
 
44
 
42
 /** Settings block operations */
45
 /** Settings block operations */
43
 struct settings_operations {
46
 struct settings_operations {
123
 			   char *buf, size_t len );
126
 			   char *buf, size_t len );
124
 };
127
 };
125
 
128
 
129
+/** Configuration setting type table */
130
+#define SETTING_TYPES "setting_types"
131
+
126
 /** Declare a configuration setting type */
132
 /** Declare a configuration setting type */
127
 #define	__setting_type \
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
  * A settings applicator
137
  * A settings applicator
139
 	int ( * apply ) ( void );
145
 	int ( * apply ) ( void );
140
 };
146
 };
141
 
147
 
148
+/** Settings applicator table */
149
+#define SETTINGS_APPLICATORS "settings_applicators"
150
+
142
 /** Declare a settings applicator */
151
 /** Declare a settings applicator */
143
 #define __settings_applicator \
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
  * A simple settings block
156
  * A simple settings block

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

115
  *	void ( *frob ) ( void ); 	// The frobnicating function itself
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
  * @endcode
120
  * @endcode
121
  *
121
  *
145
  *
145
  *
146
  *   #include "frob.h"
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
  *   // Call all linked-in frobnicators
148
  *   // Call all linked-in frobnicators
152
  *   void frob_all ( void ) {
149
  *   void frob_all ( void ) {
153
  *	struct frob *frob;
150
  *	struct frob *frob;
154
  *
151
  *
155
- *      for ( frob = frob_start ; frob < frob_end ; frob++ ) {
152
+ *	for_each_table ( frob, "frobnicators" ) {
156
  *         printf ( "Calling frobnicator \"%s\"\n", frob->name );
153
  *         printf ( "Calling frobnicator \"%s\"\n", frob->name );
157
  *	   frob->frob ();
154
  *	   frob->frob ();
158
  *	}
155
  *	}
170
 
167
 
171
 #define __table_str( x ) #x
168
 #define __table_str( x ) #x
172
 #define __table_section( table, idx ) \
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
 #define __table_section_start( table ) __table_section ( table, 00 )
172
 #define __table_section_start( table ) __table_section ( table, 00 )
176
 #define __table_section_end( table ) __table_section ( table, 99 )
173
 #define __table_section_end( table ) __table_section ( table, 99 )
185
  *
182
  *
186
  * @code
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
  * @endcode
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
 			 __natural_alignment ( type ) ))
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
  * @code
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
  * @endcode
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
  * @code
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
  * @endcode
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
 #endif /* _GPXE_TABLES_H */
291
 #endif /* _GPXE_TABLES_H */

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

98
 		       uint16_t *trans_csum );
98
 		       uint16_t *trans_csum );
99
 };
99
 };
100
 
100
 
101
+/** TCP/IP transport-layer protocol table */
102
+#define TCPIP_PROTOCOLS "tcpip_protocols"
103
+
101
 /** Declare a TCP/IP transport-layer protocol */
104
 /** Declare a TCP/IP transport-layer protocol */
102
 #define	__tcpip_protocol \
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
 /** Declare a TCP/IP network-layer protocol */
111
 /** Declare a TCP/IP network-layer protocol */
106
 #define	__tcpip_net_protocol \
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
 extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
115
 extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
110
 		      struct sockaddr_tcpip *st_src,
116
 		      struct sockaddr_tcpip *st_src,

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

26
 /** System table passed to entry point */
26
 /** System table passed to entry point */
27
 EFI_SYSTEM_TABLE *efi_systab;
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
  * Look up EFI configuration table
30
  * Look up EFI configuration table
43
  *
31
  *
92
 
80
 
93
 	/* Look up used protocols */
81
 	/* Look up used protocols */
94
 	bs = systab->BootServices;
82
 	bs = systab->BootServices;
95
-	for ( prot = efi_protocols ; prot < efi_protocols_end ; prot++ ) {
83
+	for_each_table_entry ( prot, EFI_PROTOCOLS ) {
96
 		if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL,
84
 		if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL,
97
 						    prot->protocol ) ) == 0 ) {
85
 						    prot->protocol ) ) == 0 ) {
98
 			DBGC ( systab, "EFI protocol %s is at %p\n",
86
 			DBGC ( systab, "EFI protocol %s is at %p\n",
106
 	}
94
 	}
107
 
95
 
108
 	/* Look up used configuration tables */
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
 		if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) {
98
 		if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) {
111
 			DBGC ( systab, "EFI configuration table %s is at %p\n",
99
 			DBGC ( systab, "EFI configuration table %s is at %p\n",
112
 			       uuid_ntoa ( &tab->u.uuid ), *(tab->table) );
100
 			       uuid_ntoa ( &tab->u.uuid ), *(tab->table) );

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

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
 /** An ARP cache entry */
39
 /** An ARP cache entry */
46
 struct arp_entry {
40
 struct arp_entry {
47
 	/** Network-layer protocol */
41
 	/** Network-layer protocol */
176
 static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) {
170
 static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) {
177
 	struct arp_net_protocol *arp_net_protocol;
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
 		if ( arp_net_protocol->net_protocol->net_proto == net_proto ) {
174
 		if ( arp_net_protocol->net_protocol->net_proto == net_proto ) {
182
 			return arp_net_protocol;
175
 			return arp_net_protocol;
183
 		}
176
 		}

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

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
 /** List of network devices */
39
 /** List of network devices */
46
 struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
40
 struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
47
 
41
 
538
 	struct net_protocol *net_protocol;
532
 	struct net_protocol *net_protocol;
539
 
533
 
540
 	/* Hand off to network-layer protocol, if any */
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
 		if ( net_protocol->net_proto == net_proto ) {
536
 		if ( net_protocol->net_proto == net_proto ) {
544
 			return net_protocol->rx ( iobuf, netdev, ll_source );
537
 			return net_protocol->rx ( iobuf, netdev, ll_source );
545
 		}
538
 		}

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

14
  * TCP/IP transport-network layer interface
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
 /** Process a received TCP/IP packet
17
 /** Process a received TCP/IP packet
30
  *
18
  *
31
  * @v iobuf		I/O buffer
19
  * @v iobuf		I/O buffer
48
 	struct tcpip_protocol *tcpip;
36
 	struct tcpip_protocol *tcpip;
49
 
37
 
50
 	/* Hand off packet to the appropriate transport-layer protocol */
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
 		if ( tcpip->tcpip_proto == tcpip_proto ) {
40
 		if ( tcpip->tcpip_proto == tcpip_proto ) {
53
 			DBG ( "TCP/IP received %s packet\n", tcpip->name );
41
 			DBG ( "TCP/IP received %s packet\n", tcpip->name );
54
 			return tcpip->rx ( iobuf, st_src, st_dest, pshdr_csum );
42
 			return tcpip->rx ( iobuf, st_src, st_dest, pshdr_csum );
76
 	struct tcpip_net_protocol *tcpip_net;
64
 	struct tcpip_net_protocol *tcpip_net;
77
 
65
 
78
 	/* Hand off packet to the appropriate network-layer protocol */
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
 		if ( tcpip_net->sa_family == st_dest->st_family ) {
68
 		if ( tcpip_net->sa_family == st_dest->st_family ) {
82
 			DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
69
 			DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
83
 			return tcpip_net->tx ( iobuf, tcpip_protocol, st_src,
70
 			return tcpip_net->tx ( iobuf, tcpip_protocol, st_src,

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

88
 	DHCP_END
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
 /** Version number feature */
91
 /** Version number feature */
96
 FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
92
 FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
97
 
93
 
884
 	struct dhcp_netdev_desc dhcp_desc;
880
 	struct dhcp_netdev_desc dhcp_desc;
885
 	struct dhcp_client_id client_id;
881
 	struct dhcp_client_id client_id;
886
 	struct dhcp_client_uuid client_uuid;
882
 	struct dhcp_client_uuid client_uuid;
883
+	uint8_t *dhcp_features;
887
 	size_t dhcp_features_len;
884
 	size_t dhcp_features_len;
888
 	size_t ll_addr_len;
885
 	size_t ll_addr_len;
889
 	ssize_t len;
886
 	ssize_t len;
903
 	dhcppkt->dhcphdr->ciaddr = ciaddr;
900
 	dhcppkt->dhcphdr->ciaddr = ciaddr;
904
 
901
 
905
 	/* Add options to identify the feature list */
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
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
905
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
908
 				    dhcp_features_len ) ) != 0 ) {
906
 				    dhcp_features_len ) ) != 0 ) {
909
 		DBG ( "DHCP could not set features list option: %s\n",
907
 		DBG ( "DHCP could not set features list option: %s\n",

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

43
 /** Shutdown flags for exit */
43
 /** Shutdown flags for exit */
44
 int shutdown_exit_flags = 0;
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
  * Identify the boot network device
47
  * Identify the boot network device
54
  *
48
  *
124
 	struct sanboot_protocol *sanboot;
118
 	struct sanboot_protocol *sanboot;
125
 
119
 
126
 	/* Quick hack */
120
 	/* Quick hack */
127
-	for ( sanboot = sanboot_protocols ;
128
-	      sanboot < sanboot_protocols_end ; sanboot++ ) {
121
+	for_each_table_entry ( sanboot, SANBOOT_PROTOCOLS ) {
129
 		if ( strncmp ( root_path, sanboot->prefix,
122
 		if ( strncmp ( root_path, sanboot->prefix,
130
 			       strlen ( sanboot->prefix ) ) == 0 ) {
123
 			       strlen ( sanboot->prefix ) ) == 0 ) {
131
 			return sanboot->boot ( root_path );
124
 			return sanboot->boot ( root_path );

Loading…
Cancel
Save