Multitasking Theory- Part 2

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kernel

Multitasking Theory- Part 2

Post by kernel »

Ok, I have 2 simple questions about multitasking.

First, before your schedular switches tasks, does it save the current register values somewhere and load the new tasks register values?
And, when you jmp to a new task, are you jumping to a memory location to resume the task or what?
thanx ;D
Schol-R-LEA

Re:Multitasking Theory- Part 2

Post by Schol-R-LEA »

kernel wrote: Ok, I have 2 simple questions about multitasking.

First, before your schedular switches tasks, does it save the current register values somewhere and load the new tasks register values?
Yes. In the simple example I gave before, it pushed them onto the task's local stack before switching to the scheduler's stack. When running in protected mode, I believe that there are hardware-supported methods for saving and restoring task contexts, though I don't know the details of that yet myself. Regardless of how it is done, yes, the registers have to be saved when switching out of a task, and restored when switching back into one.
kernel wrote: And, when you jmp to a new task, are you jumping to a memory location to resume the task or what?
thanx ;D
Basically, yes, but usually it would take the form of either a function return or (more likely still for a x86 real-mode kernel) an interrupt return, rather than a simple jump. Once again, that is just the simplest case; in p-mode there are other mechanisms that you'd probably use instead (e.g., task gates), but they amount to much the same effect.
kernel

Re:Multitasking Theory- Part 2

Post by kernel »

cool. thanks ;D
Peter_Vigren

Re:Multitasking Theory- Part 2

Post by Peter_Vigren »

kernel wrote: Ok, I have 2 simple questions about multitasking.

First, before your schedular switches tasks, does it save the current register values somewhere and load the new tasks register values?
And, when you jmp to a new task, are you jumping to a memory location to resume the task or what?
thanx ;D
In protected mode, you can faciliate the built-in task switching support of the processor... which automaticly saves/restores all registers and other relevant information upon task switch (often triggered by the timer interrupt for scheduling purpose) if you have set up the necessary selectors and such correctly.
Piotr Sejfried

Re:Multitasking Theory- Part 2

Post by Piotr Sejfried »

Hello,

I see that you are talking about Mu;titasking in protected mode. Is there anyone who knows
something more about it? Somebody who can
help in writeing 32 bit pmode multitasking kernel?

Best Regards

Peter
srg

Re:Multitasking Theory- Part 2

Post by srg »

In protected mode, you can faciliate the built-in task switching support of the processor... which automaticly saves/restores all registers and other relevant information upon task switch (often triggered by the timer interrupt for scheduling purpose) if you have set up the necessary selectors and such correctly.
But what if you use a flat memory model with single 4GB code and data segments??

Steven Graham
Peter_Vigren

Re:Multitasking Theory- Part 2

Post by Peter_Vigren »

srg wrote:
In protected mode, you can faciliate the built-in task switching support of the processor... which automaticly saves/restores all registers and other relevant information upon task switch (often triggered by the timer interrupt for scheduling purpose) if you have set up the necessary selectors and such correctly.
But what if you use a flat memory model with single 4GB code and data segments??

Steven Graham
I'm not really sure what you mean... If you mean that you want to run a number of tasks while sharing memory, then that is easily done...
Post Reply