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) ();