Multitasking? [Sort of Fixed]

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Multitasking? [Sort of Fixed]

Post 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.
Last edited by pcmattman on Sun Feb 04, 2007 3:13 am, edited 1 time in total.
iammisc
Member
Member
Posts: 269
Joined: Thu Nov 09, 2006 6:23 pm

Post 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?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
Post Reply