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 @@
.global reset_user_stack
.global switch_to_user_mode
.global switch_to_supervisor_mode
.global switch_mode
.global change_ret
.extern user_stack DATA // this adress can be read like: ldr Rx, =user_stack
reset_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
mov r1, #3
msr CONTROL, r1
isb
mov r2, #3
msr CONTROL, r2
bx lr
switch_to_user_mode:
mrs r0, control
mov r0, #3
msr control, r0
isb
bx lr
switch_to_supervisor_mode:
mrs r0, control
mov r0, #0
msr control, r0
isb
switch_mode:
mrs r1, control
mov r1, r0
msr control, r1
bx lr
/*************************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment