Re:SymbOS: preemptive multitasking OS that can play mp3s, vi...
by cmrdporcupine on Thursday December 17, 2015 @09:43AM
(#10751702)
816 has a relocatable stack and direct(nee zero) page, so that's good. Unfortunately both of those still have to be in the lower 64k bank. So that's a bit frustrating for trying to write OS support for multitasking larger memory systems.
(In either case, you'll probably want some mechanism for tasks to relinquish their timeslice early; no reason not to make multitasking run better when tasks cooperate, even if it doesn't absolutely require that.)
To do the actual task switch, do exactly what you do on any system:
- save register state in tasks's register area (the state will be available on entry to the interrupt routine, in the usual fashion. The task pointer will be a system global at a fixed address)
- set timer for one timeslice hence (timers probably count down to zero, so this will just be a question of putting a value somewhere into an I/O register)
- resumes task by jumping to the program counter value from the task's register area
- GOTO 10...
(The complications come on something like the 6502, which has a fixed-size, fixed-address stack - but this it hard task-switching difficult, not the preemption! How I imagine CLIPS gets around this: it requires CMD SuperCPU, which is a 65816. Like the Z80 and 6809, but unlike the 6502, the 65816 has a relocatable stack. So it will probably behave as I describe above.)