ITchimp wrote:I have got some really weird bugs... the base pointer changes mysterious to garbage on the execution path...
from c00f6f4c to 001048e8, by executing leave...
You have a corrupted stack problem.
ITchimp wrote:and leave is not supposed to change ebp
Yes, it's supposed to change ebp! This is how it works: in each function, ebp should point to the stack where the function's local variables start. Obviously when you return from a function, you must restore ebp to the caller function's local variables start.
In
function prologue, ebp is pushed on the stack, and set to esp. This way ebp gets the top of the stack for the function call. This is called "creating a stack frame".
In
function epilogue, all local variables should be removed from the stack (by setting esp to the stack top stored in ebp), then the previous ebp popped. This is called "leaving a stack frame". Because the ebp value that was pushed in the prologue is popped, the top of the stack now must point to the caller's address (and will be popped by the "ret" instruction).
You can do this with a pair of push+mov and mov+pop instructions, but some architecture (like x86_32) has special instructions to do so, like your "leave" instruction for example. If this doesn't work, that means only one thing: your stack is corrupted!
To debug, dump the stack AFTER the function prologue, and BEFORE the function epilogue (in other words, before the "leave" instruction). The two stack dumps must be identical to work correctly. (FYI: bochs debug has a "print-stack" command). If you change the stack in an interrupt handler (like for a context switch) then make sure that the new stack contains a stack frame pointer and a return address as well, otherwise you can't return from that function.
Cheers,
bzt