S32K148 switch to supervisor mode and back

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

S32K148 switch to supervisor mode and back

跳至解决方案
2,068 次查看
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 解答
1,885 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

Please see this thread:

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

Thanks,

BR, Daniel

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,886 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

Please see this thread:

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

Thanks,

BR, Daniel

0 项奖励
回复
1,885 次查看
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 项奖励
回复
1,885 次查看
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.