david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[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.
This commit is contained in:
Michael Brown 2009-03-12 19:41:40 +00:00
parent 3ed468e0c5
commit 1266d7902b
48 changed files with 239 additions and 264 deletions

View File

@ -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;

View File

@ -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 )

View File

@ -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 );
}

View File

@ -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;
}

View File

@ -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 )

View File

@ -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 );
}

View File

@ -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" );

View File

@ -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 );

View File

@ -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 */

View File

@ -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 );

View File

@ -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;
}

View File

@ -7,11 +7,6 @@
#include <unistd.h>
#include <gpxe/eisa.h>
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 )

View File

@ -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 */

View File

@ -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 )

View File

@ -13,11 +13,6 @@
#include <gpxe/io.h>
#include <gpxe/mca.h>
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 ) )

View File

@ -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 ) &&

View File

@ -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" );

View File

@ -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;
}

View File

@ -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 );
}

View File

@ -85,6 +85,9 @@ struct console_driver {
int ( *iskey ) ( void );
};
/** Console driver table */
#define CONSOLES "consoles"
/**
* Mark a <tt> struct console_driver </tt> 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 */

View File

@ -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;

View File

@ -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 */

View File

@ -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 */

View File

@ -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
*

View File

@ -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 );

View File

@ -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 */

View File

@ -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 ) \

View File

@ -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

View File

@ -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;

View File

@ -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
*

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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,

View File

@ -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 )

View File

@ -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 */

View File

@ -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 );

View File

@ -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 */

View File

@ -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

View File

@ -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 */

View File

@ -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,

View File

@ -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) );

View File

@ -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;
}

View File

@ -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 );
}

View File

@ -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,

View File

@ -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",

View File

@ -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 );