From ee89199793683b3120a55f1c1887e12333c5ea7e Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Wed, 25 Nov 2020 16:53:24 -0700 Subject: Add ability to jump to a usermode init routine. This routine will has a newly allocated stack. I found out that when using the st-flash utility it likes to reset the device with the IPSR in HARD FAULT mode (?) so I have to manually hit the reset button to get it to work. --- src/kern/priv.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/kern/priv.c') diff --git a/src/kern/priv.c b/src/kern/priv.c index 3162639..2c45eca 100644 --- a/src/kern/priv.c +++ b/src/kern/priv.c @@ -2,6 +2,7 @@ #include "arch.h" #include "kern/log.h" +#include "kern/mem.h" void set_control_register(uint32_t reg) { @@ -24,7 +25,16 @@ void enter_user_mode() void jump_to_user_mode() { + void* new_stack = kalloc(4096); + new_stack += 4096; + asm volatile( - "mov r0, #1\n\t" - "msr control, r0\n\t"); + "mov r0, %0\n\t" + "msr psp, r0\n\t" + "mrs r0, control\n\t" + "orrs r0, r0, #3\n\t" + "msr control, r0\n\t" + "isb\n\t" + "dsb\n\t" + "b usermode_start\n\t" : : "r"(new_stack)); } -- cgit