This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
SPR access
- From: David Brown <david at westcontrol dot com>
- To: Tran Tu Truong <tutruong0412 at gmail dot com>, <gcc-help at gcc dot gnu dot org>, <gcc at gcc dot gnu dot org>
- Date: Fri, 8 Jul 2016 18:07:36 +0200
- Subject: SPR access
- Authentication-results: sourceware.org; auth=none
- References: <CAM-oYiabzs67RRpdpM+dFTOL3pmjgW=jjqQHa2Mk+vCiFLEHFw@mail.gmail.com>
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--
>