Page 1 of 1
function's prologue/epilogue
Posted: Mon Jan 14, 2008 3:06 pm
by devel
Hi there,
has anybody experiences with implementing prologue/epilogue of function in gcc?
For example to change ret instruction to lret.
regards & thnx in advance,
devel.
Posted: Mon Jan 14, 2008 5:49 pm
by Combuster
The Good Thing (tm) is to use assembler to wrap up GCC functions for interrupts.
Posted: Mon Jan 14, 2008 6:42 pm
by mathematician
push ds
push es
push fs
push gs
push ebp
push eax
push ebx
push ecx
push edx
push esi
push edi
call _func
;next three lines for hardware interrupts only
; - assuming you're not using APIC
mov al, 20h
out 20h, al
out 0a0h, al
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
pop ebp
pop gs
pop fs
pop es
pop ds
iret
adjust as necessary for 64 bit mode
Posted: Tue Jan 15, 2008 12:43 am
by devel
Sorry for misunderstanding. I meant whether it is possible to override gcc's default
prolog/epilogue code? Is there any macro in gcc for handling this?
regards,
devel.
Posted: Tue Jan 15, 2008 2:10 am
by JamesM
No, it can't be done.
At least, when I was looking for a way to do it, I didn't find any.
Posted: Thu Jan 17, 2008 8:03 am
by XCHG
I don't know much C but I remember with Visual Studio, I could create
naked functions in which I got to write my own prologue and epilogue in pure assembly:
Code: Select all
int __declspec(naked) __stdcall Add (int a, int b){
__asm{
PUSH EBP
MOV EBP , ESP
MOV EAX , DWORD PTR [EBP + 0x08]
ADD EAX , DWORD PTR [EBP + 0x0C]
POP EBP
RET 0x08
}
}
I don't know but maybe there is a way around it also in GCC.
Posted: Thu Jan 17, 2008 10:16 am
by blound
XCHG wrote:I don't know much C but I remember with Visual Studio, I could create
naked functions in which I got to write my own prologue and epilogue in pure assembly:
Code: Select all
int __declspec(naked) __stdcall Add (int a, int b){
__asm{
PUSH EBP
MOV EBP , ESP
MOV EAX , DWORD PTR [EBP + 0x08]
ADD EAX , DWORD PTR [EBP + 0x0C]
POP EBP
RET 0x08
}
}
I don't know but maybe there is a way around it also in GCC.
From needing "naked" supoprt on another project, gcc only supports naked on some arches ( x86 not being one of them ), I got this from trying it myself, and a partner on the project reading the mailing lists and seeing one of the gcc devs saying "who would need this on x86..." - so it never got implemented
Posted: Thu Jan 17, 2008 10:28 am
by Brynet-Inc
I don't see a use to this... considering in such a "naked" function, you couldn't actually "have" any C code, (
The compiler couldn't automatically determine the convention you're using.. right?)
So what's the point? Why not just write the entire function in asm?
Just my opinion...