Anonymous user
Interrupt Service Routines: Difference between revisions
→Black Magic: Asm goto under new section, and less opinionated about gotos and asm gotos
[unchecked revision] | [unchecked revision] |
m (reworded one sentence, looks more sane now) |
(→Black Magic: Asm goto under new section, and less opinionated about gotos and asm gotos) |
||
Line 134:
Neither gcc nor g++ offer any means (on x86 or x86-64) to have an interrupt service routine only in C or C++ without performing '''black magic'''.
Added===Black Magic===
Look at the faulty code [[Interrupt_Service_Routines#The_Problem|above]], where the proper C function exit code was skipped, screwing up the stack. Now, consider this code snippet, where the exit code is added manually:
Line 164:
This assumes that leave is the correct end-of-function handling - you are doing the function return code "by hand", and leave the compiler-generated handling as "dead code". Needless to say, such assumptions on compiler internals are dangerous. This code can break on a different compiler, or even a different version of the same compiler. It is therefore strongly discouraged, and listed only for completeness.
===Asm Goto===
Having read all the above warnings and still eager to have a solution for writing ISRs in C(++) code using gcc? Consider the following:
<source lang="c">
Line 181 ⟶ 182:
}
</source>
This code uses "asm goto" - a relatively new GCC-specific feature (see http://wiki.osdev.org/Inline_Assembly#asm_goto).
[[Category:Interrupts]]
|