setup: Switch to unprivileged execution

This commit is contained in:
Saleem Rashid 2018-02-13 18:18:19 +00:00 committed by Pavol Rusnak
parent a00ac050e5
commit e3a0b6e7b4
3 changed files with 11 additions and 2 deletions

View File

@ -102,13 +102,13 @@ int main(void)
}
#endif
timer_init();
#ifdef APPVER
// enable MPU (Memory Protection Unit)
mpu_config();
#endif
timer_init();
#if DEBUG_LINK
oledSetDebugLink(1);
storage_wipe();

View File

@ -193,4 +193,7 @@ void mpu_config(void)
__asm__ volatile("dsb");
__asm__ volatile("isb");
// Switch to unprivileged software execution to prevent access to MPU
set_mode_unprivileged();
}

6
util.h
View File

@ -66,6 +66,12 @@ static inline void __attribute__((noreturn)) load_vector_table(const vector_tabl
// Prevent compiler from generating stack protector code (which causes CPU fault because the stack is moved)
for (;;);
}
static inline void set_mode_unprivileged(void)
{
// http://infocenter.arm.com/help/topic/com.arm.doc.dui0552a/CHDBIBGJ.html
__asm__ volatile("msr control, %0" :: "r" (0x1));
}
#endif
#endif