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.
function's prologue/epilogue
- mathematician
- Member
- Posts: 437
- Joined: Fri Dec 15, 2006 5:26 pm
- Location: Church Stretton Uk
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
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
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:
I don't know but maybe there is a way around it also in GCC.
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
}
}
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
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 implementedXCHG 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:
I don't know but maybe there is a way around it also in GCC.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 } }
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact: