difference between user and supervisor mode?

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

difference between user and supervisor mode?

5,345 次查看
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 项奖励
回复
3 回复数

5,333 次查看
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.
-------------------------------------------------------------------------------

5,330 次查看
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 项奖励
回复

5,303 次查看
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