blob: 327bdf0d7ffaa2835d1b476521216bd322dddb89 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include <stdint.h>
enum execution_mode {
MODE_USER = 0x10,
MODE_FIQ = 0x11,
MODE_IRQ = 0x12,
MODE_SUPERVISOR = 0x13,
MODE_MONITOR = 0x16,
MODE_ABORT = 0x17,
MODE_HYPERVISOR = 0x1a,
MODE_UNDEFINED = 0x1b,
MODE_SYSTEM = 0x1f,
};
inline static uint32_t read_CPSR(void)
{
uint32_t CPSR;
// get content of current program status register
asm("mrs %0, cpsr" : "=r" (CPSR) ::);
return CPSR;
}
inline static enum execution_mode read_processor_mode(void)
{
/* lowest 5 bits indicate processor mode */
return read_CPSR() & 0x1f;
}
inline static void set_system_mode(void)
{
uint32_t CPSR = read_CPSR();
CPSR = (CPSR >> 5) << 5;
CPSR |= MODE_SYSTEM;
asm("msr cpsr, %0" :: "r" (CPSR) : "memory");
}
|