facing issue with assembly instruction mtmsr

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

facing issue with assembly instruction mtmsr

1,570 Views
lakshmanank
Contributor II

Hi All

I am facing some issue with mtmsr assembly instruction while trying to write into msr register of MPC8641D.

below is my code which is compiling successfully but get runtime error as illegal instruction.

register long toMSR;
register long fromMSR;

asm ("mfmsr %0;"

              : "=r" (fromMSR)  // output operand

              );

printf("after mfmsr");

asm("mtmsr %0;"

           : "r" (toMSR) // input operand

         );

printf(" after mtmsr");

Output:

after mfmsr

illegal instruction -- error

what could be the possible error in the above code?

is the syntax is correct?
c

5 Replies

976 Views
hwrobel
NXP Employee
NXP Employee

Your code looks as if it is Linux user space.

mtmsr is a privileged instruction. A Linux user process is not allowed to mess with mtmsr directly. This is for the kernel.

Heinz

976 Views
lakshmanank
Contributor II

Hi Marius

I am using Buildroot cross compiler for MP8641HPCN architecture.

I am not using any Code Warrior. I am just building an userspace application and trying

in my board loaded with linux.

Hi Heinz

Thanks for your reply. So You mean I dont have any write access from userspace to change the MSR.

Is my understanding correct??

Thank you

Lachu

0 Kudos

976 Views
hwrobel
NXP Employee
NXP Employee

Correct. You can’t execute privileged instructions in user mode. Check, e.g., the e600 documentation and the Power ISA 2.06 for details.

0 Kudos

976 Views
lakshmanank
Contributor II

Hi Heinz

As you told me I understood that I cannot use msmtr instruction in userspace. I am now writing the msr register in uboot initialization and verifying what I have written. I am trying to write an application to run on uboot. prior to that I tried running the hello_world demo example in uboot. I am facing issue with loads command. after going through some web sources I understood it may be a problem in load address.

Now I want to know how should I separate the application from compiling along with uboot so that i dont want to compile uboot everytime I want to compile my application.

or do we have any other replacement to wrtie into MSR and other special purpose registers in userspace application(using movw instruction).

Regards

Lakshmanan K

0 Kudos

976 Views
marius_grigoras
NXP Employee
NXP Employee

Hi,

Please find below an example about using mtmsr instruction with MW compiler from CW Classic:

asm void __reset(void)

{

  //

  //   Enable altivec, floating point and machine check exception

  //

  lis r3, 0x0200

  ori r3, r3, 0x3000

  mtmsr r3

  b __start

}

What toolchain/compiler are you using? Can you tell me please also your CW version?

Regards and thank you,

Marius

0 Kudos