Multi-taskin?
Multi-taskin?
As far as I have understand, I can use the timer-interrupt for multitasking? My problem is, suppose I have the EIP/All registers stored for a thread. Then I would like to fill the registers with the correct values, no problem. But how do I set the EIP to a special address and then how do I start to execute from there?
Re:Multi-taskin?
When an interrupt is called the cpu pushes the following in order:
EFLAGS
CS
EIP
So to modify the retern address pop EIP and CS off the stack and push CS and newEIP onto the stack.
there are other ways of task switching. if you haven't yet read the manuals. you can get them from intel
EFLAGS
CS
EIP
So to modify the retern address pop EIP and CS off the stack and push CS and newEIP onto the stack.
Code: Select all
Timer_handler:
...
pop oldEIP
pop oldCS
push newCS ; now when we retern CS = NewCS
push newEIP; now when we retern EIP = NewEIP
IRET
Re:Multi-taskin?
Instead, if your interrupt handler saves all registers (which it must do anyways) simply store an ESP value for each task. Have your timer handler push a return address onto the current stack, switch stacks, and then execute a ret instruction. This will pop the return address off of the new stack. Have a routine such as this one, from my older OS, in Microsoft C++ (pardon me for not using *nix ):
I think this is something like what *nix does, but I am not sure. Anyways, this seems to work for me.
Good luck,
Mike
Code: Select all
EXTERN void TmSwitchTo(IThread *pThreadCur, IThread *pThreadNew)
{
__asm push esi;
__asm push edi;
__asm push ebp;
__asm mov ecx, pThreadCur; // ECX = current thread
__asm mov edx, pThreadNew; // EDX = new thread
__asm mov dword ptr [ecx]IThread.SaveESP, esp;
__asm mov dword ptr [ecx]IThread.SaveEIP, offset tsret;
__asm mov esp, dword ptr [edx]IThread.SaveESP;
__asm push dword ptr [edx]IThread.SaveEIP;
__asm jmp TmSwitchTo2; // FASTCALL (cur ECX, new EDX)
tsret:
__asm pop ebp;
__asm pop edi;
__asm pop esi;
}
EXTERN void __fastcall TmSwitchTo2(IThread *pThreadCur, IThread *pThreadNew)
{
// Code here will be called each time a task switches.
// This would be a good place to switch CR3, etc.
}
Good luck,
Mike
Re:Multi-taskin?
Here is a simple example of multitasking, that fits in the boot sector of a floppy, less than 512 bytes, its for realmode, but may help ?.
http://512.decard.net/entries/nanoos2.zip
PS: It was a entry in the 512b compo.
http://512.decard.net/entries/nanoos2.zip
PS: It was a entry in the 512b compo.