mirror of
https://github.com/ipxe/ipxe
synced 2025-12-26 09:32:33 +03:00
[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:
@@ -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 */
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 ) \
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user