This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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: sigh... newlib startup


On 15 September 2006 17:13, Matt Gessner wrote:

> I have no OS, and am trying to link in and run newlib for an MPC8245
> (603e).
> 
> I'm using my own linker script, but apparently the combination of things
> I'm doing isn't working right at all.
> 
> First, when I link crt0.o from libgloss/rs6000 and call _start, it does
> all this stuff to try to set up the relocation tables (I guess that's
> what it's doing).  It crashes right before it calls main() because it's
> somehow using all the wrong offsets into where it THINKS things should
> be.  So I'm assuming I have a link error here.

   Seems likely; I'd guess it's a matter of LMA vs. VMA.

> Second, if I take out crt0.o and handle clearing bss myself, things
> still don't work because apparently functions like sprintf() are going
> to refer to that table anyway, and since it's not set up, it's all
> garbage.

  Yes, there's no simple way to bypass the CRT initialisation and still have
complex stuff like sprintf work.  Some of the very basic functions might be
ok, but I can't advise you to try it, it would be an inherently fragile and
risky solution.
 
> ARGH!
> 
> Can someone point me to some documentation, please, that will tell me
> how to set all this up, including using my own linker file?  The linker
> file is necessary because I need to put all the ROMable sections into
> order starting at 0xFF000000, and then copy them into RAM later.
> 
> I've searched all over Google and the mail archives for information on
> how to do this, but I've not been able to find anything on how this
> should all be organized to make it work.

  Read up on LMA and VMA in the ld docs.  Section 3.1, "Basic linker script
contents" says ...

"    Every loadable or allocatable output section has two addresses.  The
first is the "VMA", or virtual memory address.  This is the address the
section will have when the output file is run.  The second is the
"LMA", or load memory address.  This is the address at which the
section will be loaded.  In most cases the two addresses will be the
same.  An example of when they might be different is when a data section
is loaded into ROM, and then copied into RAM when the program starts up
(this technique is often used to initialize global variables in a ROM
based system).  In this case the ROM address would be the LMA, and the
RAM address would be the VMA.   "

  That sounds like just what you need, but I haven't written linker scripts
with separate LMA and VMA myself, so you may have to do some experimentation
to get the syntax etc. correct.  See also section 3.6.8.2, "Output Section
LMA" and 3.6.3, "Output Section Description".

> I'd really like to make this work, but I need a bit more information as
> to how things are organized and fit together.

  We're slightly outside my experience here, but I hope this helps.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


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