Page 1 of 1

quick task switching question

Posted: Wed Jul 23, 2008 2:04 pm
by itisiuk
right im busy redoing multitasking in my os.
anyway ive deciced upon the following piece of code as a short cut and was
wondering if there would be any major problems with this. so far it works, but thats only for 2 processes.

my irq nasm stub and the bit im concered with

Code: Select all

irq_stub:
pushad
push ds
push es
push fs
push gs

mov ax, KERNEL_DS
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

push esp         ;; push the current stack
call irq_handler
add esp, 4         ;; remove previous call?
mov esp, eax    ;;; get the new stack

pop gs
pop fs
pop es
pop ds
popad
add esp, 8   ;; remove int num and error code
iret
and my basic irq_handler

Code: Select all

void *irq_handler(struct regs *r)
{
void *sp = r;

return sp;
}
and the regs struct

Code: Select all

struct regs
{
unsigned int gs, fs, es, ds;
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
unsigned int int_no, err_code;
unsigned int eip, cs, eflags, useresp, ss;
};

Re: quick task switching question

Posted: Thu Jul 24, 2008 2:26 am
by lukem95
Erm... you do realise that's doing nothing? It just saves the stack, moves the address into EAX and then changes the stack to the address in EAX... which would be the SAME stack =/ unless you plan to add some code to that, it's doing nothing useful.

And that will occur for all IRQ's, including the PIT, HDD or any other hardware you've initiated... it would be better to assign it to one particular IRQ number.

Re: quick task switching question

Posted: Thu Jul 24, 2008 4:20 am
by octa
hmm.. u need to hav dynamic mem alloction. and also u r doin nothing there...
jus create new instances of structture and switch the register values savin the old one !!!!

Re: quick task switching question

Posted: Thu Jul 24, 2008 7:22 am
by itisiuk
yeah soz it missed out my other code :oops: and i do have dynamic mem allocation.
i dont have anywhere to post all my code so was just posting a little pices of it.
and yes i realize that, that piece of code is doing nothing
however in the full piece of code im changing the address stored in eax so it points to a new stack.

as for
And that will occur for all IRQ's, including the PIT, HDD or any other hardware you've initiated... it would be better to assign it to one particular IRQ number.
would this create any major problems with the code if i left it like this. which i think was the point i was trying to get at origonally.

Re: quick task switching question

Posted: Thu Jul 24, 2008 7:32 am
by AJ
The code you have will work if you have a switch statement in your irq handler - it will just be slower than if you had a specific scheduler interrupt handler.

Cheers,
Adam

Re: quick task switching question

Posted: Thu Jul 24, 2008 8:10 am
by itisiuk
cheers.

im just trying something different and i just want to get things working for now so
not really interested in speed at present, i can sort that out later.