diff --git a/src/core/console.c b/src/core/console.c index c9773f71..1ea3dc13 100644 --- a/src/core/console.c +++ b/src/core/console.c @@ -5,11 +5,6 @@ /** @file */ -static struct console_driver console_drivers[0] - __table_start ( struct console_driver, console ); -static struct console_driver console_drivers_end[0] - __table_end ( struct console_driver, console ); - /** * Write a single character to each console device. * @@ -28,8 +23,7 @@ void putchar ( int character ) { if ( character == '\n' ) putchar ( '\r' ); - for ( console = console_drivers; console < console_drivers_end ; - console++ ) { + for_each_table_entry ( console, CONSOLES ) { if ( ( ! console->disabled ) && console->putchar ) console->putchar ( character ); } @@ -51,8 +45,7 @@ void putchar ( int character ) { static struct console_driver * has_input ( void ) { struct console_driver *console; - for ( console = console_drivers; console < console_drivers_end ; - console++ ) { + for_each_table_entry ( console, CONSOLES ) { if ( ( ! console->disabled ) && console->iskey ) { if ( console->iskey () ) return console; diff --git a/src/core/device.c b/src/core/device.c index 84915c2d..1f57e4c6 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -29,11 +29,6 @@ * */ -static struct root_device root_devices[0] - __table_start ( struct root_device, root_devices ); -static struct root_device root_devices_end[0] - __table_end ( struct root_device, root_devices ); - /** Registered root devices */ static LIST_HEAD ( devices ); @@ -77,7 +72,7 @@ static void probe_devices ( void ) { struct root_device *rootdev; int rc; - for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) { + for_each_table_entry ( rootdev, ROOT_DEVICES ) { list_add ( &rootdev->dev.siblings, &devices ); INIT_LIST_HEAD ( &rootdev->dev.children ); if ( ( rc = rootdev_probe ( rootdev ) ) != 0 ) diff --git a/src/core/exec.c b/src/core/exec.c index a9861b60..181ca4c5 100644 --- a/src/core/exec.c +++ b/src/core/exec.c @@ -34,11 +34,6 @@ * */ -static struct command commands[0] - __table_start ( struct command, commands ); -static struct command commands_end[0] - __table_end ( struct command, commands ); - /* Avoid dragging in getopt.o unless a command really uses it */ int optind; int nextchar; @@ -78,7 +73,7 @@ int execv ( const char *command, char * const argv[] ) { reset_getopt(); /* Hand off to command implementation */ - for ( cmd = commands ; cmd < commands_end ; cmd++ ) { + for_each_table_entry ( cmd, COMMANDS ) { if ( strcmp ( command, cmd->name ) == 0 ) return cmd->exec ( argc, ( char ** ) argv ); } diff --git a/src/core/gdbstub.c b/src/core/gdbstub.c index bbed344f..45df7f2b 100644 --- a/src/core/gdbstub.c +++ b/src/core/gdbstub.c @@ -54,10 +54,6 @@ struct gdbstub { int len; /* length of payload */ }; -/* Transports */ -static struct gdb_transport gdb_transport_start[0] __table_start ( struct gdb_transport, gdb_transports ); -static struct gdb_transport gdb_transport_end[0] __table_end ( struct gdb_transport, gdb_transports ); - /* Packet parser states */ static void gdbstub_state_new ( struct gdbstub *stub, char ch ); static void gdbstub_state_data ( struct gdbstub *stub, char ch ); @@ -387,7 +383,8 @@ void gdbstub_handler ( int signo, gdbreg_t *regs ) { struct gdb_transport *find_gdb_transport ( const char *name ) { struct gdb_transport *trans; - for ( trans = gdb_transport_start; trans < gdb_transport_end; trans++ ) { + + for_each_table_entry ( trans, GDB_TRANSPORTS ) { if ( strcmp ( trans->name, name ) == 0 ) { return trans; } diff --git a/src/core/image.c b/src/core/image.c index 277d09a9..0d188c30 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -37,12 +37,6 @@ /** List of registered images */ struct list_head images = LIST_HEAD_INIT ( images ); -/** List of image types */ -static struct image_type image_types[0] - __table_start ( struct image_type, image_types ); -static struct image_type image_types_end[0] - __table_end ( struct image_type, image_types ); - /** * Free executable/loadable image * @@ -219,7 +213,7 @@ int image_autoload ( struct image *image ) { return image_load ( image ); /* Otherwise probe for a suitable type */ - for ( type = image_types ; type < image_types_end ; type++ ) { + for_each_table_entry ( type, IMAGE_TYPES ) { DBGC ( image, "IMAGE %p trying type %s\n", image, type->name ); rc = image_load_type ( image, type ); if ( image->type == NULL ) diff --git a/src/core/init.c b/src/core/init.c index 50e199ce..e1c9dce0 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -25,18 +25,6 @@ * */ -/** Registered initialisation functions */ -static struct init_fn init_fns[0] - __table_start ( struct init_fn, init_fns ); -static struct init_fn init_fns_end[0] - __table_end ( struct init_fn, init_fns ); - -/** Registered startup/shutdown functions */ -static struct startup_fn startup_fns[0] - __table_start ( struct startup_fn, startup_fns ); -static struct startup_fn startup_fns_end[0] - __table_end ( struct startup_fn, startup_fns ); - /** "startup() has been called" flag */ static int started = 0; @@ -54,9 +42,8 @@ void initialise ( void ) { struct init_fn *init_fn; /* Call registered initialisation functions */ - for ( init_fn = init_fns ; init_fn < init_fns_end ; init_fn++ ) { + for_each_table_entry ( init_fn, INIT_FNS ) init_fn->initialise (); - } } /** @@ -73,8 +60,7 @@ void startup ( void ) { return; /* Call registered startup functions */ - for ( startup_fn = startup_fns ; startup_fn < startup_fns_end ; - startup_fn++ ) { + for_each_table_entry ( startup_fn, STARTUP_FNS ) { if ( startup_fn->startup ) startup_fn->startup(); } @@ -90,7 +76,7 @@ void startup ( void ) { * This function reverses the actions of startup(), and leaves gPXE in * a state ready to be removed from memory. You may call startup() * again after calling shutdown(). - + * * Call this function only once, before either exiting main() or * starting up a non-returnable image. */ @@ -101,8 +87,7 @@ void shutdown ( int flags ) { return; /* Call registered shutdown functions (in reverse order) */ - for ( startup_fn = startup_fns_end - 1 ; startup_fn >= startup_fns ; - startup_fn-- ) { + for_each_table_entry_reverse ( startup_fn, STARTUP_FNS ) { if ( startup_fn->shutdown ) startup_fn->shutdown ( flags ); } diff --git a/src/core/main.c b/src/core/main.c index bd2428f0..809d4dcf 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -27,9 +27,6 @@ Literature dealing with the network protocols: #define BOLD "\033[1m" #define CYAN "\033[36m" -static struct feature features[0] __table_start ( struct feature, features ); -static struct feature features_end[0] __table_end ( struct feature, features ); - /** * Main entry point * @@ -61,7 +58,7 @@ __asmcall int main ( void ) { NORMAL " -- Open Source Boot Firmware -- " CYAN "http://etherboot.org" NORMAL "\n" "Features:" ); - for ( feature = features ; feature < features_end ; feature++ ) + for_each_table_entry ( feature, FEATURES ) printf ( " %s", feature->name ); printf ( "\n" ); diff --git a/src/core/open.c b/src/core/open.c index db8d92e6..89a96d72 100644 --- a/src/core/open.c +++ b/src/core/open.c @@ -30,18 +30,6 @@ * */ -/** Registered URI openers */ -static struct uri_opener uri_openers[0] - __table_start ( struct uri_opener, uri_openers ); -static struct uri_opener uri_openers_end[0] - __table_end ( struct uri_opener, uri_openers ); - -/** Registered socket openers */ -static struct socket_opener socket_openers[0] - __table_start ( struct socket_opener, socket_openers ); -static struct socket_opener socket_openers_end[0] - __table_end ( struct socket_opener, socket_openers ); - /** * Open URI * @@ -63,7 +51,7 @@ int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ) { return -ENOMEM; /* Find opener which supports this URI scheme */ - for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) { + for_each_table_entry ( opener, URI_OPENERS ) { if ( strcmp ( resolved_uri->scheme, opener->scheme ) == 0 ) { rc = opener->open ( xfer, resolved_uri ); goto done; @@ -121,7 +109,7 @@ int xfer_open_socket ( struct xfer_interface *xfer, int semantics, socket_semantics_name ( semantics ), socket_family_name ( peer->sa_family ) ); - for ( opener = socket_openers; opener < socket_openers_end; opener++ ){ + for_each_table_entry ( opener, SOCKET_OPENERS ) { if ( ( opener->semantics == semantics ) && ( opener->family == peer->sa_family ) ) { return opener->open ( xfer, peer, local ); diff --git a/src/core/process.c b/src/core/process.c index 6a687140..dcae9017 100644 --- a/src/core/process.c +++ b/src/core/process.c @@ -31,12 +31,6 @@ /** Process run queue */ static LIST_HEAD ( run_queue ); -/** Registered permanent processes */ -static struct process processes[0] - __table_start ( struct process, processes ); -static struct process processes_end[0] - __table_end ( struct process, processes ); - /** * Add process to process list * @@ -93,9 +87,8 @@ void step ( void ) { static void init_processes ( void ) { struct process *process; - for ( process = processes ; process < processes_end ; process++ ) { + for_each_table_entry ( process, PERMANENT_PROCESSES ) process_add ( process ); - } } /** Process initialiser */ diff --git a/src/core/resolv.c b/src/core/resolv.c index f4a587f1..667f2ded 100644 --- a/src/core/resolv.c +++ b/src/core/resolv.c @@ -150,12 +150,6 @@ struct resolver numeric_resolver __resolver ( RESOLV_NUMERIC ) = { *************************************************************************** */ -/** Registered name resolvers */ -static struct resolver resolvers[0] - __table_start ( struct resolver, resolvers ); -static struct resolver resolvers_end[0] - __table_end ( struct resolver, resolvers ); - /** A name resolution multiplexer */ struct resolv_mux { /** Reference counter */ @@ -223,7 +217,7 @@ static void resolv_mux_done ( struct resolv_interface *resolv, /* Attempt next child resolver, if possible */ mux->resolver++; - if ( mux->resolver >= resolvers_end ) { + if ( mux->resolver >= table_end ( struct resolver, RESOLVERS ) ) { DBGC ( mux, "RESOLV %p failed to resolve name\n", mux ); goto finished; } @@ -262,7 +256,7 @@ int resolv ( struct resolv_interface *resolv, const char *name, return -ENOMEM; resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt ); resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt ); - mux->resolver = resolvers; + mux->resolver = table_start ( struct resolver, RESOLVERS ); memcpy ( &mux->sa, sa, sizeof ( mux->sa ) ); memcpy ( mux->name, name, name_len ); diff --git a/src/core/settings.c b/src/core/settings.c index bb5a382b..55f96383 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -37,24 +37,6 @@ * */ -/** Registered settings */ -static struct setting settings[0] - __table_start ( struct setting, settings ); -static struct setting settings_end[0] - __table_end ( struct setting, settings ); - -/** Registered setting types */ -static struct setting_type setting_types[0] - __table_start ( struct setting_type, setting_types ); -static struct setting_type setting_types_end[0] - __table_end ( struct setting_type, setting_types ); - -/** Registered settings applicators */ -static struct settings_applicator settings_applicators[0] - __table_start ( struct settings_applicator, settings_applicators ); -static struct settings_applicator settings_applicators_end[0] - __table_end ( struct settings_applicator, settings_applicators ); - /****************************************************************************** * * Registered settings blocks @@ -229,8 +211,7 @@ static int apply_settings ( void ) { int rc; /* Call all settings applicators */ - for ( applicator = settings_applicators ; - applicator < settings_applicators_end ; applicator++ ) { + for_each_table_entry ( applicator, SETTINGS_APPLICATORS ) { if ( ( rc = applicator->apply() ) != 0 ) { DBG ( "Could not apply settings using applicator " "%p: %s\n", applicator, strerror ( rc ) ); @@ -670,7 +651,7 @@ int storef_setting ( struct settings *settings, struct setting *setting, static struct setting * find_setting ( const char *name ) { struct setting *setting; - for ( setting = settings ; setting < settings_end ; setting++ ) { + for_each_table_entry ( setting, SETTINGS ) { if ( strcmp ( name, setting->name ) == 0 ) return setting; } @@ -686,7 +667,7 @@ static struct setting * find_setting ( const char *name ) { static struct setting_type * find_setting_type ( const char *name ) { struct setting_type *type; - for ( type = setting_types ; type < setting_types_end ; type++ ) { + for_each_table_entry ( type, SETTING_TYPES ) { if ( strcmp ( name, type->name ) == 0 ) return type; } diff --git a/src/drivers/bus/eisa.c b/src/drivers/bus/eisa.c index d9e42359..1af56f2e 100644 --- a/src/drivers/bus/eisa.c +++ b/src/drivers/bus/eisa.c @@ -7,11 +7,6 @@ #include #include -static struct eisa_driver eisa_drivers[0] - __table_start ( struct eisa_driver, eisa_drivers ); -static struct eisa_driver eisa_drivers_end[0] - __table_end ( struct eisa_driver, eisa_drivers ); - static void eisabus_remove ( struct root_device *rootdev ); /** @@ -57,7 +52,7 @@ static int eisa_probe ( struct eisa_device *eisa ) { eisa->slot, eisa->vendor_id, eisa->prod_id, isa_id_string ( eisa->vendor_id, eisa->prod_id ), eisa->ioaddr ); - for ( driver = eisa_drivers; driver < eisa_drivers_end; driver++ ) { + for_each_table_entry ( driver, EISA_DRIVERS ) { for ( i = 0 ; i < driver->id_count ; i++ ) { id = &driver->ids[i]; if ( id->vendor_id != eisa->vendor_id ) diff --git a/src/drivers/bus/isa.c b/src/drivers/bus/isa.c index fa5def54..eb49fbf2 100644 --- a/src/drivers/bus/isa.c +++ b/src/drivers/bus/isa.c @@ -48,11 +48,6 @@ static isa_probe_addr_t isa_extra_probe_addrs[] = { isa_extra_probe_addrs[ (ioidx) + ISA_EXTRA_PROBE_ADDR_COUNT ] : \ (driver)->probe_addrs[(ioidx)] ) -static struct isa_driver isa_drivers[0] - __table_start ( struct isa_driver, isa_drivers ); -static struct isa_driver isa_drivers_end[0] - __table_end ( struct isa_driver, isa_drivers ); - static void isabus_remove ( struct root_device *rootdev ); /** @@ -100,7 +95,7 @@ static int isabus_probe ( struct root_device *rootdev ) { int ioidx; int rc; - for ( driver = isa_drivers ; driver < isa_drivers_end ; driver++ ) { + for_each_table_entry ( driver, ISA_DRIVERS ) { for ( ioidx = ISA_IOIDX_MIN ( driver ) ; ioidx <= ISA_IOIDX_MAX ( driver ) ; ioidx++ ) { /* Allocate struct isa_device */ diff --git a/src/drivers/bus/isapnp.c b/src/drivers/bus/isapnp.c index 8f812df8..957a955b 100644 --- a/src/drivers/bus/isapnp.c +++ b/src/drivers/bus/isapnp.c @@ -72,11 +72,6 @@ */ uint16_t isapnp_read_port; -static struct isapnp_driver isapnp_drivers[0] - __table_start ( struct isapnp_driver, isapnp_drivers ); -static struct isapnp_driver isapnp_drivers_end[0] - __table_end ( struct isapnp_driver, isapnp_drivers ); - static void isapnpbus_remove ( struct root_device *rootdev ); /* @@ -594,7 +589,7 @@ static int isapnp_probe ( struct isapnp_device *isapnp ) { isa_id_string ( isapnp->vendor_id, isapnp->prod_id ), isapnp->ioaddr, isapnp->irqno ); - for ( driver = isapnp_drivers; driver < isapnp_drivers_end; driver++ ){ + for_each_table_entry ( driver, ISAPNP_DRIVERS ) { for ( i = 0 ; i < driver->id_count ; i++ ) { id = &driver->ids[i]; if ( id->vendor_id != isapnp->vendor_id ) diff --git a/src/drivers/bus/mca.c b/src/drivers/bus/mca.c index e9233813..d6bb60f2 100644 --- a/src/drivers/bus/mca.c +++ b/src/drivers/bus/mca.c @@ -13,11 +13,6 @@ #include #include -static struct mca_driver mca_drivers[0] - __table_start ( struct mca_driver, mca_drivers ); -static struct mca_driver mca_drivers_end[0] - __table_end ( struct mca_driver, mca_drivers ); - static void mcabus_remove ( struct root_device *rootdev ); /** @@ -41,7 +36,7 @@ static int mca_probe ( struct mca_device *mca ) { mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3], mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] ); - for ( driver = mca_drivers; driver < mca_drivers_end; driver++ ){ + for_each_table_entry ( driver, MCA_DRIVERS ) { for ( i = 0 ; i < driver->id_count ; i++ ) { id = &driver->ids[i]; if ( id->id != MCA_ID ( mca ) ) diff --git a/src/drivers/bus/pci.c b/src/drivers/bus/pci.c index 2dc9d43a..7f038c2b 100644 --- a/src/drivers/bus/pci.c +++ b/src/drivers/bus/pci.c @@ -34,11 +34,6 @@ * */ -static struct pci_driver pci_drivers[0] - __table_start ( struct pci_driver, pci_drivers ); -static struct pci_driver pci_drivers_end[0] - __table_end ( struct pci_driver, pci_drivers ); - static void pcibus_remove ( struct root_device *rootdev ); /** @@ -188,7 +183,7 @@ static int pci_probe ( struct pci_device *pci ) { PCI_FUNC ( pci->devfn ), pci->vendor, pci->device, pci->membase, pci->ioaddr, pci->irq ); - for ( driver = pci_drivers ; driver < pci_drivers_end ; driver++ ) { + for_each_table_entry ( driver, PCI_DRIVERS ) { for ( i = 0 ; i < driver->id_count ; i++ ) { id = &driver->ids[i]; if ( ( id->vendor != PCI_ANY_ID ) && diff --git a/src/hci/shell.c b/src/hci/shell.c index 18b1068e..74787e3c 100644 --- a/src/hci/shell.c +++ b/src/hci/shell.c @@ -29,11 +29,6 @@ * */ -static struct command commands[0] - __table_start ( struct command, commands ); -static struct command commands_end[0] - __table_end ( struct command, commands ); - /** The shell prompt string */ static const char shell_prompt[] = "gPXE> "; @@ -65,7 +60,7 @@ static int help_exec ( int argc __unused, char **argv __unused ) { unsigned int hpos = 0; printf ( "\nAvailable commands:\n\n" ); - for ( command = commands ; command < commands_end ; command++ ) { + for_each_table_entry ( command, COMMANDS ) { hpos += printf ( " %s", command->name ); if ( hpos > ( 16 * 4 ) ) { printf ( "\n" ); diff --git a/src/hci/strerror.c b/src/hci/strerror.c index 74995e8b..30532b39 100644 --- a/src/hci/strerror.c +++ b/src/hci/strerror.c @@ -18,11 +18,6 @@ * */ -static struct errortab errortab_start[0] - __table_start ( struct errortab, errortab ); -static struct errortab errortab_end[0] - __table_end ( struct errortab, errortab ); - /** * Find error description * @@ -33,8 +28,7 @@ static struct errortab errortab_end[0] static struct errortab * find_error ( int errno, int mask ) { struct errortab *errortab; - for ( errortab = errortab_start ; errortab < errortab_end ; - errortab++ ) { + for_each_table_entry ( errortab, ERRORTAB ) { if ( ( ( errortab->errno ^ errno ) & mask ) == 0 ) return errortab; } diff --git a/src/hci/tui/settings_ui.c b/src/hci/tui/settings_ui.c index 4ab38270..61f94cde 100644 --- a/src/hci/tui/settings_ui.c +++ b/src/hci/tui/settings_ui.c @@ -77,12 +77,8 @@ struct setting_widget { char value[256]; /* enough size for a DHCP string */ }; -/** Registered configuration settings */ -static struct setting all_settings[0] - __table_start ( struct setting, settings ); -static struct setting all_settings_end[0] - __table_end ( struct setting, settings ); -#define NUM_SETTINGS ( ( unsigned ) ( all_settings_end - all_settings ) ) +/** Number of registered configuration settings */ +#define NUM_SETTINGS table_num_entries ( struct setting, SETTINGS ) static void load_setting ( struct setting_widget *widget ) __nonnull; static int save_setting ( struct setting_widget *widget ) __nonnull; @@ -223,6 +219,9 @@ static int edit_setting ( struct setting_widget *widget, int key ) { static void init_setting_index ( struct setting_widget *widget, struct settings *settings, unsigned int index ) { + struct setting *all_settings = + table_start ( struct setting, SETTINGS ); + init_setting ( widget, settings, &all_settings[index], ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL ); } diff --git a/src/include/console.h b/src/include/console.h index 9addd526..fd36cd5b 100644 --- a/src/include/console.h +++ b/src/include/console.h @@ -85,6 +85,9 @@ struct console_driver { int ( *iskey ) ( void ); }; +/** Console driver table */ +#define CONSOLES "consoles" + /** * Mark a struct console_driver as being part of the * console drivers table. @@ -102,7 +105,7 @@ struct console_driver { * @endcode * */ -#define __console_driver __table ( struct console_driver, console, 01 ) +#define __console_driver __table ( struct console_driver, CONSOLES, 01 ) /* Function prototypes */ diff --git a/src/include/gpxe/arp.h b/src/include/gpxe/arp.h index 6464ce0c..5bdd1d56 100644 --- a/src/include/gpxe/arp.h +++ b/src/include/gpxe/arp.h @@ -26,9 +26,12 @@ struct arp_net_protocol { const void *net_addr ); }; +/** ARP protocol table */ +#define ARP_NET_PROTOCOLS "arp_net_protocols" + /** Declare an ARP protocol */ #define __arp_net_protocol \ - __table ( struct arp_net_protocol, arp_net_protocols, 01 ) + __table ( struct arp_net_protocol, ARP_NET_PROTOCOLS, 01 ) extern struct net_protocol arp_protocol; diff --git a/src/include/gpxe/command.h b/src/include/gpxe/command.h index 5d8057ab..ee270dfd 100644 --- a/src/include/gpxe/command.h +++ b/src/include/gpxe/command.h @@ -17,6 +17,8 @@ struct command { int ( * exec ) ( int argc, char **argv ); }; -#define __command __table ( struct command, commands, 01 ) +#define COMMANDS "commands" + +#define __command __table ( struct command, COMMANDS, 01 ) #endif /* _GPXE_COMMAND_H */ diff --git a/src/include/gpxe/device.h b/src/include/gpxe/device.h index f40cc95a..bcc848aa 100644 --- a/src/include/gpxe/device.h +++ b/src/include/gpxe/device.h @@ -102,7 +102,10 @@ struct root_driver { void ( * remove ) ( struct root_device *rootdev ); }; +/** Root device table */ +#define ROOT_DEVICES "root_devices" + /** Declare a root device */ -#define __root_device __table ( struct root_device, root_devices, 01 ) +#define __root_device __table ( struct root_device, ROOT_DEVICES, 01 ) #endif /* _GPXE_DEVICE_H */ diff --git a/src/include/gpxe/efi/efi.h b/src/include/gpxe/efi/efi.h index c7f63b6c..c44e09cb 100644 --- a/src/include/gpxe/efi/efi.h +++ b/src/include/gpxe/efi/efi.h @@ -54,9 +54,12 @@ struct efi_protocol { void **protocol; }; +/** EFI protocol table */ +#define EFI_PROTOCOLS "efi_protocols" + /** Declare an EFI protocol used by gPXE */ #define __efi_protocol \ - __table ( struct efi_protocol, efi_protocols, 01 ) + __table ( struct efi_protocol, EFI_PROTOCOLS, 01 ) /** Declare an EFI protocol to be required by gPXE * @@ -86,9 +89,12 @@ struct efi_config_table { int required; }; +/** EFI configuration table table */ +#define EFI_CONFIG_TABLES "efi_config_tables" + /** Declare an EFI configuration table used by gPXE */ #define __efi_config_table \ - __table ( struct efi_config_table, efi_config_tables, 01 ) + __table ( struct efi_config_table, EFI_CONFIG_TABLES, 01 ) /** Declare an EFI configuration table to be used by gPXE * diff --git a/src/include/gpxe/eisa.h b/src/include/gpxe/eisa.h index e9d890e1..1f3a9caa 100644 --- a/src/include/gpxe/eisa.h +++ b/src/include/gpxe/eisa.h @@ -79,8 +79,11 @@ struct eisa_driver { void ( * remove ) ( struct eisa_device *eisa ); }; +/** EISA driver table */ +#define EISA_DRIVERS "eisa_drivers" + /** Declare an EISA driver */ -#define __eisa_driver __table ( struct eisa_driver, eisa_drivers, 01 ) +#define __eisa_driver __table ( struct eisa_driver, EISA_DRIVERS, 01 ) extern void eisa_device_enabled ( struct eisa_device *eisa, int enabled ); diff --git a/src/include/gpxe/errortab.h b/src/include/gpxe/errortab.h index e9a56768..8e746f02 100644 --- a/src/include/gpxe/errortab.h +++ b/src/include/gpxe/errortab.h @@ -14,6 +14,8 @@ struct errortab { const char *text; }; -#define __errortab __table ( struct errortab, errortab, 01 ) +#define ERRORTAB "errortab" + +#define __errortab __table ( struct errortab, ERRORTAB, 01 ) #endif /* _GPXE_ERRORTAB_H */ diff --git a/src/include/gpxe/features.h b/src/include/gpxe/features.h index 32c31694..e979ee7c 100644 --- a/src/include/gpxe/features.h +++ b/src/include/gpxe/features.h @@ -50,8 +50,11 @@ /** @} */ +/** DHCP feature table */ +#define DHCP_FEATURES "dhcp_features" + /** Declare a feature code for DHCP */ -#define __dhcp_feature __table ( uint8_t, dhcp_features, 01 ) +#define __dhcp_feature __table ( uint8_t, DHCP_FEATURES, 01 ) /** Construct a DHCP feature table entry */ #define DHCP_FEATURE( feature_opt, ... ) \ @@ -69,9 +72,12 @@ struct feature { char *name; }; +/** Named feature table */ +#define FEATURES "features" + /** Declare a named feature */ #define __feature_name( category ) \ - __table ( struct feature, features, category ) + __table ( struct feature, FEATURES, category ) /** Construct a named feature */ #define FEATURE_NAME( category, text ) \ diff --git a/src/include/gpxe/gdbstub.h b/src/include/gpxe/gdbstub.h index bf5d24d2..624b15f7 100644 --- a/src/include/gpxe/gdbstub.h +++ b/src/include/gpxe/gdbstub.h @@ -45,7 +45,9 @@ struct gdb_transport { void ( * send ) ( const char *buf, size_t len ); }; -#define __gdb_transport __table ( struct gdb_transport, gdb_transports, 01 ) +#define GDB_TRANSPORTS "gdb_transports" + +#define __gdb_transport __table ( struct gdb_transport, GDB_TRANSPORTS, 01 ) /** * Look up GDB transport by name diff --git a/src/include/gpxe/image.h b/src/include/gpxe/image.h index b953e150..cb3bb361 100644 --- a/src/include/gpxe/image.h +++ b/src/include/gpxe/image.h @@ -123,9 +123,12 @@ struct image_type { */ #define PROBE_PXE 03 +/** Executable or loadable image type table */ +#define IMAGE_TYPES "image_types" + /** An executable or loadable image type */ #define __image_type( probe_order ) \ - __table ( struct image_type, image_types, probe_order ) + __table ( struct image_type, IMAGE_TYPES, probe_order ) extern struct list_head images; diff --git a/src/include/gpxe/init.h b/src/include/gpxe/init.h index e0e9f9c8..9ce56d77 100644 --- a/src/include/gpxe/init.h +++ b/src/include/gpxe/init.h @@ -13,9 +13,12 @@ struct init_fn { void ( * initialise ) ( void ); }; +/** Initialisation function table */ +#define INIT_FNS "init_fns" + /** Declare an initialisation functon */ #define __init_fn( init_order ) \ - __table ( struct init_fn, init_fns, init_order ) + __table ( struct init_fn, INIT_FNS, init_order ) /** @defgroup initfn_order Initialisation function ordering * @{ @@ -49,9 +52,12 @@ struct startup_fn { void ( * shutdown ) ( int flags ); }; +/** Startup/shutdown function table */ +#define STARTUP_FNS "startup_fns" + /** Declare a startup/shutdown function */ #define __startup_fn( startup_order ) \ - __table ( struct startup_fn, startup_fns, startup_order ) + __table ( struct startup_fn, STARTUP_FNS, startup_order ) /** @defgroup startfn_order Startup/shutdown function ordering * diff --git a/src/include/gpxe/isa.h b/src/include/gpxe/isa.h index bb25dbce..947cb986 100644 --- a/src/include/gpxe/isa.h +++ b/src/include/gpxe/isa.h @@ -58,8 +58,11 @@ struct isa_driver { void ( * remove ) ( struct isa_device *isa ); }; +/** ISA driver table */ +#define ISA_DRIVERS "isa_drivers" + /** Declare an ISA driver */ -#define __isa_driver __table ( struct isa_driver, isa_drivers, 01 ) +#define __isa_driver __table ( struct isa_driver, ISA_DRIVERS, 01 ) /** * Set ISA driver-private data diff --git a/src/include/gpxe/isapnp.h b/src/include/gpxe/isapnp.h index 07797a99..4a7c7817 100644 --- a/src/include/gpxe/isapnp.h +++ b/src/include/gpxe/isapnp.h @@ -223,8 +223,11 @@ struct isapnp_driver { void ( * remove ) ( struct isapnp_device *isapnp ); }; +/** ISAPnP driver table */ +#define ISAPNP_DRIVERS "isapnp_drivers" + /** Declare an ISAPnP driver */ -#define __isapnp_driver __table ( struct isapnp_driver, isapnp_drivers, 01 ) +#define __isapnp_driver __table ( struct isapnp_driver, ISAPNP_DRIVERS, 01 ) extern uint16_t isapnp_read_port; diff --git a/src/include/gpxe/mca.h b/src/include/gpxe/mca.h index 21f9e74d..d1f38c8e 100644 --- a/src/include/gpxe/mca.h +++ b/src/include/gpxe/mca.h @@ -77,8 +77,11 @@ struct mca_driver { void ( * remove ) ( struct mca_device *mca ); }; +/** MCA driver table */ +#define MCA_DRIVERS "mca_drivers" + /** Declare an MCA driver */ -#define __mca_driver __table ( struct mca_driver, mca_drivers, 01 ) +#define __mca_driver __table ( struct mca_driver, MCA_DRIVERS, 01 ) /** * Set MCA driver-private data diff --git a/src/include/gpxe/netdevice.h b/src/include/gpxe/netdevice.h index f1585de0..9d1c9d07 100644 --- a/src/include/gpxe/netdevice.h +++ b/src/include/gpxe/netdevice.h @@ -279,11 +279,17 @@ struct net_device { /** Network device has link */ #define NETDEV_LINK_UP 0x0002 +/** Link-layer protocol table */ +#define LL_PROTOCOLS "ll_protocols" + /** Declare a link-layer protocol */ -#define __ll_protocol __table ( struct ll_protocol, ll_protocols, 01 ) +#define __ll_protocol __table ( struct ll_protocol, LL_PROTOCOLS, 01 ) + +/** Network-layer protocol table */ +#define NET_PROTOCOLS "net_protocols" /** Declare a network-layer protocol */ -#define __net_protocol __table ( struct net_protocol, net_protocols, 01 ) +#define __net_protocol __table ( struct net_protocol, NET_PROTOCOLS, 01 ) extern struct list_head net_devices; extern struct net_device_operations null_netdev_operations; diff --git a/src/include/gpxe/open.h b/src/include/gpxe/open.h index 81d5fc24..69a8b3f4 100644 --- a/src/include/gpxe/open.h +++ b/src/include/gpxe/open.h @@ -58,8 +58,11 @@ struct uri_opener { int ( * open ) ( struct xfer_interface *xfer, struct uri *uri ); }; +/** URI opener table */ +#define URI_OPENERS "uri_openers" + /** Register a URI opener */ -#define __uri_opener __table ( struct uri_opener, uri_openers, 01 ) +#define __uri_opener __table ( struct uri_opener, URI_OPENERS, 01 ) /** A socket opener */ struct socket_opener { @@ -78,8 +81,11 @@ struct socket_opener { struct sockaddr *local ); }; +/** Socket opener table */ +#define SOCKET_OPENERS "socket_openers" + /** Register a socket opener */ -#define __socket_opener __table ( struct socket_opener, socket_openers, 01 ) +#define __socket_opener __table ( struct socket_opener, SOCKET_OPENERS, 01 ) extern int xfer_open_uri ( struct xfer_interface *xfer, struct uri *uri ); extern int xfer_open_uri_string ( struct xfer_interface *xfer, diff --git a/src/include/gpxe/pci.h b/src/include/gpxe/pci.h index 1ccdb100..86bd8f79 100644 --- a/src/include/gpxe/pci.h +++ b/src/include/gpxe/pci.h @@ -308,8 +308,11 @@ struct pci_driver { void ( * remove ) ( struct pci_device *pci ); }; +/** PCI driver table */ +#define PCI_DRIVERS "pci_drivers" + /** Declare a PCI driver */ -#define __pci_driver __table ( struct pci_driver, pci_drivers, 01 ) +#define __pci_driver __table ( struct pci_driver, PCI_DRIVERS, 01 ) #define PCI_DEVFN( slot, func ) ( ( (slot) << 3 ) | (func) ) #define PCI_SLOT( devfn ) ( ( (devfn) >> 3 ) & 0x1f ) diff --git a/src/include/gpxe/process.h b/src/include/gpxe/process.h index 8d9b109a..705c9f67 100644 --- a/src/include/gpxe/process.h +++ b/src/include/gpxe/process.h @@ -63,6 +63,9 @@ process_init ( struct process *process, process_add ( process ); } +/** Permanent process table */ +#define PERMANENT_PROCESSES "processes" + /** * Declare a permanent process * @@ -70,6 +73,6 @@ process_init ( struct process *process, * at initialisation time. */ #define __permanent_process \ - __table ( struct process, processes, 01 ) + __table ( struct process, PERMANENT_PROCESSES, 01 ) #endif /* _GPXE_PROCESS_H */ diff --git a/src/include/gpxe/resolv.h b/src/include/gpxe/resolv.h index e73c8201..d276522e 100644 --- a/src/include/gpxe/resolv.h +++ b/src/include/gpxe/resolv.h @@ -149,9 +149,12 @@ struct resolver { /** Normal resolver priority */ #define RESOLV_NORMAL 02 +/** Resolvers table */ +#define RESOLVERS "resolvers" + /** Register as a name resolver */ #define __resolver( resolv_order ) \ - __table ( struct resolver, resolvers, resolv_order ) + __table ( struct resolver, RESOLVERS, resolv_order ) extern void resolv_done ( struct resolv_interface *resolv, struct sockaddr *sa, int rc ); diff --git a/src/include/gpxe/sanboot.h b/src/include/gpxe/sanboot.h index ea26a356..68fd0b9b 100644 --- a/src/include/gpxe/sanboot.h +++ b/src/include/gpxe/sanboot.h @@ -8,7 +8,9 @@ struct sanboot_protocol { int ( * boot ) ( const char *root_path ); }; +#define SANBOOT_PROTOCOLS "sanboot_protocols" + #define __sanboot_protocol \ - __table ( struct sanboot_protocol, sanboot_protocols, 01 ) + __table ( struct sanboot_protocol, SANBOOT_PROTOCOLS, 01 ) #endif /* _GPXE_SANBOOT_H */ diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index fe9c8082..4f7f98ef 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -36,8 +36,11 @@ struct setting { unsigned int tag; }; +/** Configuration setting table */ +#define SETTINGS "settings" + /** Declare a configuration setting */ -#define __setting __table ( struct setting, settings, 01 ) +#define __setting __table ( struct setting, SETTINGS, 01 ) /** Settings block operations */ struct settings_operations { @@ -123,9 +126,12 @@ struct setting_type { char *buf, size_t len ); }; +/** Configuration setting type table */ +#define SETTING_TYPES "setting_types" + /** Declare a configuration setting type */ #define __setting_type \ - __table ( struct setting_type, setting_types, 01 ) + __table ( struct setting_type, SETTING_TYPES, 01 ) /** * A settings applicator @@ -139,9 +145,12 @@ struct settings_applicator { int ( * apply ) ( void ); }; +/** Settings applicator table */ +#define SETTINGS_APPLICATORS "settings_applicators" + /** Declare a settings applicator */ #define __settings_applicator \ - __table ( struct settings_applicator, settings_applicators, 01 ) + __table ( struct settings_applicator, SETTINGS_APPLICATORS, 01 ) /** * A simple settings block diff --git a/src/include/gpxe/tables.h b/src/include/gpxe/tables.h index b2c56ab6..5d4a43c5 100644 --- a/src/include/gpxe/tables.h +++ b/src/include/gpxe/tables.h @@ -115,7 +115,7 @@ * void ( *frob ) ( void ); // The frobnicating function itself * }; * - * #define __frobnicator __table ( frobnicators, 01 ) + * #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 ) * * @endcode * @@ -145,14 +145,11 @@ * * #include "frob.h" * - * static struct frob frob_start[0] __table_start ( frobnicators ); - * static struct frob frob_end[0] __table_end ( frobnicators ); - * * // Call all linked-in frobnicators * void frob_all ( void ) { * struct frob *frob; * - * for ( frob = frob_start ; frob < frob_end ; frob++ ) { + * for_each_table ( frob, "frobnicators" ) { * printf ( "Calling frobnicator \"%s\"\n", frob->name ); * frob->frob (); * } @@ -170,7 +167,7 @@ #define __table_str( x ) #x #define __table_section( table, idx ) \ - __section__ ( ".tbl." __table_str ( table ) "." __table_str ( idx ) ) + __section__ ( ".tbl." table "." __table_str ( idx ) ) #define __table_section_start( table ) __table_section ( table, 00 ) #define __table_section_end( table ) __table_section ( table, 99 ) @@ -185,45 +182,110 @@ * * @code * - * struct my_foo __table ( foo, 01 ) = { + * #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 ) + * + * struct frobnicator my_frob __frobnicator = { * ... * }; * * @endcode * */ -#define __table( type, table, idx ) \ - __attribute__ (( __table_section ( table, idx ), \ +#define __table( type, table, idx ) \ + __attribute__ (( __table_section ( table, idx ), \ __natural_alignment ( type ) )) /** - * Linker table start marker. + * Start of linker table. * - * Declares a data structure (usually an empty data structure) to be - * the start of a linker table. Use as e.g. + * Return the start of a linker table. Use as e.g. * * @code * - * static struct foo_start[0] __table_start ( foo ); + * struct frobnicator *frobs = + * table_start ( struct frobnicator, "frobnicators" ); * * @endcode * */ -#define __table_start( type, table ) __table ( type, table, 00 ) +#define table_start( type, table ) ( { \ + static type __table_start[0] __table ( type, table, 00 ); \ + __table_start; } ) /** - * Linker table end marker. + * End of linker table. * - * Declares a data structure (usually an empty data structure) to be - * the end of a linker table. Use as e.g. + * Return the end of a linker table. Use as e.g. * * @code * - * static struct foo_end[0] __table_end ( foo ); + * struct frobnicator *frobs_end = + * table_end ( struct frobnicator, "frobnicators" ); * * @endcode * */ -#define __table_end( type, table ) __table ( type, table, 99 ) +#define table_end( type, table ) ( { \ + static type __table_end[0] __table ( type, table, 99 ); \ + __table_end; } ) + +/** + * Calculate number of entries in linker table. + * + * Return the number of entries within a linker table. Use as e.g. + * + * @code + * + * unsigned int num_frobs = + * table_num_entries ( struct frobnicator, "frobnicators" ); + * + * @endcode + * + */ +#define table_num_entries( type, table ) \ + ( ( unsigned int ) ( table_end ( type, table ) - \ + table_start ( type, table ) ) ) + +/** + * Iterate through all entries within a linker table. + * + * Use as e.g. + * + * @code + * + * struct frobnicator *frob; + * + * for_each_table_entry ( frob, "frobnicators" ) { + * ... + * } + * + * @endcode + * + */ +#define for_each_table_entry( pointer, table ) \ + for ( pointer = table_start ( typeof ( * pointer ), table ) ; \ + pointer < table_end ( typeof ( * pointer ), table ) ; \ + pointer++ ) + +/** + * Iterate through all entries within a linker table in reverse order. + * + * Use as e.g. + * + * @code + * + * struct frobnicator *frob; + * + * for_each_table_entry_reverse ( frob, "frobnicators" ) { + * ... + * } + * + * @endcode + * + */ +#define for_each_table_entry_reverse( pointer, table ) \ + for ( pointer = table_end ( typeof ( * pointer ), table ) - 1 ; \ + pointer >= table_start ( typeof ( * pointer ), table ) ; \ + pointer-- ) #endif /* _GPXE_TABLES_H */ diff --git a/src/include/gpxe/tcpip.h b/src/include/gpxe/tcpip.h index da89530e..5200b5ed 100644 --- a/src/include/gpxe/tcpip.h +++ b/src/include/gpxe/tcpip.h @@ -98,13 +98,19 @@ struct tcpip_net_protocol { uint16_t *trans_csum ); }; +/** TCP/IP transport-layer protocol table */ +#define TCPIP_PROTOCOLS "tcpip_protocols" + /** Declare a TCP/IP transport-layer protocol */ #define __tcpip_protocol \ - __table ( struct tcpip_protocol, tcpip_protocols, 01 ) + __table ( struct tcpip_protocol, TCPIP_PROTOCOLS, 01 ) + +/** TCP/IP network-layer protocol table */ +#define TCPIP_NET_PROTOCOLS "tcpip_net_protocols" /** Declare a TCP/IP network-layer protocol */ #define __tcpip_net_protocol \ - __table ( struct tcpip_net_protocol, tcpip_net_protocols, 01 ) + __table ( struct tcpip_net_protocol, TCPIP_NET_PROTOCOLS, 01 ) extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto, struct sockaddr_tcpip *st_src, diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c index 6e54cf7e..43a3ca80 100644 --- a/src/interface/efi/efi_init.c +++ b/src/interface/efi/efi_init.c @@ -26,18 +26,6 @@ EFI_HANDLE efi_image_handle; /** System table passed to entry point */ EFI_SYSTEM_TABLE *efi_systab; -/** Declared used EFI protocols */ -static struct efi_protocol efi_protocols[0] \ - __table_start ( struct efi_protocol, efi_protocols ); -static struct efi_protocol efi_protocols_end[0] \ - __table_end ( struct efi_protocol, efi_protocols ); - -/** Declared used EFI configuration tables */ -static struct efi_config_table efi_config_tables[0] \ - __table_start ( struct efi_config_table, efi_config_tables ); -static struct efi_config_table efi_config_tables_end[0] \ - __table_end ( struct efi_config_table, efi_config_tables ); - /** * Look up EFI configuration table * @@ -92,7 +80,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, /* Look up used protocols */ bs = systab->BootServices; - for ( prot = efi_protocols ; prot < efi_protocols_end ; prot++ ) { + for_each_table_entry ( prot, EFI_PROTOCOLS ) { if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL, prot->protocol ) ) == 0 ) { DBGC ( systab, "EFI protocol %s is at %p\n", @@ -106,7 +94,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, } /* Look up used configuration tables */ - for ( tab = efi_config_tables ; tab < efi_config_tables_end ; tab++ ) { + for_each_table_entry ( tab, EFI_CONFIG_TABLES ) { if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) { DBGC ( systab, "EFI configuration table %s is at %p\n", uuid_ntoa ( &tab->u.uuid ), *(tab->table) ); diff --git a/src/net/arp.c b/src/net/arp.c index ba9ebf48..cf2fe988 100644 --- a/src/net/arp.c +++ b/src/net/arp.c @@ -36,12 +36,6 @@ * */ -/** Registered ARP protocols */ -static struct arp_net_protocol arp_net_protocols[0] - __table_start ( struct arp_net_protocol, arp_net_protocols ); -static struct arp_net_protocol arp_net_protocols_end[0] - __table_end ( struct arp_net_protocol, arp_net_protocols ); - /** An ARP cache entry */ struct arp_entry { /** Network-layer protocol */ @@ -176,8 +170,7 @@ int arp_resolve ( struct net_device *netdev, struct net_protocol *net_protocol, static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) { struct arp_net_protocol *arp_net_protocol; - for ( arp_net_protocol = arp_net_protocols ; - arp_net_protocol < arp_net_protocols_end ; arp_net_protocol++ ) { + for_each_table_entry ( arp_net_protocol, ARP_NET_PROTOCOLS ) { if ( arp_net_protocol->net_protocol->net_proto == net_proto ) { return arp_net_protocol; } diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 9e142d27..9e031497 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -36,12 +36,6 @@ * */ -/** Registered network-layer protocols */ -static struct net_protocol net_protocols[0] - __table_start ( struct net_protocol, net_protocols ); -static struct net_protocol net_protocols_end[0] - __table_end ( struct net_protocol, net_protocols ); - /** List of network devices */ struct list_head net_devices = LIST_HEAD_INIT ( net_devices ); @@ -538,8 +532,7 @@ int net_rx ( struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol; /* Hand off to network-layer protocol, if any */ - for ( net_protocol = net_protocols ; net_protocol < net_protocols_end ; - net_protocol++ ) { + for_each_table_entry ( net_protocol, NET_PROTOCOLS ) { if ( net_protocol->net_proto == net_proto ) { return net_protocol->rx ( iobuf, netdev, ll_source ); } diff --git a/src/net/tcpip.c b/src/net/tcpip.c index d4542b05..cef638f3 100644 --- a/src/net/tcpip.c +++ b/src/net/tcpip.c @@ -14,18 +14,6 @@ * TCP/IP transport-network layer interface */ -/** Registered network-layer protocols that support TCP/IP */ -static struct tcpip_net_protocol tcpip_net_protocols[0] - __table_start ( struct tcpip_net_protocol, tcpip_net_protocols ); -static struct tcpip_net_protocol tcpip_net_protocols_end[0] - __table_end ( struct tcpip_net_protocol, tcpip_net_protocols ); - -/** Registered transport-layer protocols that support TCP/IP */ -static struct tcpip_protocol tcpip_protocols[0] - __table_start ( struct tcpip_protocol, tcpip_protocols ); -static struct tcpip_protocol tcpip_protocols_end[0] - __table_end ( struct tcpip_protocol, tcpip_protocols ); - /** Process a received TCP/IP packet * * @v iobuf I/O buffer @@ -48,7 +36,7 @@ int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto, struct tcpip_protocol *tcpip; /* Hand off packet to the appropriate transport-layer protocol */ - for ( tcpip = tcpip_protocols; tcpip < tcpip_protocols_end; tcpip++ ) { + for_each_table_entry ( tcpip, TCPIP_PROTOCOLS ) { if ( tcpip->tcpip_proto == tcpip_proto ) { DBG ( "TCP/IP received %s packet\n", tcpip->name ); 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, struct tcpip_net_protocol *tcpip_net; /* Hand off packet to the appropriate network-layer protocol */ - for ( tcpip_net = tcpip_net_protocols ; - tcpip_net < tcpip_net_protocols_end ; tcpip_net++ ) { + for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) { if ( tcpip_net->sa_family == st_dest->st_family ) { DBG ( "TCP/IP sending %s packet\n", tcpip_net->name ); return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c index ab843ce1..0f445995 100644 --- a/src/net/udp/dhcp.c +++ b/src/net/udp/dhcp.c @@ -88,10 +88,6 @@ static uint8_t dhcp_request_options_data[] = { DHCP_END }; -/** DHCP feature codes */ -static uint8_t dhcp_features[0] __table_start ( uint8_t, dhcp_features ); -static uint8_t dhcp_features_end[0] __table_end ( uint8_t, dhcp_features ); - /** Version number feature */ FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH ); @@ -884,6 +880,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt, struct dhcp_netdev_desc dhcp_desc; struct dhcp_client_id client_id; struct dhcp_client_uuid client_uuid; + uint8_t *dhcp_features; size_t dhcp_features_len; size_t ll_addr_len; ssize_t len; @@ -903,7 +900,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt, dhcppkt->dhcphdr->ciaddr = ciaddr; /* Add options to identify the feature list */ - dhcp_features_len = ( dhcp_features_end - dhcp_features ); + dhcp_features = table_start ( uint8_t, DHCP_FEATURES ); + dhcp_features_len = table_num_entries ( uint8_t, DHCP_FEATURES ); if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features, dhcp_features_len ) ) != 0 ) { DBG ( "DHCP could not set features list option: %s\n", diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index 98e79a7f..6cb744c3 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -43,12 +43,6 @@ /** Shutdown flags for exit */ int shutdown_exit_flags = 0; -/* SAN boot protocols */ -static struct sanboot_protocol sanboot_protocols[0] \ - __table_start ( struct sanboot_protocol, sanboot_protocols ); -static struct sanboot_protocol sanboot_protocols_end[0] \ - __table_end ( struct sanboot_protocol, sanboot_protocols ); - /** * Identify the boot network device * @@ -124,8 +118,7 @@ int boot_root_path ( const char *root_path ) { struct sanboot_protocol *sanboot; /* Quick hack */ - for ( sanboot = sanboot_protocols ; - sanboot < sanboot_protocols_end ; sanboot++ ) { + for_each_table_entry ( sanboot, SANBOOT_PROTOCOLS ) { if ( strncmp ( root_path, sanboot->prefix, strlen ( sanboot->prefix ) ) == 0 ) { return sanboot->boot ( root_path );