Task Switching

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
shad

Task Switching

Post 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");
Tim

Re:Task Switching

Post by Tim »

No it's not. You need to set ESP to the end of the stack area. EBP is irrelevant here.
shad

Re:Task Switching

Post by shad »

so that same code with kmalloc(1024) + 1023 will work?
Tim

Re:Task Switching

Post 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).
shad

Re:Task Switching

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Task Switching

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

Re:Task Switching

Post by shad »

this is just not working out. i think im gonna go single task os...
beyond infinity lazy

Re:Task Switching

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