difference between user and supervisor mode?

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

difference between user and supervisor mode?

2,767 Views
JeorgeB
Contributor III

Hi, 

 

what is difference between user and supervisor mode?

e.g. page 542 (S32K1xx RM):

" The RCM registers can be written only in supervisor mode. Write accesses in user mode are blocked and will result in a bus error. "

can we switch between them in runtime dynamically?

 

Thanks.

0 Kudos
3 Replies

2,755 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi JeorgeB,

The device is running in Supervisor (privileged) mode out of reset. It is controlled by nPRIV bit in CONTROL register (it is core register, see ARM documentation for more details).

If you need to switch to User mode, just set the nPRIV bit in CONTROL register

// switch to User (unprivileged) mode
 __asm__("mov r0, #0x01");
 __asm__("msr control, r0"); // nPRIV = 1‍‍‍


And to switch it back, you need to do it in SVC handler

// make a supervisor call (SVC) to transfer control to privileged software
 __asm__("svc #0x00");

void SVC_Handler(void){
 // switch to Supervisor (privileged) mode
 __asm__("mov r0, #0x00");
 __asm__("msr control, r0"); // nPRIV = 0
}‍‍‍‍‍‍‍‍

 

Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

2,752 Views
JeorgeB
Contributor III
Thanks for your kind reply, where is benefit or application of using supervisor mode? (assume we do not implement any OS on MCU)
0 Kudos

2,725 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Sorry for my late reply!
I am not very familiar with this part, you can refer: Processor mode and privilege levels for software execution
ARM Cortex related question can also ask in community.arm.com