Parcourir la source

[tables] Add table_index()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown il y a 14 ans
Parent
révision
da123eada4
1 fichiers modifiés avec 25 ajouts et 0 suppressions
  1. 25
    0
      src/include/ipxe/tables.h

+ 25
- 0
src/include/ipxe/tables.h Voir le fichier

@@ -308,6 +308,31 @@ FILE_LICENCE ( GPL2_OR_LATER );
308 308
 	( ( unsigned int ) ( table_end ( table ) -			\
309 309
 			     table_start ( table ) ) )
310 310
 
311
+/**
312
+ * Get index of entry within linker table
313
+ *
314
+ * @v table		Linker table
315
+ * @v entry		Table entry
316
+ *
317
+ * Example usage:
318
+ *
319
+ * @code
320
+ *
321
+ *   #define FROBNICATORS __table ( struct frobnicator, "frobnicators" )
322
+ *
323
+ *   #define __frobnicator __table_entry ( FROBNICATORS, 01 )
324
+ *
325
+ *   struct frobnicator my_frob __frobnicator = {
326
+ *      ...
327
+ *   };
328
+ *
329
+ *   unsigned int my_frob_idx = table_index ( FROBNICATORS, &my_frob );
330
+ *
331
+ * @endcode
332
+ */
333
+#define table_index( table, entry )					\
334
+	( ( unsigned int ) ( (entry) - table_start ( table ) ) )
335
+
311 336
 /**
312 337
  * Iterate through all entries within a linker table
313 338
  *

Chargement…
Annuler
Enregistrer