]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[tables] Incorporate table data type information into table definition
authorMichael Brown <mcb30@etherboot.org>
Fri, 13 Mar 2009 00:13:38 +0000 (00:13 +0000)
committerMichael Brown <mcb30@etherboot.org>
Fri, 13 Mar 2009 02:10:21 +0000 (02:10 +0000)
Eliminate the potential for mismatches between table names and the
table entry data type by incorporating the data type into the
definition of the table, rather than specifying it explicitly in each
table accessor method.

26 files changed:
src/core/resolv.c
src/hci/tui/settings_ui.c
src/include/console.h
src/include/gpxe/arp.h
src/include/gpxe/command.h
src/include/gpxe/device.h
src/include/gpxe/efi/efi.h
src/include/gpxe/eisa.h
src/include/gpxe/errortab.h
src/include/gpxe/features.h
src/include/gpxe/gdbstub.h
src/include/gpxe/image.h
src/include/gpxe/init.h
src/include/gpxe/isa.h
src/include/gpxe/isapnp.h
src/include/gpxe/mca.h
src/include/gpxe/netdevice.h
src/include/gpxe/open.h
src/include/gpxe/pci.h
src/include/gpxe/process.h
src/include/gpxe/resolv.h
src/include/gpxe/sanboot.h
src/include/gpxe/settings.h
src/include/gpxe/tables.h
src/include/gpxe/tcpip.h
src/net/udp/dhcp.c

index 667f2dedf65504c51b4afa019ace7a5a3e333dc2..33e341d2dcc3c3d7e0e0721f27a1d903bc316f2f 100644 (file)
@@ -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 );
 
index 61f94cdea535d046cc2b59faf8822035126faf33..83a56d3c0a6a690f89b0f8b4240294f650db217d 100644 (file)
@@ -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 );
index fd36cd5b8d4ced18cd2af3bcc1af0b234d1cd47e..93c53adbfbff0209f5794cd45629f38d2b9f19e0 100644 (file)
@@ -86,7 +86,7 @@ struct console_driver {
 };
 
 /** Console driver table */
-#define CONSOLES "consoles"
+#define CONSOLES __table ( struct console_driver, "consoles" )
 
 /**
  * Mark a <tt> struct console_driver </tt> 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 */
 
index 5bdd1d56a1294014475651f44de306eac92c742f..7dcc77930625ad96965a95c79c563a064c17435c 100644 (file)
@@ -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;
 
index ee270dfdd637480d2e6cd133e7282c8b86f75739..39bed477755a1082c55b9f35e20b58d05d5b009a 100644 (file)
@@ -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 */
index bcc848aad159b31bdae834ba25d275f9a0266535..9017f9b9d7cf3c286504a3bbd2549e5fa2d54b45 100644 (file)
@@ -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 */
index c44e09cb1846b905d9dd33fc16d6ac352d67df5d..1f5b8856345f85eca4b0ac15df33f15ecf5eeb0d 100644 (file)
@@ -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
  *
index 1f3a9caa128e553e5246f44179666312142ec9cb..cde46af2f457e06ddfe86d57ff76f7c58e8802ad 100644 (file)
@@ -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 );
 
index 8e746f029269f9dbffd742ad62ed9b473644e767..d519f68ce5c3e41f88732bf29d1a0c026372a385 100644 (file)
@@ -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 */
index e979ee7ca8e57c59fce1440c79c35550b4853bb7..8d3977cb6a02772ff42d31a6c3c116e9e6eba8fa 100644 (file)
 /** @} */
 
 /** 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 )                                     \
index 624b15f7a00af56950ff378c1ebabe7cdb234b80..2e2c4dab406342e36ad1072a486b71a3025fca79 100644 (file)
@@ -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
index cb3bb361bf1b20548f53bbc08e92c812a0a108ef..b40474671417b8dcfc580db0cccf32013bf4a320 100644 (file)
@@ -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;
 
index 9ce56d77fcc79e21e83cfdcbf7e4e3a8fec95e8d..5a51b033f2d6217fda24758a1b6e83ba26ce7778 100644 (file)
@@ -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
  *
index 947cb986fef0b79886efeb1411af6dd2b876202e..458d754be922b70003791c0f5383422f204520b1 100644 (file)
@@ -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
index 4a7c781751f115892691e33679b19e01dae2bf76..633f7b0c57c2955462e4ce8f59b904d272ecc6ae 100644 (file)
@@ -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;
 
index d1f38c8ed7e737c90a4fe1212fdcac13ce202bbd..d276acfe6cc9e28027533e5b24c03c623a295980 100644 (file)
@@ -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
index 9d1c9d07c5eea8f66788b75f621a94001edc3930..e4f5ed36ab7062398644ba23e8dd417278229cb2 100644 (file)
@@ -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;
index 69a8b3f442a19ac4e53071e65036935be390878f..61fb0ef519814b9a9c0ed3598cd1cdcd8cd488af 100644 (file)
@@ -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,
index 86bd8f79e6be9dd6f85f2a6666a5bece7c04266b..b13c01ac9d17f59c9edcd9827a4cc098778b8add 100644 (file)
@@ -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 )
index 705c9f6766c2e0d6aa7190f34c6dba3d9f03538a..42e4dfa6a32c2babcffe95d0d2af5601dd4d71d1 100644 (file)
@@ -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 */
index d276522e574b03ca160264b49054348729771287..81207d28eea20479aab39d7f853ddccf92481e25 100644 (file)
@@ -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 );
index 68fd0b9beccde2cd740bb88c53ab6a0b1390087f..05a3ddf0fc40a95481571226a0c2dbd528df05cb 100644 (file)
@@ -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 */
index 4f7f98efa32e7e3778a02908f359dc45d950ab98..c25b6ad47231d5b73a126ca175cf5c6f513353a7 100644 (file)
@@ -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
index 5d4a43c541fc75e292481ec3a6f8462f099f4978..a0b6f11374b23141c5d7fbfa8d37212252152d87 100644 (file)
@@ -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".
  *     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
  *
  *   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 ();
  *     }
 #define __attribute__( x )
 #endif
 
-#define __table_str( x ) #x
-#define __table_section( table, idx ) \
-       __section__ ( ".tbl." table "." __table_str ( idx ) )
+/**
+ * Declare a linker table
+ *
+ * @v type             Data type
+ * @v name             Table name
+ * @ret table          Linker table
+ */
+#define __table( type, name ) ( type, name )
 
-#define __table_section_start( table ) __table_section ( table, 00 )
-#define __table_section_end( table ) __table_section ( table, 99 )
+/**
+ * Get linker table data type
+ *
+ * @v table            Linker table
+ * @ret type           Data type
+ */
+#define __table_type( table ) __table_extract_type table
+#define __table_extract_type( type, name ) type
 
-#define __natural_alignment( type ) __aligned__ ( __alignof__ ( 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
 
 /**
- * Linker table entry.
+ * Get linker table section name
  *
- * Declares a data structure to be part of a linker table.  Use as
- * e.g.
+ * @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
+ *
+ * @v table            Linker table
+ * @ret start          Start of linker table
  *
- * Return the start of a linker table.  Use as e.g.
+ * Example usage:
  *
  * @code
  *
- *   struct frobnicator *frobs =
- *     table_start ( struct frobnicator, "frobnicators" );
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
  *
- * @endcode
+ *   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" )
  *
- * @endcode
+ *   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 ) {
  *     ...
  *   }
  *
  *
  */
 #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 ) {
  *     ...
  *   }
  *
  *
  */
 #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 */
index 5200b5ed5de50d5eb44c1f2727be29b0d30b4088..544b9fef5ad8576acf8c83411b252849fda94130 100644 (file)
@@ -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,
index 0f44599569baf84b1d573e462c147b76dc804ba2..97e64617fb5c019919cbec3c4726508f2a76ed3c 100644 (file)
@@ -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",