diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2020-11-25 16:53:24 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2020-11-25 16:53:24 -0700 |
commit | ee89199793683b3120a55f1c1887e12333c5ea7e (patch) | |
tree | 2996b7645b6ab727bd9c6ee7f7062626d3ff7023 /src/kern/priv.c | |
parent | 6d22b0dfc7761a605758552d5824f8039ac5a00f (diff) | |
download | stm32l4-ee89199793683b3120a55f1c1887e12333c5ea7e.tar.gz stm32l4-ee89199793683b3120a55f1c1887e12333c5ea7e.tar.bz2 stm32l4-ee89199793683b3120a55f1c1887e12333c5ea7e.zip |
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.
Diffstat (limited to 'src/kern/priv.c')
-rw-r--r-- | src/kern/priv.c | 14 |
1 files changed, 12 insertions, 2 deletions
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)); } |