PPC 405 Register Model

Scott Anderson scott_anderson at mvista.com
Wed Oct 31 06:54:22 EST 2001


Frank Rowand wrote:
>
> Jim Duey wrote:
> >
> > I'm needing to do some inline assembly for the Walnut board running MVista's
> > Hard Hat Linux and I'm concerned about clobbering registers.  Can someone
> > point me to docs or source code that describes the register usage of HHL on
> > the 405GP?
>
> If you use variable names instead of hard coding register numbers you
> don't have to worry about clobbering registers.

FYI, I've seen gcc pass r0 as the register that a variable gets stored
in.  Because some PPC instructions treat r0 as a literal zero instead of
the value in r0, this can be bad.  To work around this, you just need
to tell gcc that the asm uses r0 and it won't pass you a parameter in
it.  Here's an example chunk of code:


	/* Get the Time Base.  Make sure that r0 is declared as used;
	 * otherwise it can be passed to me as %0 which doesn't work
	 * very well with stw.
	 */
	asm volatile ("0:; mftbu 3; mftb 4; mftbu 0; cmpw 3,0; bne 0b; "
		      "stw 3,0(%0); stw 4,4(%0)"
		      :: "r" (&tb): "r3", "r4", "r0");

The "r0" at the tail end of the asm tells gcc that r0 is used.

    Scott Anderson
    scott_anderson at mvista.com   MontaVista Software Inc.
    (408)328-9214               1237 East Arques Ave.
    http://www.mvista.com       Sunnyvale, CA  94085

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/





More information about the Linuxppc-embedded mailing list