This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: SPR access
- From: David Brown <david at westcontrol dot com>
- To: <tutruong0412 at gmail dot com>
- Cc: "<gcc-help at gcc dot gnu dot org>" <gcc-help at gcc dot gnu dot org>, "<gcc at gcc dot gnu dot org>" <gcc at gcc dot gnu dot org>
- Date: Wed, 13 Jul 2016 16:56:52 +0200
- Subject: Re: SPR access
- Authentication-results: sourceware.org; auth=none
- References: <CAM-oYiabzs67RRpdpM+dFTOL3pmjgW=jjqQHa2Mk+vCiFLEHFw@mail.gmail.com> <577FCFC8.3050604@westcontrol.com> <139C00C1-5E7B-4A57-B0BF-A470C8CDCED0@gmail.com>
Hi,
No problem - helping out is one way users can contribute to the gcc
community, to save the gcc developers a little effort.
Next time, however, keep questions like this on the gcc-help mailing
list - it is for asking for help with using gcc. The gcc@gcc.gnu.org
mailing list is for development of the compiler itself.
mvh.,
David
On 13/07/16 16:39, tutruong0412@gmail.com wrote:
> 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--
>>