c - How iPXE executes functions without calling its names -


in main.c, calls initialize() , startup(). inside each of these functions in init.c, loops through table contains registered functions , calls them:

void startup ( void ) {     struct startup_fn *startup_fn;      if ( started )         return;      /* call registered startup functions */     for_each_table_entry ( startup_fn, startup_fns ) {         if ( startup_fn->startup )             startup_fn->startup();     }      started = 1; } 

i don't know registered functions are, according comment.

startup_fns:

#define startup_fns __table ( struct startup_fn, "startup_fns" ) 

__table:

#define __table( type, name ) ( type, name ) 

__table end of can into. comment says "declare linker table". how can functions?

there more in table.h, such __table_entry, table_start... table come from? entries? mean by:

#define table_start( table ) __table_entries ( table, 00 ) 

what 00 mean here?

please help. want understand. thanks.

(i'm person wrote code in question.)

the linker script instructs linker arrange sections ".tbl.*" in alphabetical order. __table_entry etc macros used place structures these sections. easiest way understand @ linker map, can produce using e.g. "make bin/rtl8139.rom.map":

.tbl.init_fns.00             0x000000000001784c        0x0 bin/blib.a(init.o) .tbl.init_fns.01             0x000000000001784c        0x4 bin/blib.a(malloc.o)             0x000000000001784c                heap_init_fn .tbl.init_fns.04             0x0000000000017850        0x4 bin/blib.a(pxe_call.o)             0x0000000000017850                pxe_init_fn .tbl.init_fns.04             0x0000000000017854        0x4 bin/blib.a(settings.o)             0x0000000000017854                builtin_init_fn .tbl.init_fns.04             0x0000000000017858        0x4 bin/blib.a(smbios_settings.o)             0x0000000000017858                smbios_init_fn .tbl.init_fns.04             0x000000000001785c        0x4 bin/blib.a(process.o)             0x000000000001785c                process_init_fn .tbl.init_fns.05             0x0000000000017860        0x4 bin/blib.a(embedded.o)             0x0000000000017860                embedded_init_fn .tbl.init_fns.99             0x0000000000017864        0x0 bin/blib.a(init.o) 

here can see various structures (heap_init_fn, pxe_init_fn, smbios_init_fn) etc. have been placed consecutively in final image, sorted initialisation order (01=init_early, used heap_init_fn in malloc.c; 04=init_normal, used smbios_init_fn in smbios_settings.c etc).

the __table_start , __table_end macros in init.c produce zero-length arrays placed in .tbl.init_fns.00 , .tbl.init_fns.99; these can used code in init.c identify start , end of table has been constructed linker.

hope helps!

michael


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -