Mail Archives: djgpp/2007/03/01/04:16:49
"Glaux" <glaux AT centrum DOT cz> wrote in message
news:1172695353 DOT 457041 DOT 104610 AT h3g2000cwc DOT googlegroups DOT com...
> Hi,
> I found that some guy ask for this attribute 2 years before without
> reply. Now I also run to situation where need to make
> __attribute__((naked)) function. Is there some better way than use
> array of bytes constant with binary assembled code which I would call
> as a code?
>
I know of no method to do this in DJGPP. Unfortunately, DJGPP is able to
produce a number of different stack frames. This code snippet shows how I
create "naked" functions for DJGPP. I use the 'leave' instruction to undo
the stackframe for simple 'void xxx(void)' functions. This won't work if
your function needs arguments or returns arguments. You shouldn't need them
for an interrupt wrapper from assembly to C. Also, -fomit-frame-pointer
changes the way the frame is created, i.e., don't use...
#ifdef __DJGPP__
#if 0
#define FOMIT /* for -fomit-frame-pointer */
#endif
/* LEAVE will undo the stack frame for **simple** DJGPP procedures. */
/* i.e., void xxx(void) */
/* This allows the use of an retf,iretf, or jmp out of the procedure. */
#ifdef FOMIT
#define LEAVE
#else
#define LEAVE "leave\n"
#endif
#define __declspec(naked)
#endif
/* '__declspec(naked)' for WATCOM to eliminate stack frame. */
/* removed by empty preprocessor define for DJGPP */
void __declspec(naked) iret_special(void)
{
#ifdef __DJGPP__
__asm__ (
LEAVE
"iretl\n"
);
#endif
#ifdef __WATCOMC__
_asm {
.386
iretd
}
#endif
}
Rod Pemberton
- Raw text -