Co-operative Multitasking?
Posted: Sat Feb 10, 2007 9:36 pm
I'm working on a co-operative multitasking system for my kernel. My ASM kernel was able to do this without any problems. My C kernel just won't work! My system basically has a function called 'NextProc' (NASM code below) that gets the return address, pushes it onto the stack as an argument for a C function, then calls it. Problem is, it doesn't work.
Edit: I can get it to work now, but the only way is basically to call each procedure from the start - not a true multitasking system. Does anyone know how I can get the IP of the function that was running before it let the next one run (NextProc()) and use that in resched?
resched:
ctxsw code:
MTProc is defined as:
Any help would be really nice!
Edit: I can get it to work now, but the only way is basically to call each procedure from the start - not a true multitasking system. Does anyone know how I can get the IP of the function that was running before it let the next one run (NextProc()) and use that in resched?
Code: Select all
_NextProc:
; get the address
push ebp
mov ebp,esp
mov eax,[ebp]
pop ebp
push eax
call _resched
ret
Code: Select all
// reschedules
void resched( unsigned int ip )
{
// put the data into the process list so that we can return to it again
ptable[currpid++].base = ip;
// check for validity
if( ptable[currpid].state == PFREE )
{
// back -> 0
currpid = 0;
}
// run the code (this is not really what you would call a multitasking system)
MTProc* p = (MTProc*) ptable[currpid].base;
p();
}
Code: Select all
_ctxsw:
push ebp
mov ebp,esp
; get the address
mov eax,[ebp+8]
; IMPORTANT: because if you don't do this
; some serious errors will come up
pop ebp
; performs the context switch to the address given
; in the first argument
; eax holds the address - return to the next process
push eax
retn
Code: Select all
typedef void (MTProc) ();