Page 1 of 1

Ughhh, multitasking help again...

Posted: Tue Jul 16, 2002 11:26 am
by Kenneth Garin
I have a few questions related to multitasking in real-mode...
Whats the basics?
How is it done?
How do I get the IP of a task once the timer hooked routine is entered (to save for future reentering).
--->So far here is a basic diagram of what I have made...
>hook timer interrupt 1Ch
>task a code
>task b code
>main code loop
>once main exits, unhook timer interrupt to resume normal
>once inside hooked timer code, reenter current task at segment:offset
The problem here is that it reenters the task at its starting offset, not its offset+IP so how do I do this???????
Thanks for ideas, help, or links. *THANKS!* Kg.
PS: Once I get a working multitasking demo I will release it for others to learn from :)

Re:Ughhh, multitasking help again...

Posted: Tue Jul 16, 2002 1:57 pm
by Pype.Clicker
Okay, let's say you have a structure for every task where you can save informations about they running status.

struct task {
farptr code; // stores cs:ip
farptr stack; // stores ss:sp
}

When you decide to switch from the current task (which structure could be pointed out by task* currtask), you should do the following:
- catch the current ss:sp value from the registers and store it into currtask->stack
- catch the last cs:ip from the stack frame (saved by the CPU at interrupt time) into currtask->code
- select a new task to be run (as any scheduler would do...)
- restore ss and sp with the values in nexttask->stack,
- normally, you should find nexttask->code already in the new stack frame. If this is not the case, you can restore them from currtask->code...
- exit your interrupt call (and go back to the interrupted code) ...

This technique requires you to clean up 8255 state (outb 0x20,0x20) *before* you do the switch so that you don't need to worry about if the restored task was suspended within an IRQ or by a system call (sleep, etc.)


This software technique is fully transposable in 32 bits :)

Re:Ughhh, multitasking help again...

Posted: Wed Jul 17, 2002 1:03 pm
by Kenneth Garin
Thanks. Even though I am an avanced programmer in low level system stuff, your reply still looks complicated to me :( Well I will re-read it a few times and then maybe I will understand it :) Im starting to think you're smarter about computers than anyone that exist.
I'd do the multitasking in pmode but my project calls for real mode usage along with multible routines running, eg: multitasking. I guess if it comes down to it I could use cooperative multitasking but if a routine fails then the whole sys will crash :( One nice thing about preemtive multitasking :)
Kg.

Re:Ughhh, multitasking help again...

Posted: Thu Jul 18, 2002 1:16 am
by Pype.Clicker
just re-read it with a paper and a pencil, and try to trace what happens ... you just use stacks to save all registers (including cs & ip) and then switch to another stack (from another task) where previous context was stored...


task_switch:
pusha
mov [out_task],sp
mov [out_task+2],ss
lss sp,[in_task]
popa
retf