Callisto4Bootloader: include/c4_privilege_modes.h File Reference

Callisto4Bootloader

Macros | Enumerations | Functions
c4_privilege_modes.h File Reference

Provide mechanisms to specify which stack to use and for the processor to operate in Unprivileged mode and access Privileged mode. More...

Go to the source code of this file.

## Macros

#define | SVC_OPS
| SVC operations. More...
#define | CALLISTO_SVC(op) C4_SVC_##op,
#define | C4_PRINT(...) printf(__VA_ARGS__)
| Wrapper to call print as a privileged operation. More...

## Enumerations

enum | C4_SVC_Op_t { C4_SVC_MAX_OPS }
| Enumeration of operations performed by SVC. The operation IDs need to fit into a uint8_t. More...

## Functions

void | C4_enterUnprivileged ()
| Set the CONTROL register for Unprivileged level. More...
void * | C4_executePrivileged (C4_SVC_Op_t op,...)
| Execute operation in privileged mode. More...

## Detailed Description

Provide mechanisms to specify which stack to use and for the processor to operate in Unprivileged mode and access Privileged mode.

Copyright
  2020 Remsdaq Ltd.

The iMXRT1062 processor has two processor modes and two privilege levels. There are two stacks available for use depending on the mode.

From the ARM® Cortex®- M7 Devices Generic User Guide(DUI046B, 2015)

2.1.1 Processor mode and privilege levels for software execution

The processor modes are:

Thread mode Used to execute application software. The processor enters Thread mode when it comes out of reset.

Handler mode Used to handle exceptions. The processor returns to Thread mode when it has finished all exception processing.

The privilege levels for software execution are:

Unprivileged The software:

- Has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
- Cannot access the system timer, NVIC, or system control block.
- Might have restricted access to memory or peripherals.

Unprivileged software executes at the unprivileged level.

Privileged The software can use all the instructions and has access to all resources.

Privileged software executes at the privileged level.

In Thread mode, the CONTROL register controls whether software execution is privileged or unprivileged, see CONTROL register on page 2-9. In Handler mode, software execution is always privileged.

Only privileged software can write to the CONTROL register to change the privilege level for software execution in Thread mode. Unprivileged software can use the `SVC` instruction to make a supervisor call to transfer control to privileged software.

2.1.2 Stacks

The processor uses a full descending stack. This means that the stack pointer holds the address of the last stacked item in memory. When the processor pushes a new item onto the stack, it decrements the stack pointer and then writes the item to the new memory location. The processor implements two stacks, the main stack and the process stack, with a pointer for each held in independent registers, see Stack Pointer on page 2-4.

In Thread mode, the CONTROL register controls whether the processor uses the main stack or the process stack, see CONTROL register on page 2-9. In Handler mode, the processor always uses the main stack. The options for processor operations are:

Summary of processor mode, execution privilege level, and stack use options
Processor mode | Used to execute | Privilege level for software execution | Stack used
--- | --- | --- | ---
Thread | Applications | Privileged or unprivileged (a) | Main stack or process stack (a)
Handler | Exception handlers | Always privileged | Main stack

a. See CONTROL register on page 2-9.

In an OS environment, the vendor recommends that threads running in Thread mode use the process stack and the kernel and exception handlers use the main stack.

Date
  8 Jul 2020

Author
  Dan Smithers dwhs@.nosp@m.rems.nosp@m.daq.c.nosp@m.om

Definition in file c4_privilege_modes.h.

## Macro Definition Documentation

## ◆ C4_PRINT

#define C4_PRINT | ( |  | ... | ) | printf(__VA_ARGS__)

Wrapper to call print as a privileged operation.

Definition at line 109 of file c4_privilege_modes.h.

## ◆ CALLISTO_SVC

#define CALLISTO_SVC | ( |  | op | ) | C4_SVC_##op,

Definition at line 101 of file c4_privilege_modes.h.

## ◆ SVC_OPS

#define SVC_OPS

Value:
CALLISTO_SVC(Reserved) \
CALLISTO_SVC(PRINT) \
CALLISTO_SVC(ADD) \
CALLISTO_SVC(USER)

SVC operations.

Ther first value (0) is reserved as it will be used by FreeRTOS. The macro values are used to construct matching enumeration and string array using the x-macro strategy.

Definition at line 90 of file c4_privilege_modes.h.

## Enumeration Type Documentation

## ◆ C4_SVC_Op_t

enum C4_SVC_Op_t

Enumeration of operations performed by SVC. The operation IDs need to fit into a uint8_t.

Enumerator
C4_SVC_MAX_OPS |

Definition at line 99 of file c4_privilege_modes.h.

## Function Documentation

## ◆ C4_enterUnprivileged()

void C4_enterUnprivileged | ( |  | ) |

Set the CONTROL register for Unprivileged level.

Definition at line 48 of file c4_privilege_modes.c.

References CONTROL_Type::b, and CONTROL_Type::nPRIV.

Referenced by TestUnprivileged().

## ◆ C4_executePrivileged()

void* C4_executePrivileged | ( | C4_SVC_Op_t | op,
|  |  | ...
| ) |  |

Execute operation in privileged mode.

Parameters

  [in] | op | Enumerated ID of operation to be performed.

Definition at line 62 of file c4_privilege_modes.c.

Referenced by SVC_test().

CALLISTO_SVC
#define CALLISTO_SVC(op)
Definition: c4_privilege_modes.h:101