[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 6502 Multitasking OS announce
How about this idea, to handle stacks? I read a similar thing in an
issue of Dr. Dobbs Journal, in an article about a small multitasker.
Given that the stack is mostly going to be used for minor parameter
passing and jsr's. I think is a good assumption -- other data
structures are better suited for larger jobs.
Instead of copying the stack to and fro on every task switch, how about
subdividing it? Each task would be allocated a portion of the stack. A
task switch moves between the portions by adding or subtracting numbers
from the stack register.
For example, let's say that we are currently on task 1. Its stack is
partially filled. The stack register holds 240. Now there is a task
switch, to task 2. The interrupt service routine stores the depth of
the stack register on task 1's stack, which in this case, is 16. Now,
the OS has also recorded where task 2's stack pointer was the last time
it was active, in the format of 192 - n. It loads up n, subtracts it
from 192, stores that in the stack register, giving xxx in the diagram
below (the correct stack entry), and executes an RTI. It will return to
the appropriate point in task 2, because task 2 was halted by an
Jump-to-Interrupt (forgot opcode) to the OS, and the last thing put on
the stack was the return address to task 2's state. So the RTI will
return to that state.
Now, how to handle allocation of the stack? Well, some routines,
particularly those needing recursion, need a lot of stack. Others don't
need much. So when a task is initiated, it can request how much it
expects to need, and the OS can allocate such-and-so.
256 -----------------
: Task 1 <- 240: 256-16
:
192 -----------------
: Task 2 <- xxx: 192-n=03
:
144 -----------------
: Task 3 (small)
112 -----------------
: Task 4 (wants
: lots)
:
48 -----------------
: System
: or Free
=050 -----------------
What do you think? Is it workable? (Again, due credits to Dr. Dobbs'
article by whoever wrote it.)