From e780bcbf7bd3dfc91b458207a02216ee7c48d0c1 Mon Sep 17 00:00:00 2001
From: Brian <brian@crocoll.ch>
Date: Wed, 20 Dec 2023 22:17:25 +0100
Subject: [PATCH] tentative artie 3

---
 assembleur.s           | 5 ++++-
 mpu_user_console_etu.c | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/assembleur.s b/assembleur.s
index b2cbed7..21fbcfb 100644
--- a/assembleur.s
+++ b/assembleur.s
@@ -7,9 +7,9 @@
 
 .global asm_test_fault
 .global switch_to_user_mode
+.global set_psp
 .extern user_stack DATA				// this adress can be read like: ldr Rx, =user_stack
 
-
 switch_to_user_mode:
 	ldr r0, =user_stack
 	msr PSP, r0
@@ -17,6 +17,9 @@ switch_to_user_mode:
 	msr CONTROL, r1
 	bx  lr
 
+set_psp:
+	mrs r0, psp
+	bx lr
 
 .equ bad_addr,0x90000
 
diff --git a/mpu_user_console_etu.c b/mpu_user_console_etu.c
index bfcefbb..bf3504a 100644
--- a/mpu_user_console_etu.c
+++ b/mpu_user_console_etu.c
@@ -36,6 +36,7 @@ volatile static unsigned idx_error;
 
 void switch_to_user_mode();
 void asm_test_fault();
+void set_psp();
 
 void MemManage_Handler() {
 	arr_addr[idx_error] = MMFAR;
@@ -44,6 +45,13 @@ void MemManage_Handler() {
 
 	SCB->CFSR = 0xFFFF;
 	LPC_GPIO2->FIOPIN = idx_error;
+
+	uint32_t* user_psp;
+
+	set_psp(user_psp);
+
+	user_psp[6] = (uint32_t)user_stating_address;
+
 }
 
 void test_supervisor_mode() {
-- 
GitLab