summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2009-03-12 20:41:40 +0100
committerMichael Brown2009-03-13 03:06:30 +0100
commit1266d7902bf7f2534ee279671d48613ef9b2434c (patch)
treea1a5b188148d983fa962a887476259768f1751d4 /src/core
parent[tcp] Avoid setting PSH flag when SYN flag is set (diff)
downloadipxe-1266d7902bf7f2534ee279671d48613ef9b2434c.tar.gz
ipxe-1266d7902bf7f2534ee279671d48613ef9b2434c.tar.xz
ipxe-1266d7902bf7f2534ee279671d48613ef9b2434c.zip
[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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/console.c11
-rw-r--r--src/core/device.c7
-rw-r--r--src/core/exec.c7
-rw-r--r--src/core/gdbstub.c7
-rw-r--r--src/core/image.c8
-rw-r--r--src/core/init.c23
-rw-r--r--src/core/main.c5
-rw-r--r--src/core/open.c16
-rw-r--r--src/core/process.c9
-rw-r--r--src/core/resolv.c10
-rw-r--r--src/core/settings.c25
11 files changed, 20 insertions, 108 deletions
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;
}