diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-01-02 20:53:42 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-01-02 20:53:42 +0100 |
commit | 9129af503c8211d713c8a160a3b6f3f86b328639 (patch) | |
tree | 3cd9ff26f4d323fc553b2a99d56be9b81a57a4c4 /os2_cm3.s | |
parent | aae314fead54dab7b258f3a6c7ac1615833f9987 (diff) | |
download | stm32f103-playground-9129af503c8211d713c8a160a3b6f3f86b328639.tar.gz stm32f103-playground-9129af503c8211d713c8a160a3b6f3f86b328639.tar.bz2 stm32f103-playground-9129af503c8211d713c8a160a3b6f3f86b328639.tar.xz stm32f103-playground-9129af503c8211d713c8a160a3b6f3f86b328639.zip |
o Adding a utility to dump segment sizes from the generated ELF files.
o Adding os2 with support for critical sections. More to come.
o Adding dma1 to test DMA + SPI.
Diffstat (limited to 'os2_cm3.s')
-rw-r--r-- | os2_cm3.s | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/os2_cm3.s b/os2_cm3.s new file mode 100644 index 0000000..dabdfe0 --- /dev/null +++ b/os2_cm3.s @@ -0,0 +1,56 @@ +.syntax unified +.cpu cortex-m3 +.thumb + +.section .text + +/* + +User threads use the process stack (PSP register), kernel and exception code use the main stack (MSP register). + +*/ + +.thumb_func +.global do_first_context_switch +// void do_first_context_switch(uint8_t *user_stack, void (task)(const void *arg)); +do_first_context_switch: + /* Set PSP to the user task's stack */ + msr psp, r0 + + // Set CONTROL.SPSEL=1 so that we run with two stacks + mov r0, #2 + msr control, r0 + isb + + // Restore the data from hardware_frame_t. + pop {r0 - r3, r12, lr} + // Pop PC and PSR. PSR is ignored, but we branch to the new PC + pop {r4, r5} + bx r4 + +/* +When this function is executed {r0-r3,r12,lr,pc} has been pushed to the stack pointed to by PSP. We push the rest of the +registers to the PSP. The current stack pointer is the MSP. + */ +.thumb_func +.global PendSV_Handler +PendSV_Handler: + // Save the rest of the context to the current process' stack + mrs r0, psp + stmdb r0!, {r4 - r11} + + // Call select_next_task_sp. after return, r0 points to a task_t + bl _ZN7trygvis3os22os16select_next_taskEPh // task_t *select_next_task(uint8_t *current_stack) + + // load task_t.stack and task_t.lr into r1 and lr + ldm r0, {r1, lr} + + ldmia r1!, {r4 - r11} + msr psp, r1 + + // Return, let the CPU restore the hardware part of the context + bx lr +.pool +.size PendSV_Handler,.-PendSV_Handler + +.end |