Page 1 of 1

Task Switching

Posted: Sat May 10, 2003 1:27 pm
by shad
For some reason im getting a GPF. The stack is setup perfectly fine from what i can see..

stack = (ulong32 *) kmalloc(1024) ;
ptr = (ulong32 *) (stack - 20);
ptr[0] = eip (task function addr)
ptr[1] = 8; (sys code sel)
ptr[2] = 0x0200; (ints enabled)

__asm__("mov %0, %%esp"::"m"(stack));
__asm__("mov %0, %%ebp"::"m"(stack - 1024));
__asm__("iret");

Re:Task Switching

Posted: Sat May 10, 2003 3:02 pm
by Tim
No it's not. You need to set ESP to the end of the stack area. EBP is irrelevant here.

Re:Task Switching

Posted: Sat May 10, 2003 6:59 pm
by shad
so that same code with kmalloc(1024) + 1023 will work?

Re:Task Switching

Posted: Sun May 11, 2003 5:01 am
by Tim
I can't say for sure. But those lines won't be broken if you have esp = kmalloc(1024) + 1024 (note: 1024 not 1023).

Re:Task Switching

Posted: Sun May 11, 2003 6:21 am
by shad
I notice that when i attempt to "manually" put these values on the new stack, no matter what i get a GPF. But if i swithc the stack 1st and then push the values, it works fine... but thats no good

Re:Task Switching

Posted: Mon May 12, 2003 3:51 am
by Pype.Clicker
hey, watch out! you allocated 1024 bytes of stack and are trying to access ((ulong*) stack) - 1024 ... remember C will multiply 1024 by sizeof(ulong) which is 4, so you're writing out of your data area !!

Nothing good can result of this, imho.

Run gcc -S and study the assembler that results of your C code, you'll better see what you're doing than if you were blindly typing C code :)

ot: use [ code ] ... [ /code ] when you're posting code so that it doesn't get messed up by YaBB.

Re:Task Switching

Posted: Tue May 13, 2003 10:13 am
by shad
this is just not working out. i think im gonna go single task os...

Re:Task Switching

Posted: Tue May 13, 2003 1:22 pm
by beyond infinity lazy
Nay shad, do not give up! It isn't difficult, it is just a question of going down to the nitty gritty in the right order - kinda chicken and egg thing it is.

Now tell, where exactly lies your problem gosh?