(Manually) relocate PPC code?
Hi,
I need to write some C code on PPC which must stay relocatable, resp. I must relocate it myself (all of code and data etc.). I'm using GNU tools.
This is for a standalone application, _NOT_ running under Linux.
Where can I find documentation about things like the format of the GOT etc., or ideally existing _simple_ (read: small) example code?
All hints, pointers, ideas appreciated - TIA!
Wolfgang
--
Software Engineering: Embedded and Realtime Systems, Embedded Linux
Phone: (+49)-8142-4596-87 Fax: (+49)-8142-4596-88 Email: [email protected]
Little known fact about Middle Earth: The Hobbits had a very sophi-
sticated computer network! It was a Tolkien Ring...
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 7 lines · Wolfgang Denk
Hi,
I need to write some C code on PPC which must stay relocatable, resp. I must relocate it myself (all of code and data etc.). I'm using GNU tools.
Quoted 6 lines
This is for a standalone application, _NOT_ running under Linux.
Where can I find documentation about things like the format of the GOT etc., or ideally existing _simple_ (read: small) example code?
All hints, pointers, ideas appreciated - TIA!
It's not terribly small, but - you REALLY should read ld.so.1's source. There may be more information in the ABI document floating around, too.
Dan
/--------------------------------\ /--------------------------------\
| Daniel Jacobowitz |__| SCS Class of 2002 | | Debian GNU/Linux Developer __ Carnegie Mellon University | | [email protected] | | [email protected] | \--------------------------------/ \--------------------------------/
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 6 lines · Wolfgang Denk
Hi,
I need to write some C code on PPC which must stay relocatable, resp. I must relocate it myself (all of code and data etc.). I'm using GNU tools.
Do you know about the -mrelocatable gcc and gas option ? Granted that it generates slightly larger code, but it helps a lot to solve this kind of problems.
Quoted 1 line
This is for a standalone application, _NOT_ running under Linux.
Fine.
Quoted 2 lines
Where can I find documentation about things like the format of the GOT etc., or ideally existing _simple_ (read: small) example code?
Well, prepboot does this (with many more things): download a pristine 2.2.12 and apply the mvme2600 patches that you'll find at ftp://vlab1.iram.es/pub/linux-2.2/. You'll then find a medium size example in arch/ppc/prepboot. Actually it could be used to load a standalone program or be integrated with it (except that you'll have to modify the Makefile and the linker script which imports a couple of kernel symbols).
Actually prepboot may even be more complex than what you need since it first relocates itself whereever it happens to be loaded by firmware and then analyzes the memory map and setup of the machine before moving itself and relocating again. The part between both relocations is easy to break (there are many things you can't do like accessing the bss since it may extend past the end of memory or whatever, and you can't easily use pointers since they would not be relocated properly in the second pass), but once the final relocation is done, the environment is reasonably friendly (don't expect a full libc either but console I/O and a simple memory management layer are available).
No interrupts however, this is left as an exercise for the reader. The MMU exception handlers can be used as a starting point (especially the only part which must be written in assembler for entry and exit).
Quoted 1 line
All hints, pointers, ideas appreciated - TIA!
Hope this helps....
Gabriel.
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/