Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help me understand iPXE code
2013-05-16, 10:09
Post: #4
RE: Help me understand iPXE code
(2013-05-16 08:34)Rickert Wrote:  
  • What's this technique called?
  • How to generate a similar table and use it in my code? Are the table names auto-generated or declared?
  • What's the reason for doing this? Isn't it easier to create an array of function pointers?

I'm not aware of this technique having a name. It's something I created, inspired by the way that the old Etherboot code handled the PCI driver list. The concept of vector-valued macros as used in tables.h is, as far as I am aware, an original idea.

If your code is licensed under GPL then you can include iPXE's tables.h directly. You can see examples of how to declare a specific table in e.g. init.h, and examples of how to declare table entries in any file containing e.g. __startup_fn. The only other part you'll need is the linker script directive to keep all table entries and sort them alphabetically:

Code:
KEEP(*(SORT(.tbl.*)))

The reason for doing this is that allows the contents of the array to be determined at link time rather than compile time. For example, both bin/realtek.rom and bin/intel.rom can be generated from the exact same compiled code simply by adjusting the options passed to the linker. Using an array of function pointers would require something like:

Code:
struct pci_driver * pci_drivers[] = {
#ifdef REALTEK
  &realtek_driver,
#endif
#ifdef INTEL
  &intel_driver,
#endif
#ifdef ....
  ....
  ....
#endif
}

See http://dox.ipxe.org/ifdef_harmful.html for some more detailed background.

Michael
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Help me understand iPXE code - mcb30 - 2013-05-16 10:09



User(s) browsing this thread: 1 Guest(s)