PPC 405 Register Model
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?
Thanks,
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
It's in the specs ABI/EABI ([Embedded] Application Binary Interface). All compilers I have run across support EABI by default.
http://www.esofta.com/softspecs.html
gvb
Quoted 7 lines · you
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?
Thanks,
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
Quoted 5 lines · Jim Duey
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. For example, look at include/asm-ppc/atomic.h and you can find documentation of inline assembly at:
http://gcc.gnu.org/onlinedocs/gcc-2.95.2/gcc_4.html#SEC93
-Frank
--
Frank Rowand <[email protected]>
MontaVista Software, Inc
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
Quoted 10 lines · Frank Rowand
Quoted 5 lines · Jim Duey
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
[email protected] 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/
Quoted 16 lines
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");
Quoted 1 line
The "r0" at the tail end of the asm tells gcc that r0 is used.
1) You use r0 as a temporary value, so you have to tell gcc that r0 is being clobbered.
2) You specified that &tb can be placed in a "r" register class which includes r0. If you change the register class to "b", then &tb would select any register that can be used as a base address, which is any general register *except* r0.
3) Since you are modifying the value in memory at the address contained in tb, you should add "memory" to the clobber list so the compiler won't assume that any memory values cached in registers are valid.
You could rewrite this asm statement as:
{ unsigned int tmp1, tmp2, tmp3;
asm volatile("0:; mtfbu %0; mtfb %1; mtfb %2; cmp %0,%2; bne 0b; "
"stw %0,0(%4); stw %1,4(%4)"
: "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3)
: "b" (&tb)
: "memory");
}All the output operands (tmp1/2/3) need to have "=" in the descriptor to indicate that they are output values, and also need "&" to indicate that they can not be shared with the intput value since these are clobbered in the asm template before the input operand is consumed.
--
Peter Barada [email protected] Wizard 781-852-2768 (direct) WaveMark Solutions(wholly owned by Motorola) 781-270-0193 (fax)
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/