Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!petera From: petera@utcsri.UUCP (Smith) Newsgroups: net.micro.pc Subject: Re: Interrupts and Microsoft C Message-ID: <2873@utcsri.UUCP> Date: Fri, 30-May-86 08:56:44 EDT Article-I.D.: utcsri.2873 Posted: Fri May 30 08:56:44 1986 Date-Received: Fri, 30-May-86 09:58:02 EDT References: <674@hou2f.UUCP> Organization: CSRI, University of Toronto Lines: 54 > > > I have an interrupt service routine which is linked with > my Microsoft 'C' application program. When the program is started > it installs the pointer to the service routine in the vector table. > As soon as the first interrupt is generated I get a stack overflow > message on the screen and the system hangs. If I disable the external > interrupt source everything works fine. Sounds like a problem in the > interrupt service routine. > > History: > This service routine is written in assembler and works fine when > linked with compiled MS basic. To link with 'C' I changed it > to assume the _TEXT segment for code and DGROUP for data, bss, and > stack, as per the Microsoft 'C' manual. I allocated more stack during > the linking phase but that didn't seem to help. > > One thing that I'm doing that may be a problem is the way I > install the interrupt vector. Rather than using the get/set interrupt > vector functions in DOS I just poke the segment and offset into the > vector page at address 0x2c (IRQ3). I don't understand why this should > cause a problem. I did it this way with the compiled basic version. > > > Is there anything special I need to do when installing a > interrupt service routine which is used by a Microsoft 'C' > program. Any comments or code examples would be welcome. > > > Thank You, > > John Antrosiglio > ATT-Bell Labs > ihnp4!hou2f!jca Re: Installing an interrupt service routine in C. Since you are getting a stack overflow what is probably happening is that the Lattice/Microsoft Compiler is generating stack checking code. Ie every time a function is entered it compares the stack top pointer with some maximum value, if it is greater it then aborts with a 'stack overflow' message. The reason you are getting this is due to the fact that the stack at the time of the interrupt will not be the same one that the C program is using, the segment may even be different. It is ok to use this stack, but only for about 20 or 30 pushes. In any case the C stack checking code will most of the time catch the fact that the stack top is wrong. There are two solutions. 1: Disable the stack checking code when you compile this module or 2: Alter the stack overflow trap routine to do nothing. Note that when you trap the interrupt in C you cannot do any calls to read/write/malloc etc because they all result in an INT which will when it returns, prematurely switch on your interrupts. Peter Ashwood-Smith University Of Toronto.