I'm trying to do a basic implementation of tasks in supervisor mode (no MMU concerns yet). I have the goal of implementing something similar to channels as they exist in the go language. I have a task structure that holds a stack pointer. When I shift from task to task I just push state onto the stack pointer, and pop off the new stack pointer. I have a global pointer called current_task which points the currently active task.
So I'm wondering what to do when one gets an interrupt. Instead of returning to the executing task, I want to jump to my yield function. My yield function will then select the next task to run and switch to it.
Is there a way to return from the interrupt to a different function? I guess I should do something like this in the irq return
sub lr,lr,#4 // fixup the address in lr
subs pc,=yield // call yield function
I'm guessing here that the lr will keep the value that it had in irq mode after the return to supervisor mode, so it will be correct in the yield function
Allowing the yield function to choose a next task to execute and jump to it
mov sp,r0 // stack pointer of next task is returned
Is this likely to work? Any pointers to simple task schedulers out there that already have this stuff working?