Post
by Mike » Tue Sep 22, 2009 4:48 am
Hello,
It is important to note that the code that handles the stack is Microsoft Visual C++ specific. The add esp, 12 is to undo an operation that the normal Visual C++ eprologue code adds at the beginning of _cdecl functions.
To get around this in another compiler, there are three methods:
-Using assembly language for the IRQ handlers, and link them to your C code.
-Using a GCC-specific extension to allow flat routines (without any eprologue/prologue code, simular to Visual C++'s _declspec (naked))
-Disassembling the interrupt handler to adjust your stack changing code to suite your needs based upon the eprologue code added by GCC. i.e., if the eprologue code adds elements to the stack, you must remove them before using iret/iretd. Else, it will fail do to a now corrupt stack. (This is what the series currently does when with add esp, 12 when building with Visual C++.)
-I suppose you can also guess - changing the add esp, 12 to different values. Might be easier to disassemble though. Values are usually in multiples of 4: 4, 8, 12, 16.