]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[tables] Add table_index()
authorMichael Brown <mcb30@ipxe.org>
Mon, 26 Jul 2010 12:26:34 +0000 (13:26 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 3 Sep 2010 20:25:06 +0000 (21:25 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/tables.h

index 130486c67e009ed0e382d3a4a8bc8a1306fdf302..74d437537882a19d610a01dbe7f4e55a6d7cea18 100644 (file)
@@ -308,6 +308,31 @@ FILE_LICENCE ( GPL2_OR_LATER );
        ( ( unsigned int ) ( table_end ( table ) -                      \
                             table_start ( table ) ) )
 
+/**
+ * Get index of entry within linker table
+ *
+ * @v table            Linker table
+ * @v entry            Table entry
+ *
+ * Example usage:
+ *
+ * @code
+ *
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
+ *
+ *   #define __frobnicator __table_entry ( FROBNICATORS, 01 )
+ *
+ *   struct frobnicator my_frob __frobnicator = {
+ *      ...
+ *   };
+ *
+ *   unsigned int my_frob_idx = table_index ( FROBNICATORS, &my_frob );
+ *
+ * @endcode
+ */
+#define table_index( table, entry )                                    \
+       ( ( unsigned int ) ( (entry) - table_start ( table ) ) )
+
 /**
  * Iterate through all entries within a linker table
  *