PC-relative branches allow code to run anyplace in memory, but they have drawbacks. One problem is that they only work within the current piece of code: since the current code doesn't know where the system libraries will be in memory, it can't use PC-relative branches to get there. Another drawback is that PC-relative branches have a limited range on the PowerPC: +/-8M instructions (+/-32MB) for unconditional branches, and +/-8K instructions (+/-32KB) for conditional branches.
Another problem involves locating data: since the code doesn't know where it will be loaded into memory, it doesn't know where its global variables will be stored. The code must be told how to locate its own variables in memory.

The PowerPC runtime architecture solves this problem by creating a Table Of Contents (TOC) for each fragment. (A fragment is a piece of executable code: an application, import library, or other collection of functions.) The Table of Contents is a collection of pointers that the code uses to locate its static data (including global variables), pointers to external functions, and imported globals from other fragments.
By the way, "Table Of Contents" is a somewhat misleading name, as it makes people think that a fragment's TOC describes the contents of that fragment. A better metaphor might be a "bibliography" or an "address book", as the TOC lists the globals and external functions that a fragment uses, not the fragment's contents. Also, a TOC's contents is private to its owner --- no code is expected to look in or modify another routine's TOC.
Some TOC facts

Reference:
https://imcs.dvfu.ru/lib.int/docs/Hardware/intro_to_ppc/ppc4_runtime4.html
No comments:
Post a Comment