Callisto4Bootloader: test/c4_privilege_modes_test.c Source File

Callisto4Bootloader

c4_privilege_modes_test.c
Go to the documentation of this file.
1
15 /*******************************************************************************
16 * Includes
17 ******************************************************************************/
18 #include "c4_privilege_modes_test.h"
19 #include "c4_privilege_modes.h"
20 #include "fsl_debug_console.h"
21
22 #include <stdio.h>
23 #include <string.h>
24
25 /*******************************************************************************
26 * Defines
27 ******************************************************************************/
28
29 /*******************************************************************************
30 * Structures
31 ******************************************************************************/
32
33 /*******************************************************************************
34 * Prototypes
35 ******************************************************************************/
36
45 static uint32_t getRegisterValue(const char *regName);
46
52 static void printRegisterValue(const char *regName, uint32_t val);
53
54 /*******************************************************************************
55 * Variables
56 ******************************************************************************/
57
58 /*******************************************************************************
59 * Interface Implementation
60 ******************************************************************************/
61
62 exit_code_t TestUnprivileged()
63 {
64 exit_code_t rc = C4_ERR_OK;
65 CONTROL_Type ctrlReg;
66
67 printf("In %s\n", __PRETTY_FUNCTION__);
68
69 ctrlReg = (CONTROL_Type)getRegisterValue("CONTROL");
70 printRegisterValue("CONTROL", ctrlReg.w);
71
72 C4_enterUnprivileged();
73
74 ctrlReg = (CONTROL_Type)getRegisterValue("CONTROL");
75 printRegisterValue("CONTROL", ctrlReg.w);
76 return rc;
77 }
78
79
80 /*******************************************************************************
81 * Local Functions
82 ******************************************************************************/
83
84 static uint32_t getRegisterValue(const char *regName)
85 {
86 uint32_t reg = 0;
87 printf("In %s(%s)\n", __PRETTY_FUNCTION__, regName);
88
89 if (0 == strcmp(regName, "CONTROL"))
90 asm volatile ("MRS %0, CONTROL\n\t":"=r"(reg));
91
92 return reg;
93 }
94
95 /*******************************************************************************/
96
97 static void printRegisterValue(const char *regName, uint32_t val)
98 {
99 if (0 == strcmp(regName, "CONTROL"))
100 {
101 CONTROL_Type ctrlReg = (CONTROL_Type)val;
102 printf("CONTROL + 0x%08lx\n\t%s mode\n\tstack = %s\n\tFPU = %s\n",
103 ctrlReg.w,
104 (ctrlReg.b.nPRIV ? "Unprivileged" : "Privileged"),
105 (ctrlReg.b.SPSEL ? "PSP" : "MSP"),
106 (ctrlReg.b.FPCA ? "Active" : "Not active"));
107 }
108 }
CONTROL_Type::b
struct CONTROL_Type::@3 b
c4_privilege_modes_test.h
Interface to test privilege modes.
CONTROL_Type::FPCA
uint32_t FPCA
Definition: core_armv81mml.h:428
CONTROL_Type::nPRIV
uint32_t nPRIV
Definition: core_armv81mml.h:426
C4_enterUnprivileged
void C4_enterUnprivileged()
Set the CONTROL register for Unprivileged level.
Definition: c4_privilege_modes.c:48
printRegisterValue
static void printRegisterValue(const char *regName, uint32_t val)
Prints the current register value.
Definition: c4_privilege_modes_test.c:91
CONTROL_Type::SPSEL
uint32_t SPSEL
Definition: core_armv81mml.h:427
TestUnprivileged
exit_code_t TestUnprivileged()
Test unprivileged mode.
Definition: c4_privilege_modes_test.c:57
exit_code_t
exit_code_t
Enumeration of error codes.
Definition: c4_error_codes.h:96
CONTROL_Type::w
uint32_t w
Definition: core_armv81mml.h:432
CONTROL_Type
Union type to access the Control Registers (CONTROL).
Definition: core_armv81mml.h:422
getRegisterValue
static uint32_t getRegisterValue(const char *regName)
Gets the current value of the specified register.
Definition: c4_privilege_modes_test.c:78
c4_privilege_modes.h
Provide mechanisms to specify which stack to use and for the processor to operate in Unprivileged mod...