Cortex M0+ using unprivileged asses level without MPU

Hello,

Cortex M0+ and most all other Cortex M devices support Privileged and Unprivileged access level. Unprivileged level does not require MPU to limit access to critical registers.

Let’s say my application requires all user tasks to be unprivileged and only kernel and special drives/handlers(auto) to be privileged.

It looks like kernel only supports Unprivileged when MPU is enabled. This is quite an overhead for simple use case above.

Is it possible to have simpler support for unprivileged access:

  • user code is unprivileged possibly selected at the task level
  • kernel code is privileged

As long as Cortex M port restores CONTROL the only requirement would be SVC wrapper call for kernel APIs from user space, which can be detected inside the kernel port by evaluating CONTROL.

Any suggestions or maybe kernel already supports this and I am missing configuration?

Regards,
Eugene

This is an interesting use case. We currently support unprivileged level only with MPU. What you describe would require taking pieces from MPU port. You want to limit me tasks’ access to critical registers?

Hi Gaurav,

This is very common use case for efficient systems. SW is usually split into trusted and non-trusted and trusted application SW is combined with RTOS (which better be trusted). The requirements to MPU are relaxed and most of the time it is static MPU set up.

Let’s assume I create wrapper macro to handle privileged(trusted) level for all RTOS API calls like this (pseudo code):

#define APPLSVC_PRIV_FUNC(api_func, …)
({
Switch2priv();
api_func(…)
Restore();
})

Install custom SVC handler to intercept non RTOS SVCs and forward RTOS ones. Fix configASSERT() in port.c

Is there anything else I need to look into to make this work?

Regards,
Eugene

I assume you are talking about the SVC to program CONTROL register to raise privilege.

I think you would also need to store and restore CONTROL register as part of task context, right?