Page 1 of 1

little multitasking kernel

Posted: Fri Jul 26, 2002 8:39 am
by drizzt
[attachment deleted by admin]

Re:little multitasking kernel

Posted: Fri Jul 26, 2002 9:11 am
by crazybuddha
I haven't looked very closely, (and forgive me if I should've), but for this loop, where is "state" updated and are you sure the C mod is giving you the result you expect (ie. don't make any assumptions about how the compiler treats the result; you have to check it)?

/* Choose the next task */
i=(curr_task+1)%MAX_TASKS;
while (task.state==0 && i!=curr_task)
      i=(i+1)%MAX_TASKS;
   
curr_task=i;

Re:little multitasking kernel

Posted: Fri Jul 26, 2002 11:22 am
by drizzt
Thanx for your reply crazybuddha...
I've already checked if curr_task correctly change. If I print its value on the screen, it gives me the correct results: 0, 1, 2, 0, 1... etc.

As I said I think the error is or in kernel.asm when I set the segment register (line 71) or when I write data in the task table... but I'm not so sure...

Re:little multitasking kernel

Posted: Sun Jul 28, 2002 4:08 am
by drizzt
But is it probable that the error is in dispatcher? Because when int 08h is invoked the also int 1Ch is invoked... so if I want to take the ip of the task when it was stopped I must to pop 6 words out of the stack...
(first 3 words are flag register, cs, ip about 1Ch address. And next 3 words are the real flag, cs, ip about the task that was running...) :-\

Sorry if I bore you with this problem, but it's very important for me...

Re:little multitasking kernel

Posted: Mon Jul 29, 2002 10:39 am
by drizzt
[attachment deleted by admin]

Re:little multitasking kernel

Posted: Mon Jul 29, 2002 10:02 pm
by crazybuddha
Despite warnings against revectoring INT 0x08 (and using 0x1c instead), this is the customary way to do it... always has been. However, as I mentioned in a different post, you need to call the old handler if you don't want any surprises.

This still won't be the end of your troubles. If you are using IRET to get CS:IP for the next task off the stack, if anything corrupts it, you won't see the new task run.

My (probably useless) advice is to try to code the absolute simplest, hardcoded task switching you can think of, then build back to where you are now. The goal is simple. Each task gets a stack and there is a table of the "task state", which is really just the SS:SP. Init the stack with values for flags, CS, and IP (for the task). Push the regs, save the state, get the "state" of the next task, pop its regs, and IRET will pop the CS and IP for the new task. The implementation can get to be a bit of a puzzle, especially with the BIOS lurking.

Pencil and paper is a godsend for figuring this kind of thing out.

Re:little multitasking kernel

Posted: Tue Jul 30, 2002 3:56 am
by Pype.Clicker
some hints from my experiences :
- don't forget to save/restore the stack state (SS/SP) as well : if you don't do it, then IRETing will simply send you back to your previous task code ...
- use the OUT 20h,20h *before* doing the task switch (so that you're sure to do it regardless of what your next task is about to do.

Re:little multitasking kernel

Posted: Tue Jul 30, 2002 11:07 am
by drizzt
Thanks crazy & pype! ;)
I've resolved the sleeping tasks problem by setting the flags register of next running task to IF=1 directly in the stack.
The next step will be to save task state SS & SP. I hope it's less difficult than previous problems... but I can always count on your experience... ;D

Re:little multitasking kernel

Posted: Thu Aug 01, 2002 10:30 pm
by crazybuddha
[attachment deleted by admin]