Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!ji.Berkeley.EDU!shebanow From: shebanow@ji.Berkeley.EDU (Mike Shebanow) Newsgroups: comp.arch Subject: Re: Interrupt vectors. Message-ID: <19253@ucbvax.BERKELEY.EDU> Date: Fri, 5-Jun-87 15:18:39 EDT Article-I.D.: ucbvax.19253 Posted: Fri Jun 5 15:18:39 1987 Date-Received: Wed, 10-Jun-87 00:44:30 EDT References: <7408@boring.cwi.nl> <2878@pyramid.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: shebanow@ji.Berkeley.EDU.UUCP (Mike Shebanow) Distribution: world Organization: University of California, Berkeley Lines: 59 Keywords: interrupt handlers Summary: Here is a reason for a single interrupt routine In article <2878@pyramid.UUCP> csg@pyramid.UUCP (Carl S. Gutekunst) writes: >In article <7408@boring.cwi.nl> jack@cwi.nl (Jack Jansen) writes: >> If you want to handle interrupts in a high-level >>language, you want all interrupts to jump to the same routine, and >>have the interrupt number handy somewhere. > >I can't for the life of me see why you'd want this. Here's why: Assume a machine (when it interrupts) (like a 68010, 68020) pushes the PSW, PC, and the interrupt vector number: +---------------+ SP-> | PSW | +---------------+ | PC | +---------------+ | IVECT | +---------------+ An interrupt handler could then be written once in assembly: .globl i_entry .extern i_table i_entry: movem.l ???,-(sp) * save all registers which C doesn't save move.? ivect(sp),r0 * get the interrupt vector number move.l i_table(r0),r1 * get a handler routine address push r0 * pass vector number as argument jsr (r1) * call handler add #4,sp * pop ivect number argument movem.l (sp)+,??? * unsave registers rte * return from interrupt Now all one needs to do to set up an interrupt handler (in C) is define the "i_table" contents: extern void handler_1(), handler_2()....; void (*i_table[])() = { handler_1, /* called for interrupt vector #1 */ handler_2, /* called for interrupt vector #2 */ etc..., }; The handler routines are now all pure C -- no assembly at all. Having written many many drivers, this would be a blessing. If you really want to know where this is nice, try writing a driver for a multiple UART board (one which has for example, 8 UARTs all of the same type with three interrupt service routines each -- receive, transmit, and control). I know -- I had to write one once. With standard machine architectures (68000), one has to have this asm glue code in each routine, one for each uart/interrupt (24 in all). This makes for a large asm file. If the ivect number is passed, a three common routines can be used -- the ivect number is used to tell which uart interrupted (a unique ivect is assigned to each uart). This makes life a lot easier. Mike Shebanow