Read PowerPC Machine State Register from C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read PowerPC Machine State Register from C

858 Views
ronjaeger
Contributor II

Using Power PC MPC5775B, how do I read the core Machine State Register from a C routine?  Other compilers have had intrinsic functions like __mfmsr() that returned the MSR value.  But I can't find the equivalent in S32DS.  I want to check the state of the EE bit (external interrupt disable).

0 Kudos
4 Replies

840 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @ronjaeger 

I used this in the past:

#define MFMSR() ({unsigned int rval; __asm__ volatile("mfmsr %0" : "=r" (rval)); rval;})
#define MTMSR(v) __asm__ volatile("mtmsr %0" : : "r"(v))

and then:

temp = MFMSR();
MTMSR(0x8000);

Regards,

Lukas

0 Kudos

827 Views
ronjaeger
Contributor II

Actually, when I use MFMSR(), it compiles without actual error, but I get this warning:
"warning (etoa:5848): GNU-style inline assembly detected. This feature is not supported."

Should I be concerned about this or just ignore the warning?

0 Kudos

819 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

That's interesting, I can't see such error on my side. If it works, there's probably no problem.

And I found one more version which can be used to access any SPR register, not only MSR:

 

#define stringify(s) tostring(s)
#define tostring(s) #s
#define mfspr(rn) ({unsigned int rval; __asm__ volatile("mfspr %0," stringify(rn) : "=r" (rval)); rval;})
#define mtspr(rn, v) __asm__ volatile("mtspr " stringify(rn) ",%0" : : "r" (v))

And then:

mtspr(570, content_of_MCSRR0);

mtspr(572, 0xFFFFFFFF); //clear all flags in MCSR register

Regards,

Lukas

0 Kudos

833 Views
ronjaeger
Contributor II

Thanks.  That seems to work.  (But see post about warning...)

0 Kudos