Yes, ARM holds the first and second arguments in r0, r1 for function calls for the task_swap function, volatile would not change this.For the KINETISL, you call task_swap(), and the ASM code assumes that the two arguments (current frame and next frame pointers) are in registers r0 and r1. For KINETISK, you do the swap entirely in ASM, including statements to move the current frame and next frame pointers into r0 and r1. Is it guaranteed that two pointer-type arguments will be in r0 and r1 when you call a function? Is that true regardless of whether or not the function defines the arguments as volatile?
Arm has two stack pointers (PSP, MSP). The MSP 'main stack pointer' is normally used in 'Big Loop' programs like arduino. The MSP also is only used when an isr 'Handler Mode' is called. The PSP 'process stack pointer' is only used in 'Thread Mode' which would just be non-isr functions. This allows the tasks to have a separate stack pointer from any isr code. This is still experimental on my part though you could easily just use the MSP for everything (isr and non-isr). The reason would be that the system could still run "using the MSP" to safely restart or shutdown the Teensy if a stack overflow happens in one of the users tasks. This is not implemented yet though!Can you explain your choice to use PSP rather than MSP for tasks?
The current version does this in two chunks that I uploaded last night, just like you proposed above. The Teensy LC cannot directly load or store the 'high registers' so thats what you see in the context switch code. This could be done a bunch of different ways but this is the best I came up with so far that keeps the same 'stack_frame' structures as the Teensy 3.x. I'm trying to keep the Teensy LC and Teensy 3.x code as much as possible the same.For LC, is there any reason you don't save the current frame in two steps rather than three? I tried the code below and it seems to be equivalent to the 3-step process in beta 2.0
"STMIA r0!,{r3-r7}" "\n\t" // Save r3,r4-r7 to r0! (currentframe->sp)
"MOV r2,r8" "\n\t" // move r8 into r2
"MOV r3,r9" "\n\t" // move r9 into r3
"MOV r4,sl" "\n\t" // move sl (r10) into r4
"MOV r5,fp" "\n\t" // move fp (r11) into r5
"MOV r6,ip" "\n\t" // move ip (r12) into r6
"MOV r7,lr" "\n\t" // move lr into r7
"STMIA r0!,{r2-r7}" "\n\t" // Save r8-r12,lr to r0! (currentframe->r8)
One thing that I'm interested in is you said you have code for mutexs, semaphores and such would you be willing to merge that into this library? If not its cool just those would be nice to have also.