quick task switching question

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
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

quick task switching question

Post 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;
};
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Re: quick task switching question

Post 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.
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
octa
Member
Member
Posts: 50
Joined: Sat Jun 28, 2008 9:15 am

Re: quick task switching question

Post 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 !!!!
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: quick task switching question

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: quick task switching question

Post 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
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: quick task switching question

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