How to make S32K146 M4 Core user mode and supervisor mode switching?

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

How to make S32K146 M4 Core user mode and supervisor mode switching?

2,654 次查看
paulzhou
Contributor II

Dear Sir 

      How to make S32K146 M4 Core user mode and supervisor mode switching?

      Do you have demo code for this case? or reference application document ?

      Do S32K146 MCAL must do user mode and supervisor mode switching to meets functional security?

     Thank you!

标签 (1)
2 回复数

2,198 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,
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
}

Unfortunately, I’m not familiar with MCAL.
Could you please create a service ticket?

https://community.nxp.com/docs/DOC-329745 

Regards,
Daniel

2,199 次查看
paulzhou
Contributor II

Dear Daniel
     Thank you for your help and this problem is solved

0 项奖励
回复