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
解決済! 解決策の投稿を見る。
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
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.