Skip to content
Snippets Groups Projects
Commit 9cfe91a1 authored by iliya's avatar iliya
Browse files

feat: ex1 seemingly finished

parent d064a263
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,10 @@ ...@@ -11,7 +11,10 @@
switch_to_user_mode: switch_to_user_mode:
ldr r0, =user_stack
msr PSP, r0
mov r1, #1
msr CONTROL, r1
bx lr bx lr
......
macro.h 0 → 100644
/*
* macro.h
*
* Created on: 20 Dec 2023
* Author: iliya
*/
#ifndef MACRO_H_
#define MACRO_H_
// Region enable bit
#define REGION_ENABLE (0x1 << 0)
// Memory region sizes
#define SET_SIZE_512KB (0x12 << 1)
#define SET_SIZE_32KB (0xE << 1)
#define SET_SIZE_16KB (0xD << 1)
// Access permission attribute
#define BTEX_NORMAL_NOT_SHAREABLE (0x1 << 19)
#define BTEX_NOT_SHAREABLE_DEVICE (0x2 << 19)
// Access permission field
#define RO (0x7 << 24)
#define RW (0x3 << 24)
#define RW_PRIV (0x1 << 24)
#define RW_PRIV_R_UNPRIV (0x2 << 24)
#endif /* MACRO_H_ */
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "globals.h" #include "globals.h"
#include "user_cmd.h" #include "user_cmd.h"
#include "uart.h" #include "uart.h"
#include "macro.h"
#define MMFAR *(unsigned *)0xE000ED34 #define MMFAR *(unsigned *)0xE000ED34
...@@ -31,8 +32,6 @@ void switch_to_user_mode(); ...@@ -31,8 +32,6 @@ void switch_to_user_mode();
void asm_test_fault(); void asm_test_fault();
void MemManage_Handler() { void MemManage_Handler() {
SCB->SHCSR |= (1 << 16);
// Activez le MPU
} }
void test_supervisor_mode() { void test_supervisor_mode() {
...@@ -55,11 +54,44 @@ void test_user_mode() { ...@@ -55,11 +54,44 @@ void test_user_mode() {
n = LPC_TIM0->TC; // not OK (privileged access only) n = LPC_TIM0->TC; // not OK (privileged access only)
} }
int main(void) { int main(void) {
// MPU configuration here... // MPU configuration here...
// Region 0 (Flash)
MPU->RNR = 0;
MPU->RBAR = 0x00000000;
MPU->RASR = RO | BTEX_NORMAL_NOT_SHAREABLE | SET_SIZE_512KB | REGION_ENABLE;
// Region 1 (SRAM1)
MPU->RNR = 1;
MPU->RBAR = 0x10000000;
MPU->RASR = RW | BTEX_NORMAL_NOT_SHAREABLE | SET_SIZE_32KB | REGION_ENABLE;
// Region 2 (SRAM1)
MPU->RNR = 2;
MPU->RBAR = 0x2007C000;
MPU->RASR = RW_PRIV_R_UNPRIV | BTEX_NORMAL_NOT_SHAREABLE | SET_SIZE_32KB | REGION_ENABLE;
// Region 3 (GPIO)
MPU->RNR = 3;
MPU->RBAR = 0x2009C000;
MPU->RASR = RW_PRIV_R_UNPRIV | BTEX_NOT_SHAREABLE_DEVICE | SET_SIZE_16KB | REGION_ENABLE;
// Region 4 (périphériques dont timers)
MPU->RNR = 4;
MPU->RBAR = 0x40000000;
MPU->RASR = RW_PRIV | BTEX_NOT_SHAREABLE_DEVICE | SET_SIZE_32KB | REGION_ENABLE;
// Region 5 (UART)
MPU->RNR = 5;
MPU->RBAR = 0x4000C000;
MPU->RASR = RW | BTEX_NOT_SHAREABLE_DEVICE | SET_SIZE_16KB | REGION_ENABLE;
SCB->SHCSR |= (1 << 16);
MPU->CTRL |= 0x1 << 0;
// testing memory accesses in supervisor mode: // testing memory accesses in supervisor mode:
test_supervisor_mode(); // to be removed after checking // test_supervisor_mode(); // to be removed after checking
user_start: user_stating_address = &&user_start;// save the address of the label 'user_start' (for exercise 2) user_start: user_stating_address = &&user_start;// save the address of the label 'user_start' (for exercise 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment