+/rtos

git clone https://git.julia.blue/+/rtos

Joseph RyanAdd stack overflow detection with the MPUb9fc7f5

master
941 B37 linesraw
1.cpu cortex-m4
2.fpu fpv4-sp-d16
3.syntax unified
4.thumb
5.text
6
7.extern current_thread
8.extern mpu_swap_region
9// .extern context_switch_hook
10
11.thumb_func
12.global pendsv_handler
13pendsv_handler:
14    CPSID I
15    PUSH {R4 - R11}
16
17// For debugging context switches in C
18    // PUSH {LR}
19    // BL context_switch_hook
20    // POP  {LR}
21
22    LDR  R0, =current_thread    // R0 = &current_thread
23    LDR  R1, [R0]               // R1 = current_thread
24    STR  SP, [R1]               // SP = *current_thread aka current_thread->sp
25    LDR  R1, [R1,#4]            // R1 = current_thread->next_tcb;
26    STR  R1, [R0]               // current_thread = current_thread->next_tcb;
27    LDR  SP, [R1]               // SP = current_thread->sp
28
29    // Change MPU region to current thread's stack
30    // TODO: make this faster by modifying the address register directly
31    push {LR}
32    BL mpu_swap_region 
33    POP {LR}
34
35    POP  {R4 - R11}
36    CPSIE I
37    BX LR