allow task to make their own stacks
Posted: Fri Aug 03, 2007 4:25 am
Many OS's load some sort of object file and then allocate the stack per each thread.
I am considering making the threads make their own stacks, or use no stack.
This would allow the programmer to do what ever they want and make the stack as big or small as they want.
I am going to use software timer interupt driven task switching- each process has a page directory and each process makes threads that can have their own stack. All processes virtual address spaces start at 0 and extend to 4gb.
Each process has a structure (127 max processes) containing a id byte, status byte, page directory, bunch of blocks detailing the page location in ram or hardrive, and 127 thread structres
each thread structure has
id byte
status byte
sleep timer byte
storage for registers
the task switcher does
When the task switcher is ran if first switches to kernel page directory, saves the registers, sets up its own stack (1 task switcher/interrupt handler stack per cpu to avoid conflicts)
and enters the loop above.
Notice how this software task switcher avoids the assumption that task will have stacks, but it does save the registers so it still saves the stack if it exists.
The task switcher is a routine called by the system timer handler and can be called by a software interupt handler (who can be called by the task to implement sleep() ) as well as other software interupt handlers such as io (the thread wants to send io, it first ask the os for a handle to a device, then it can read input at anytime, and if it request write access it can call the interupt who switches the tasks so eventually the device driver task (think microkernel) can process it and return a value into the read stream by the time the requesting task resumes- heh thats long).
Anyways this will be my first os so don't assume I know what I am talking about.
I am considering making the threads make their own stacks, or use no stack.
This would allow the programmer to do what ever they want and make the stack as big or small as they want.
I am going to use software timer interupt driven task switching- each process has a page directory and each process makes threads that can have their own stack. All processes virtual address spaces start at 0 and extend to 4gb.
Each process has a structure (127 max processes) containing a id byte, status byte, page directory, bunch of blocks detailing the page location in ram or hardrive, and 127 thread structres
each thread structure has
id byte
status byte
sleep timer byte
storage for registers
the task switcher does
Code: Select all
loops through process structures
loops through thread structures
thread is ready to execute (see below)
or sleep timer is not 0 yet
subtract 1 from sleep timer
continue looping though threadsuntil you reach 127
continue looping until you reach 127
hlt (idle process, the timer irq handler does task switching)
thread is ready to execute
set page directory cr3 to the process's pd and load threads registers
return (iret)
and enters the loop above.
Notice how this software task switcher avoids the assumption that task will have stacks, but it does save the registers so it still saves the stack if it exists.
The task switcher is a routine called by the system timer handler and can be called by a software interupt handler (who can be called by the task to implement sleep() ) as well as other software interupt handlers such as io (the thread wants to send io, it first ask the os for a handle to a device, then it can read input at anytime, and if it request write access it can call the interupt who switches the tasks so eventually the device driver task (think microkernel) can process it and return a value into the read stream by the time the requesting task resumes- heh thats long).
Anyways this will be my first os so don't assume I know what I am talking about.