SPR access

tutruong0412@gmail.com tutruong0412@gmail.com
Wed Jul 13 14:39:00 GMT 2016


Hi,

Thank you for your answer.
It is very useful for me.

Best regards;

Truong TT

> On Jul 8, 2016, at 11:07 PM, David Brown <david@westcontrol.com> wrote:
> 
> Hi,
> 
> (You have something wrong with your emails - the subject for your post
> had a copy of most of the body of the email.  I have changed it to
> something smaller.)
> 
> You can't use a function argument for the number of the SPR, because the
> assembler requires the SPR at assembly time to generate the full mtspr
> instruction.  My solution was to use a macro for this, rather than a
> function (even a static inline function won't work):
> 
> #define readSpr(sp) ({ uint32_t res; \
>        asm volatile (" mfspr %[res], %[spr] " : \
>        [res] "=r" (res) : \
>        [spr] "i" (sp) ); \
>        res; })
> 
> #define writeSpr(sp, va) \
>        asm volatile (" mtspr %[spr], %[val] " : \
>        : \
>        [spr] "i" (sp), [val] "r" (va) )
> 
> 
> mvh.,
> 
> David
> 
> 
> 
>> On 08/07/16 16:16, Tran Tu Truong wrote:
>> Dear Mr/Ms;
>> 
>> I am Truong, working at Vietnam human engineering in Vietnam.
>> Now, I am using D32 Design Studio for programming MPC5777C micro
>> controller (GNU C Compiler 4.9). I've already made a sample inline asm
>> code in .C file ase bellow:
>> void set_spr ( uint32_t spr_num, uint32_t val )
>> {
>> asm volalatile ("mtspr %0, %1"
>> :
>> :"r"(spr_num), "r"(val)
>> );
>> }
>> This code does not work correct (It should work but not work). I found
>> out the constraints operands [:"r"(spr_num),] is not correct. I thinks
>> it better if spr_num is be referred as a constant not a register ( ex:
>> mtspr 120, val ). But I don't know how to revise.
>> I also referred on
>> https://gcc.gnu.org/onlinedocs/gcc/Constraints.html#Constraints
>> about PowerPC but I cannot understand clearly.So, could you please
>> help me to explain about that?
>> If you have the instruction about "constraints for asm operands" for
>> MPC5777C micro controller, please provide me.
>> 
>> Thank you.
>> --Tran Tu Truong--
> 



More information about the Gcc-help mailing list