Page 1 of 1
pop ebp a no no?
Posted: Sun Dec 14, 2003 2:50 am
by mr. xsism
after fixing a bootloader problem for my NEW FAT12 bootloader i have run into some kernel problems not experienced before. I have found and fixed 1 with a lovely hackman disassembler. It was pop ebp. I simply recoded the assembly function to not use ebp so i wouldn't have to pop it.
Now i have found another proble and guess what? The problematic code is a 'pop ebp'. This ASSEMBLY function looks like this:
Code: Select all
; void outportb(dword port,byte value)
[global outportb]
outportb:
push ebp
mov ebp, esp
mov edx, [ebp+8]
mov al, [ebp+12]
out dx, al
pop ebp
retn
and i edited it like so:
Code: Select all
; void outportb(dword port,byte value)
[global outportb]
outportb:
;push ebp
;mov ebp, esp
mov edx, [esp+4]
mov al, [esp+8]
out dx, al
;pop ebp
retn
Unfortunately it still isn't being set right and i think i may have to do with the offset of the stack i chanaged it to.
But i changed the last function in the same way as above and it fixed the problem. Is there som sacredness that GCC has with EBP?? :S
Thanks,
mr. xsism
Re:pop ebp a no no?
Posted: Sun Dec 14, 2003 4:37 am
by df
the
is common stackframe code. you function looks fine to me, which suggests something else is wrong.
Re:pop ebp a no no?
Posted: Sun Dec 14, 2003 4:47 am
by Perica
..
Re:pop ebp a no no?
Posted: Sun Dec 14, 2003 7:29 am
by Curufir
Aren't those stack offsets wrong in the first example? I would have thought it would be 4 and 8, not 8 and 12. Bah, maybe I just need more coffee ;D.
Re:pop ebp a no no?
Posted: Sun Dec 14, 2003 7:51 am
by Candy
Curufir wrote:
Aren't those stack offsets wrong in the first example? I would have thought it would be 4 and 8, not 8 and 12. Bah, maybe I just need more coffee ;D.
Jolt cola seems to help too
(drank over 2l cola today...)
You have a 4-byte EBP and a 4-byte EIP, so you add 8 and 12 for the 0th and 1st argument resp.
If you take the ebp away, you still keep the EIP, so it's 4 and 8. They're correct, no question about that. What is wrong, I don't know.
If it was my kernel, I'd start searching around the stack size, something overwriting (or being overwritten by) my stack, or the kernel loader possibly missing or not mapping some parts of the kernel.
Re:pop ebp a no no?
Posted: Sun Dec 14, 2003 8:34 am
by richie
I'm not sure but I would try to save all used registered (edx, eax). And I would use eax instead of al when fetching the parameter.
So my suggestion is:
Code: Select all
; void outportb(dword port,byte value)
[global outportb]
outportb:
push ebp
mov ebp, esp
push eax
push edx
mov edx, [ebp+8]
mov eax, [ebp+12]
out dx, al
pop edx
pop eax
pop ebp
retn
Re:pop ebp a no no?
Posted: Sun Dec 14, 2003 10:08 am
by Tim
No need to save EAX as the calling function expects it to be destroyed anyway, in case the outportb function was to return a value. Similarly EDX would be used for certain return value types, so this is expected to be destroyed too.
Stack frame initialisation prolog (PUSH EBP/MOV EBP, ESP) and teardown epilog (MOV ESP, EBP/POP EBP) aren't necessary here, since the outportb function doesn't use any local variables. But if you do remove the function prolog and epilog, remember to convert EBP references to parameters to ESP references and subtract 4 from each offset.
Re:pop ebp a no no?
Posted: Sun Dec 14, 2003 7:38 pm
by mr. xsism
well i'm not using ebp as you can see. It works. Why else would popping ebp cause a triple? OY!!! Well for now it works without ebp so i use [esp+offset]. The first var is +4 right and so on in 4byte incs???
I'm going to try to write a mouse driver right quick and see if there are problems there too....
so tired....