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

feat: one function for permutting between modes & computing user stack size dynamically

parent 6fae3c24
No related branches found
No related tags found
No related merge requests found
...@@ -9,30 +9,24 @@ ...@@ -9,30 +9,24 @@
.global reset_user_stack .global reset_user_stack
.global switch_to_user_mode .global switch_to_user_mode
.global switch_to_supervisor_mode .global switch_to_supervisor_mode
.global switch_mode
.global change_ret .global change_ret
.extern user_stack DATA // this adress can be read like: ldr Rx, =user_stack .extern user_stack DATA // this adress can be read like: ldr Rx, =user_stack
reset_user_stack: reset_user_stack:
ldr r0, =user_stack ldr r0, =user_stack
add r0, r0, #8192 // 2048 * word_size mov r1, USER_STACK_SIZE
lsl r1, r1, #2 // (e.g. multiply by word size == 4 bytes)
add r0, r1
msr PSP, r0 msr PSP, r0
mov r1, #3 mov r2, #3
msr CONTROL, r1 msr CONTROL, r2
isb
bx lr bx lr
switch_to_user_mode: switch_mode:
mrs r0, control mrs r1, control
mov r0, #3 mov r1, r0
msr control, r0 msr control, r1
isb
bx lr
switch_to_supervisor_mode:
mrs r0, control
mov r0, #0
msr control, r0
isb
bx lr bx lr
/*************************/ /*************************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment