Page 1 of 1

Multitasking? [Sort of Fixed]

Posted: Sat Feb 03, 2007 9:53 pm
by pcmattman
I'm writing a multitasking system (in NASM assembly). So far, it just has 2 predefined 'tasks' to test out the system. Later, it will allow a custom number of procedures.

The scheduler runs on the timer interrupt (using preemption). When it needs to reschedule, it pops the CS and IP off the stack (which was pushed on when the interrupt was called). It then calls resched which saves and restores the register states. It then takes the popped CS and IP and than jumps to that location.

The problem is, none of the code in the procedures actually runs. It just hangs when it needs to jump to the procedure. Any ideas?

Note: I'm using real-mode by the way.

Update: Now the scheduler is working properly, but after the first 'reschedule' no more timer interrupts fire, effectively stopping the OS from multitasking.

Update 2: I've taken out the whole preemptive scheduler and replaced it with a cooperative scheduler. It works much better for the type of system I'm writing. Of course, if anyone can help me write a preemptive scheduler I'll be much happier.

Posted: Sat Feb 03, 2007 10:45 pm
by iammisc
i'm not sure about the hanging but don't you need to send an eoi to the pic and do an iret in order to receive another interrupt?

Posted: Sat Feb 03, 2007 10:48 pm
by pcmattman
I've emulated the IRET function (by popping IP, CS and the flags) but I didn't know about the EOI... I'll try that.

Posted: Sat Feb 03, 2007 11:23 pm
by pcmattman
OK, the scheduler now works, sort of. The problem is that the scheduler overwrites the other procedure's IP restore value. Is there any way I can stop this from happening?

Update: Found the problem: whenever the interrupt fires, when I pop the IP off the stack, it is an incorrect value. Any help in this matter would be great.