This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: MIPS question: _gp = (. + 0x8000);


Michael Anburaj wrote:
Hi,

I have a question regarding the following line found in a lot of MIPS linker scripts:

_gp = (. + 0x8000);

_gp gets loaded into $gp. How does this value ‘_gp’ relate with access to .sdata & .sbss session using $gp?

Access to stuff in sdata/sbss uses different instructions that are more efficient for small amounts of data. But the tradeoff is having to use a fixed base register for accessing them. That is $gp. GCC/GAS generate relocs relative to the _gp symbol, which the linker munges appropriately so that as long as $gp points to _gp everything works.


Why is 0x8000 added (to the foot of .sdata section)? To Place $gp halfway in the 64KB $gp accessible space??

Correct. The offsets that GCC uses are signed.


Can you point to a detailed material on this?

Here's the GCC info file about the -G argument on MIPS:


`-G NUM'
     Put global and static items less than or equal to NUM bytes into
     the small data or bss sections instead of the normal data or bss
     section.  This allows the assembler to emit one word memory
     reference instructions based on the global pointer (GP or $28),
     instead of the normal two words used.  By default, NUM is 8 when
     the MIPS assembler is used, and 0 when the GNU assembler is used.
     The `-G NUM' switch is also passed to the assembler and linker.
     All modules should be compiled with the same `-G NUM' value.


Jifl -- eCosCentric http://www.eCosCentric.com/ The eCos and RedBoot experts Visit us at Embedded World 2004, Nürnberg, Germany, 17-19 Feb, Stand 12-449 --["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine


-- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]