johnl@esegue.uucp (John Levine) (08/09/89)
In article <8908082020.AA17430@ee.ecn.purdue.edu> lewie@EE.ECN.PURDUE.EDU (Jeff Lewis) writes: >Say one wanted to define an interrupt handler entirely in C (GNU C, that is). In many PC compilers, there is a poorly documented keyword "interrupt" so you can say this: void interrupt foo_handler(bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, flags, ...) { ... } It tells the compiler to save all of the registers in the prolog rather than just the usual savable ones, and to restore them and generate a "return from interrupt" in the epilog. The optional arguments (which you needn't declare if you don't care about them) are the saved registers on the stack so you can look at them and change them. There are standard routines that let you install pointers to such routines into interrupt vectors. This swell feature turns out to be completely useless. On the PC you cannot assume that there is enough room on the interrupt-time stack to do any more than save your context, so you need to switch to a stack private to the interrupt handler. The code generated by Turbo and Microsoft C, at least, doesn't do that and there is no way to tell the compiler to do a stack switch. If your interrupt is caused by an external device, you need to issue an OUT instruction just before the RTI to tell the interrupt controller to dismiss the interrupt, and the compilers don't do that either. Real interrupt routines always need a modest amount of assembler glue. I suspect that in any real architecture, there will be a few little warts in the way interrupts are handled that make it hard to provide the compiler with a general interrupt handler that it can generate. The assembler glue code required is always short but never quite trivial. I don't think it's worth the effort to shove the whole thing into the compiler. -- John R. Levine, Segue Software, POB 349, Cambridge MA 02238, +1 617 492 3869 {ima|lotus}!esegue!johnl, johnl@ima.isc.com, Levine@YALE.something Massachusetts has 64 licensed drivers who are over 100 years old. -The Globe
Leisner.Henr@XEROX.COM (marty) (08/09/89)
[ John Levine sez: I suspect that in any real architecture, there will be a few little warts in the way interrupts are handled that make it hard to provide the compiler with a general interrupt handler that it can generate. The assembler glue code required is always short but never quite trivial. I don't think it's worth the effort to shove the whole thing into the compiler. ] I agree whole-heartedly with the above statement. I also feel if a programmer wants to perform such low-level, hardware dependent, non-portable work as interrupt handling, he should know how to do it himself and understand the necessary glue. [ John sez: In many PC compilers, there is a poorly documented keyword "interrupt" so you can say this: void interrupt foo_handler(bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, flags, ...) ] The interrupt an abomination. It doesn't really work. I see people use it since they don't know the details of generating the glue themselves. I don't know how they expect to ever be able to debug their code when it breaks. Real programmers write their interrupt handlers in assembler! marty ARPA: leisner.henr@xerox.com GV: leisner.henr NS: leisner:wbst139:xerox UUCP: hplabs!arisia!leisner