diff options
author | vetch <vetch97@gmail.com> | 2019-11-05 16:54:28 +0100 |
---|---|---|
committer | vetch <vetch97@gmail.com> | 2019-11-05 16:54:28 +0100 |
commit | 2beaa82a116a7e855327d3702999c371920fb410 (patch) | |
tree | 2b09111c608e64e8d846f0ad4455a1aac29a18a4 /cpsr.h | |
parent | dcd4da0d9386e2f48a1161b3464116c2ba90234f (diff) | |
parent | d3da1d80ac2ce844b19feab6187722fc72eaa59c (diff) | |
download | rpi-MMU-example-2beaa82a116a7e855327d3702999c371920fb410.tar.gz rpi-MMU-example-2beaa82a116a7e855327d3702999c371920fb410.zip |
merge bob into alice
Diffstat (limited to 'cpsr.h')
-rw-r--r-- | cpsr.h | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -0,0 +1,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"); +} |