S32K148 switch to supervisor mode and back

cancel
Showing results for 
Search instead for 
Did you mean: 

S32K148 switch to supervisor mode and back

Jump to solution
494 Views
michael_kirches
Contributor III

Dear NXP community,

I have a question about application modes on the S32K148.

To test some particularities in our current application, it would be helpful to be able to check, if the application is currently running in user or supervisor mode and to switch to supervisor mode if required. These checks are related to CAN and a third party CAN stack we have to integrate.

We want to check, if the CAN stack tries to access registers which may be protected, we want to achieve something similar to this pseudo-code function:

Function ReadFromProtectedRegister(Pointer_To_Address)
VAR content
IF Application in User Mode THEN
   Switch to Supervisor Mode
   content = Content of memory at Pointer_To_Address
   Switch back to User Mode
ELSE
   content = Content of memory at Pointer_To_Address
ENDIF
RETURN content
END‍‍‍‍‍‍‍‍‍‍‍

Could anyone please give us a hint on how to achieve this? Thanks a lot in advance.

Regards,

Michael

1 Solution
311 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

Please see this thread:

https://community.nxp.com/thread/480213 

Thanks,

BR, Daniel

View solution in original post

0 Kudos
3 Replies
312 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

Please see this thread:

https://community.nxp.com/thread/480213 

Thanks,

BR, Daniel

View solution in original post

0 Kudos
311 Views
michael_kirches
Contributor III

Hi Daniel,

thanks for the link, but how would I check, if the application currently runs in user or supervisor mode? Unfortunatelly I am not too familiar with assembler instructions.

BR,

Michael

0 Kudos
311 Views
michael_kirches
Contributor III

I solved the question on how to check for privileged/unprivileged mode myself. In case anyone else stumbles accross the same question:

register int r0 __asm__("r0");

__asm__("mrs r0, control"); // nPRIV = 1

printf("R0 is: %d", r0);

This will move co-processor register control to register r0 and print the current value of r0.