diff --git a/src/core/resolv.c b/src/core/resolv.c index 667f2ded..33e341d2 100644 --- a/src/core/resolv.c +++ b/src/core/resolv.c @@ -217,7 +217,7 @@ static void resolv_mux_done ( struct resolv_interface *resolv, /* Attempt next child resolver, if possible */ mux->resolver++; - if ( mux->resolver >= table_end ( struct resolver, RESOLVERS ) ) { + if ( mux->resolver >= table_end ( RESOLVERS ) ) { DBGC ( mux, "RESOLV %p failed to resolve name\n", mux ); goto finished; } @@ -256,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 = table_start ( struct resolver, RESOLVERS ); + mux->resolver = table_start ( RESOLVERS ); memcpy ( &mux->sa, sa, sizeof ( mux->sa ) ); memcpy ( mux->name, name, name_len ); diff --git a/src/hci/tui/settings_ui.c b/src/hci/tui/settings_ui.c index 61f94cde..83a56d3c 100644 --- a/src/hci/tui/settings_ui.c +++ b/src/hci/tui/settings_ui.c @@ -78,7 +78,7 @@ struct setting_widget { }; /** Number of registered configuration settings */ -#define NUM_SETTINGS table_num_entries ( struct setting, SETTINGS ) +#define NUM_SETTINGS table_num_entries ( SETTINGS ) static void load_setting ( struct setting_widget *widget ) __nonnull; static int save_setting ( struct setting_widget *widget ) __nonnull; @@ -219,8 +219,7 @@ 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 ); + struct setting *all_settings = table_start ( 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 fd36cd5b..93c53adb 100644 --- a/src/include/console.h +++ b/src/include/console.h @@ -86,7 +86,7 @@ struct console_driver { }; /** Console driver table */ -#define CONSOLES "consoles" +#define CONSOLES __table ( struct console_driver, "consoles" ) /** * Mark a struct console_driver as being part of the @@ -105,7 +105,7 @@ struct console_driver { * @endcode * */ -#define __console_driver __table ( struct console_driver, CONSOLES, 01 ) +#define __console_driver __table_entry ( CONSOLES, 01 ) /* Function prototypes */ diff --git a/src/include/gpxe/arp.h b/src/include/gpxe/arp.h index 5bdd1d56..7dcc7793 100644 --- a/src/include/gpxe/arp.h +++ b/src/include/gpxe/arp.h @@ -27,11 +27,11 @@ struct arp_net_protocol { }; /** ARP protocol table */ -#define ARP_NET_PROTOCOLS "arp_net_protocols" +#define ARP_NET_PROTOCOLS \ + __table ( struct arp_net_protocol, "arp_net_protocols" ) /** Declare an ARP protocol */ -#define __arp_net_protocol \ - __table ( struct arp_net_protocol, ARP_NET_PROTOCOLS, 01 ) +#define __arp_net_protocol __table_entry ( 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 ee270dfd..39bed477 100644 --- a/src/include/gpxe/command.h +++ b/src/include/gpxe/command.h @@ -17,8 +17,8 @@ struct command { int ( * exec ) ( int argc, char **argv ); }; -#define COMMANDS "commands" +#define COMMANDS __table ( struct command, "commands" ) -#define __command __table ( struct command, COMMANDS, 01 ) +#define __command __table_entry ( COMMANDS, 01 ) #endif /* _GPXE_COMMAND_H */ diff --git a/src/include/gpxe/device.h b/src/include/gpxe/device.h index bcc848aa..9017f9b9 100644 --- a/src/include/gpxe/device.h +++ b/src/include/gpxe/device.h @@ -103,9 +103,9 @@ struct root_driver { }; /** Root device table */ -#define ROOT_DEVICES "root_devices" +#define ROOT_DEVICES __table ( struct root_device, "root_devices" ) /** Declare a root device */ -#define __root_device __table ( struct root_device, ROOT_DEVICES, 01 ) +#define __root_device __table_entry ( ROOT_DEVICES, 01 ) #endif /* _GPXE_DEVICE_H */ diff --git a/src/include/gpxe/efi/efi.h b/src/include/gpxe/efi/efi.h index c44e09cb..1f5b8856 100644 --- a/src/include/gpxe/efi/efi.h +++ b/src/include/gpxe/efi/efi.h @@ -55,11 +55,10 @@ struct efi_protocol { }; /** EFI protocol table */ -#define EFI_PROTOCOLS "efi_protocols" +#define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" ) /** Declare an EFI protocol used by gPXE */ -#define __efi_protocol \ - __table ( struct efi_protocol, EFI_PROTOCOLS, 01 ) +#define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 ) /** Declare an EFI protocol to be required by gPXE * @@ -90,11 +89,11 @@ struct efi_config_table { }; /** EFI configuration table table */ -#define EFI_CONFIG_TABLES "efi_config_tables" +#define EFI_CONFIG_TABLES \ + __table ( struct efi_config_table, "efi_config_tables" ) /** Declare an EFI configuration table used by gPXE */ -#define __efi_config_table \ - __table ( struct efi_config_table, EFI_CONFIG_TABLES, 01 ) +#define __efi_config_table __table_entry ( 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 1f3a9caa..cde46af2 100644 --- a/src/include/gpxe/eisa.h +++ b/src/include/gpxe/eisa.h @@ -80,10 +80,10 @@ struct eisa_driver { }; /** EISA driver table */ -#define EISA_DRIVERS "eisa_drivers" +#define EISA_DRIVERS __table ( struct eisa_driver, "eisa_drivers" ) /** Declare an EISA driver */ -#define __eisa_driver __table ( struct eisa_driver, EISA_DRIVERS, 01 ) +#define __eisa_driver __table_entry ( 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 8e746f02..d519f68c 100644 --- a/src/include/gpxe/errortab.h +++ b/src/include/gpxe/errortab.h @@ -14,8 +14,8 @@ struct errortab { const char *text; }; -#define ERRORTAB "errortab" +#define ERRORTAB __table ( struct errortab, "errortab" ) -#define __errortab __table ( struct errortab, ERRORTAB, 01 ) +#define __errortab __table_entry ( ERRORTAB, 01 ) #endif /* _GPXE_ERRORTAB_H */ diff --git a/src/include/gpxe/features.h b/src/include/gpxe/features.h index e979ee7c..8d3977cb 100644 --- a/src/include/gpxe/features.h +++ b/src/include/gpxe/features.h @@ -51,10 +51,10 @@ /** @} */ /** DHCP feature table */ -#define DHCP_FEATURES "dhcp_features" +#define DHCP_FEATURES __table ( uint8_t, "dhcp_features" ) /** Declare a feature code for DHCP */ -#define __dhcp_feature __table ( uint8_t, DHCP_FEATURES, 01 ) +#define __dhcp_feature __table_entry ( DHCP_FEATURES, 01 ) /** Construct a DHCP feature table entry */ #define DHCP_FEATURE( feature_opt, ... ) \ @@ -73,11 +73,10 @@ struct feature { }; /** Named feature table */ -#define FEATURES "features" +#define FEATURES __table ( struct feature, "features" ) /** Declare a named feature */ -#define __feature_name( category ) \ - __table ( struct feature, FEATURES, category ) +#define __feature_name( category ) __table_entry ( 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 624b15f7..2e2c4dab 100644 --- a/src/include/gpxe/gdbstub.h +++ b/src/include/gpxe/gdbstub.h @@ -45,9 +45,9 @@ struct gdb_transport { void ( * send ) ( const char *buf, size_t len ); }; -#define GDB_TRANSPORTS "gdb_transports" +#define GDB_TRANSPORTS __table ( struct gdb_transport, "gdb_transports" ) -#define __gdb_transport __table ( struct gdb_transport, GDB_TRANSPORTS, 01 ) +#define __gdb_transport __table_entry ( GDB_TRANSPORTS, 01 ) /** * Look up GDB transport by name diff --git a/src/include/gpxe/image.h b/src/include/gpxe/image.h index cb3bb361..b4047467 100644 --- a/src/include/gpxe/image.h +++ b/src/include/gpxe/image.h @@ -124,11 +124,10 @@ struct image_type { #define PROBE_PXE 03 /** Executable or loadable image type table */ -#define IMAGE_TYPES "image_types" +#define IMAGE_TYPES __table ( struct image_type, "image_types" ) /** An executable or loadable image type */ -#define __image_type( probe_order ) \ - __table ( struct image_type, IMAGE_TYPES, probe_order ) +#define __image_type( probe_order ) __table_entry ( IMAGE_TYPES, probe_order ) extern struct list_head images; diff --git a/src/include/gpxe/init.h b/src/include/gpxe/init.h index 9ce56d77..5a51b033 100644 --- a/src/include/gpxe/init.h +++ b/src/include/gpxe/init.h @@ -14,11 +14,10 @@ struct init_fn { }; /** Initialisation function table */ -#define INIT_FNS "init_fns" +#define INIT_FNS __table ( struct init_fn, "init_fns" ) /** Declare an initialisation functon */ -#define __init_fn( init_order ) \ - __table ( struct init_fn, INIT_FNS, init_order ) +#define __init_fn( init_order ) __table_entry ( INIT_FNS, init_order ) /** @defgroup initfn_order Initialisation function ordering * @{ @@ -53,11 +52,11 @@ struct startup_fn { }; /** Startup/shutdown function table */ -#define STARTUP_FNS "startup_fns" +#define STARTUP_FNS __table ( struct startup_fn, "startup_fns" ) /** Declare a startup/shutdown function */ #define __startup_fn( startup_order ) \ - __table ( struct startup_fn, STARTUP_FNS, startup_order ) + __table_entry ( 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 947cb986..458d754b 100644 --- a/src/include/gpxe/isa.h +++ b/src/include/gpxe/isa.h @@ -59,10 +59,10 @@ struct isa_driver { }; /** ISA driver table */ -#define ISA_DRIVERS "isa_drivers" +#define ISA_DRIVERS __table ( struct isa_driver, "isa_drivers" ) /** Declare an ISA driver */ -#define __isa_driver __table ( struct isa_driver, ISA_DRIVERS, 01 ) +#define __isa_driver __table_entry ( ISA_DRIVERS, 01 ) /** * Set ISA driver-private data diff --git a/src/include/gpxe/isapnp.h b/src/include/gpxe/isapnp.h index 4a7c7817..633f7b0c 100644 --- a/src/include/gpxe/isapnp.h +++ b/src/include/gpxe/isapnp.h @@ -224,10 +224,10 @@ struct isapnp_driver { }; /** ISAPnP driver table */ -#define ISAPNP_DRIVERS "isapnp_drivers" +#define ISAPNP_DRIVERS __table ( struct isapnp_driver, "isapnp_drivers" ) /** Declare an ISAPnP driver */ -#define __isapnp_driver __table ( struct isapnp_driver, ISAPNP_DRIVERS, 01 ) +#define __isapnp_driver __table_entry ( ISAPNP_DRIVERS, 01 ) extern uint16_t isapnp_read_port; diff --git a/src/include/gpxe/mca.h b/src/include/gpxe/mca.h index d1f38c8e..d276acfe 100644 --- a/src/include/gpxe/mca.h +++ b/src/include/gpxe/mca.h @@ -78,10 +78,10 @@ struct mca_driver { }; /** MCA driver table */ -#define MCA_DRIVERS "mca_drivers" +#define MCA_DRIVERS __table ( struct mca_driver, "mca_drivers" ) /** Declare an MCA driver */ -#define __mca_driver __table ( struct mca_driver, MCA_DRIVERS, 01 ) +#define __mca_driver __table_entry ( MCA_DRIVERS, 01 ) /** * Set MCA driver-private data diff --git a/src/include/gpxe/netdevice.h b/src/include/gpxe/netdevice.h index 9d1c9d07..e4f5ed36 100644 --- a/src/include/gpxe/netdevice.h +++ b/src/include/gpxe/netdevice.h @@ -280,16 +280,16 @@ struct net_device { #define NETDEV_LINK_UP 0x0002 /** Link-layer protocol table */ -#define LL_PROTOCOLS "ll_protocols" +#define LL_PROTOCOLS __table ( struct ll_protocol, "ll_protocols" ) /** Declare a link-layer protocol */ -#define __ll_protocol __table ( struct ll_protocol, LL_PROTOCOLS, 01 ) +#define __ll_protocol __table_entry ( LL_PROTOCOLS, 01 ) /** Network-layer protocol table */ -#define NET_PROTOCOLS "net_protocols" +#define NET_PROTOCOLS __table ( struct net_protocol, "net_protocols" ) /** Declare a network-layer protocol */ -#define __net_protocol __table ( struct net_protocol, NET_PROTOCOLS, 01 ) +#define __net_protocol __table_entry ( 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 69a8b3f4..61fb0ef5 100644 --- a/src/include/gpxe/open.h +++ b/src/include/gpxe/open.h @@ -59,10 +59,10 @@ struct uri_opener { }; /** URI opener table */ -#define URI_OPENERS "uri_openers" +#define URI_OPENERS __table ( struct uri_opener, "uri_openers" ) /** Register a URI opener */ -#define __uri_opener __table ( struct uri_opener, URI_OPENERS, 01 ) +#define __uri_opener __table_entry ( URI_OPENERS, 01 ) /** A socket opener */ struct socket_opener { @@ -82,10 +82,10 @@ struct socket_opener { }; /** Socket opener table */ -#define SOCKET_OPENERS "socket_openers" +#define SOCKET_OPENERS __table ( struct socket_opener, "socket_openers" ) /** Register a socket opener */ -#define __socket_opener __table ( struct socket_opener, SOCKET_OPENERS, 01 ) +#define __socket_opener __table_entry ( 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 86bd8f79..b13c01ac 100644 --- a/src/include/gpxe/pci.h +++ b/src/include/gpxe/pci.h @@ -309,10 +309,10 @@ struct pci_driver { }; /** PCI driver table */ -#define PCI_DRIVERS "pci_drivers" +#define PCI_DRIVERS __table ( struct pci_driver, "pci_drivers" ) /** Declare a PCI driver */ -#define __pci_driver __table ( struct pci_driver, PCI_DRIVERS, 01 ) +#define __pci_driver __table_entry ( 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 705c9f67..42e4dfa6 100644 --- a/src/include/gpxe/process.h +++ b/src/include/gpxe/process.h @@ -64,7 +64,7 @@ process_init ( struct process *process, } /** Permanent process table */ -#define PERMANENT_PROCESSES "processes" +#define PERMANENT_PROCESSES __table ( struct process, "processes" ) /** * Declare a permanent process @@ -72,7 +72,6 @@ process_init ( struct process *process, * Permanent processes will be automatically added to the process list * at initialisation time. */ -#define __permanent_process \ - __table ( struct process, PERMANENT_PROCESSES, 01 ) +#define __permanent_process __table_entry ( PERMANENT_PROCESSES, 01 ) #endif /* _GPXE_PROCESS_H */ diff --git a/src/include/gpxe/resolv.h b/src/include/gpxe/resolv.h index d276522e..81207d28 100644 --- a/src/include/gpxe/resolv.h +++ b/src/include/gpxe/resolv.h @@ -150,11 +150,10 @@ struct resolver { #define RESOLV_NORMAL 02 /** Resolvers table */ -#define RESOLVERS "resolvers" +#define RESOLVERS __table ( struct resolver, "resolvers" ) /** Register as a name resolver */ -#define __resolver( resolv_order ) \ - __table ( struct resolver, RESOLVERS, resolv_order ) +#define __resolver( resolv_order ) __table_entry ( 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 68fd0b9b..05a3ddf0 100644 --- a/src/include/gpxe/sanboot.h +++ b/src/include/gpxe/sanboot.h @@ -8,9 +8,9 @@ struct sanboot_protocol { int ( * boot ) ( const char *root_path ); }; -#define SANBOOT_PROTOCOLS "sanboot_protocols" +#define SANBOOT_PROTOCOLS \ + __table ( struct sanboot_protocol, "sanboot_protocols" ) -#define __sanboot_protocol \ - __table ( struct sanboot_protocol, SANBOOT_PROTOCOLS, 01 ) +#define __sanboot_protocol __table_entry ( SANBOOT_PROTOCOLS, 01 ) #endif /* _GPXE_SANBOOT_H */ diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index 4f7f98ef..c25b6ad4 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -37,10 +37,10 @@ struct setting { }; /** Configuration setting table */ -#define SETTINGS "settings" +#define SETTINGS __table ( struct setting, "settings" ) /** Declare a configuration setting */ -#define __setting __table ( struct setting, SETTINGS, 01 ) +#define __setting __table_entry ( SETTINGS, 01 ) /** Settings block operations */ struct settings_operations { @@ -127,11 +127,10 @@ struct setting_type { }; /** Configuration setting type table */ -#define SETTING_TYPES "setting_types" +#define SETTING_TYPES __table ( struct setting_type, "setting_types" ) /** Declare a configuration setting type */ -#define __setting_type \ - __table ( struct setting_type, SETTING_TYPES, 01 ) +#define __setting_type __table_entry ( SETTING_TYPES, 01 ) /** * A settings applicator @@ -146,11 +145,11 @@ struct settings_applicator { }; /** Settings applicator table */ -#define SETTINGS_APPLICATORS "settings_applicators" +#define SETTINGS_APPLICATORS \ + __table ( struct settings_applicator, "settings_applicators" ) /** Declare a settings applicator */ -#define __settings_applicator \ - __table ( struct settings_applicator, SETTINGS_APPLICATORS, 01 ) +#define __settings_applicator __table_entry ( SETTINGS_APPLICATORS, 01 ) /** * A simple settings block diff --git a/src/include/gpxe/tables.h b/src/include/gpxe/tables.h index 5d4a43c5..a0b6f113 100644 --- a/src/include/gpxe/tables.h +++ b/src/include/gpxe/tables.h @@ -98,7 +98,7 @@ * The linker script takes care of assembling the tables for us. All * our table sections have names of the format @c .tbl.NAME.NN where * @c NAME designates the data structure stored in the table (e.g. @c - * init_fn) and @c NN is a two-digit decimal number used to impose an + * init_fns) and @c NN is a two-digit decimal number used to impose an * ordering upon the tables if required. @c NN=00 is reserved for the * symbol indicating "table start", and @c NN=99 is reserved for the * symbol indicating "table end". @@ -115,7 +115,9 @@ * void ( *frob ) ( void ); // The frobnicating function itself * }; * - * #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 ) + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * + * #define __frobnicator __table_entry ( FROBNICATORS, 01 ) * * @endcode * @@ -149,7 +151,7 @@ * void frob_all ( void ) { * struct frob *frob; * - * for_each_table ( frob, "frobnicators" ) { + * for_each_table ( frob, FROBNICATORS ) { * printf ( "Calling frobnicator \"%s\"\n", frob->name ); * frob->frob (); * } @@ -165,97 +167,154 @@ #define __attribute__( x ) #endif -#define __table_str( x ) #x -#define __table_section( table, 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 ) - -#define __natural_alignment( type ) __aligned__ ( __alignof__ ( type ) ) +/** + * Declare a linker table + * + * @v type Data type + * @v name Table name + * @ret table Linker table + */ +#define __table( type, name ) ( type, name ) /** - * Linker table entry. + * Get linker table data type * - * Declares a data structure to be part of a linker table. Use as - * e.g. + * @v table Linker table + * @ret type Data type + */ +#define __table_type( table ) __table_extract_type table +#define __table_extract_type( type, name ) type + +/** + * Get linker table name + * + * @v table Linker table + * @ret name Table name + */ +#define __table_name( table ) __table_extract_name table +#define __table_extract_name( type, name ) name + +/** + * Get linker table section name + * + * @v table Linker table + * @v idx Sub-table index + * @ret section Section name + */ +#define __table_section( table, idx ) \ + ".tbl." __table_name ( table ) "." __table_str ( idx ) +#define __table_str( x ) #x + +/** + * Get linker table alignment + * + * @v table Linker table + * @ret align Alignment + */ +#define __table_alignment( table ) __alignof__ ( __table_type ( table ) ) + +/** + * Declare a linker table entry + * + * @v table Linker table + * @v idx Sub-table index + * + * Example usage: * * @code * - * #define __frobnicator __table ( struct frobnicator, "frobnicators", 01 ) + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * + * #define __frobnicator __table_entry ( FROBNICATORS, 01 ) * * struct frobnicator my_frob __frobnicator = { * ... * }; * * @endcode - * */ -#define __table( type, table, idx ) \ - __attribute__ (( __table_section ( table, idx ), \ - __natural_alignment ( type ) )) +#define __table_entry( table, idx ) \ + __attribute__ (( __section__ ( __table_section ( table, idx ) ) \ + __aligned__ ( __table_alignment ( table ) ) )) /** - * Start of linker table. + * Get start of linker table * - * Return the start of a linker table. Use as e.g. + * @v table Linker table + * @ret start Start of linker table + * + * Example usage: * * @code * - * struct frobnicator *frobs = - * table_start ( struct frobnicator, "frobnicators" ); + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * + * struct frobnicator *frobs = table_start ( FROBNICATORS ); * * @endcode - * */ -#define table_start( type, table ) ( { \ - static type __table_start[0] __table ( type, table, 00 ); \ +#define table_start( table ) ( { \ + static __table_type ( table ) __table_start[0] \ + __table_entry ( table, 00 ); \ __table_start; } ) /** - * End of linker table. + * Get end of linker table * - * Return the end of a linker table. Use as e.g. + * @v table Linker table + * @ret end End of linker table + * + * Example usage: * * @code * - * struct frobnicator *frobs_end = - * table_end ( struct frobnicator, "frobnicators" ); + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * + * struct frobnicator *frobs_end = table_end ( FROBNICATORS ); * * @endcode - * */ -#define table_end( type, table ) ( { \ - static type __table_end[0] __table ( type, table, 99 ); \ +#define table_end( table ) ( { \ + static __table_type ( table ) __table_end[0] \ + __table_entry ( table, 99 ); \ __table_end; } ) /** - * Calculate number of entries in linker table. + * Get number of entries in linker table * - * Return the number of entries within a linker table. Use as e.g. + * @v table Linker table + * @ret num_entries Number of entries in linker table + * + * Example usage: * * @code * - * unsigned int num_frobs = - * table_num_entries ( struct frobnicator, "frobnicators" ); + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * + * unsigned int num_frobs = table_num_entries ( FROBNICATORS ); * * @endcode * */ -#define table_num_entries( type, table ) \ - ( ( unsigned int ) ( table_end ( type, table ) - \ - table_start ( type, table ) ) ) +#define table_num_entries( table ) \ + ( ( unsigned int ) ( table_end ( table ) - \ + table_start ( table ) ) ) /** - * Iterate through all entries within a linker table. + * Iterate through all entries within a linker table * - * Use as e.g. + * @v pointer Entry pointer + * @v table Linker table + * + * Example usage: * * @code * + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * * struct frobnicator *frob; * - * for_each_table_entry ( frob, "frobnicators" ) { + * for_each_table_entry ( frob, FROBNICATORS ) { * ... * } * @@ -263,20 +322,25 @@ * */ #define for_each_table_entry( pointer, table ) \ - for ( pointer = table_start ( typeof ( * pointer ), table ) ; \ - pointer < table_end ( typeof ( * pointer ), table ) ; \ + for ( pointer = table_start ( table ) ; \ + pointer < table_end ( table ) ; \ pointer++ ) /** - * Iterate through all entries within a linker table in reverse order. + * Iterate through all entries within a linker table in reverse order * - * Use as e.g. + * @v pointer Entry pointer + * @v table Linker table + * + * Example usage: * * @code * + * #define FROBNICATORS __table ( struct frobnicator, "frobnicators" ) + * * struct frobnicator *frob; * - * for_each_table_entry_reverse ( frob, "frobnicators" ) { + * for_each_table_entry_reverse ( frob, FROBNICATORS ) { * ... * } * @@ -284,8 +348,8 @@ * */ #define for_each_table_entry_reverse( pointer, table ) \ - for ( pointer = table_end ( typeof ( * pointer ), table ) - 1 ; \ - pointer >= table_start ( typeof ( * pointer ), table ) ; \ + for ( pointer = ( table_end ( table ) - 1 ) ; \ + pointer >= table_start ( table ) ; \ pointer-- ) #endif /* _GPXE_TABLES_H */ diff --git a/src/include/gpxe/tcpip.h b/src/include/gpxe/tcpip.h index 5200b5ed..544b9fef 100644 --- a/src/include/gpxe/tcpip.h +++ b/src/include/gpxe/tcpip.h @@ -99,18 +99,17 @@ struct tcpip_net_protocol { }; /** TCP/IP transport-layer protocol table */ -#define TCPIP_PROTOCOLS "tcpip_protocols" +#define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" ) /** Declare a TCP/IP transport-layer protocol */ -#define __tcpip_protocol \ - __table ( struct tcpip_protocol, TCPIP_PROTOCOLS, 01 ) +#define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 ) /** TCP/IP network-layer protocol table */ -#define TCPIP_NET_PROTOCOLS "tcpip_net_protocols" +#define TCPIP_NET_PROTOCOLS \ + __table ( struct tcpip_net_protocol, "tcpip_net_protocols" ) /** Declare a TCP/IP network-layer protocol */ -#define __tcpip_net_protocol \ - __table ( struct tcpip_net_protocol, TCPIP_NET_PROTOCOLS, 01 ) +#define __tcpip_net_protocol __table_entry ( 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/net/udp/dhcp.c b/src/net/udp/dhcp.c index 0f445995..97e64617 100644 --- a/src/net/udp/dhcp.c +++ b/src/net/udp/dhcp.c @@ -900,8 +900,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt, dhcppkt->dhcphdr->ciaddr = ciaddr; /* Add options to identify the feature list */ - dhcp_features = table_start ( uint8_t, DHCP_FEATURES ); - dhcp_features_len = table_num_entries ( uint8_t, DHCP_FEATURES ); + dhcp_features = table_start ( DHCP_FEATURES ); + dhcp_features_len = table_num_entries ( 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",