Path: utzoo!utgpu!watmath!uunet!bu-cs!spdcc!ima!esegue!johnl
From: johnl@esegue.uucp (John Levine)
Newsgroups: gnu.gcc
Subject: Re: interrupt handlers
Summary: yetch
Message-ID: <1989Aug9.020658.2482@esegue.uucp>
Date: 9 Aug 89 02:06:58 GMT
References: <8908082020.AA17430@ee.ecn.purdue.edu>
Reply-To: johnl@ima.isc.com (John Levine)
Distribution: gnu
Organization: Segue Software, Cambridge MA
Lines: 38

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