if you 'move' the stack, so you just want it to be at another address (eg 0xE0000000 insetad of at 1MB), you wil need to determine top of the stack, copy all to the new address (top->current esp == to ==> 0xE0000000->(top-current esp+0xE0000000). That piece of math is calculating end of new stack using current stacks size
Then you will need to find all stored EBPs and change them. If you do not do this, no function can get its stack back, ESP will be corrupted, and boom! Finding and chanhing ESPs is tricky. You could do this: walk through the stack, if the data on it is an address between top and bottom of the old stack, change it to new address:
Code: Select all
// walk trough stack:
uint32_t *stack = oldTop;
while((uint32_t)stack > oldBottom)
{
// *stack contains data
if(*stack > oldBottom && *stack <= oldTop) // If points to stack
{
*stack = (*stack-oldBottom)+newBottom; // old address minus old bottom makes offset on stack (real addressing, no stack wise ;)). Then add new bottom, which then is new address.
}
stack--; // GCC will take 4 bytes off since its 4byte pointer
}
That would work. Try to use as much as ASM as possible, since THEN you have control over the stack (push, pop). GCC will use stack for loops too, so be warned:!: For copying stack use plain asm.
Good luck!
// Jarvix
Jinix. Kernel programming is a black art that should be avoided if at all possible.