Xref: utzoo comp.os.msdos.programmer:5223 alt.msdos.programmer:2713 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!uunet!news.uu.net!nwnexus!amc-gw!jwbirdsa From: jwbirdsa@amc.com (James Birdsall) Newsgroups: comp.os.msdos.programmer,alt.msdos.programmer Subject: Re: Notes about Borland C++ interrupt keyword Message-ID: <1991May21.223853.12830@amc.com> Date: 21 May 91 22:38:53 GMT References: <1991May20.171545.23591@amc.com> <1991May21.140557.16018@cbnewsc.att.com> Reply-To: jwbirdsa@europa.amc.com (James Birdsall) Organization: Applied Microsystems, Redmond, WA Lines: 65 Allow me to clarify my earlier posting. Also please note that I was in a bad mood that day and not feeling kindly disposed toward the compiler in question. In article <1991May21.140557.16018@cbnewsc.att.com> tjr@cbnewsc.att.com (thomas.j.roberts) writes: >From article <1991May20.171545.23591@amc.com>, by jwbirdsa@amc.com (James Birdsall): >> Anyone writing interrupt handlers using TC++'s "interrupt" keyword >> should be aware that DS is not preserved into the function. DS is preserved >> through the function; the value of DS after the interrupt is the same as >> before. However, the value of DS while the function is executing is not the >> same as the value when it was called. The entry code pushes all the >> registers on the stack and then reloads DS with the value for the program's >> near data segment. >> >> This doesn't matter for most interrupt handlers, but if you're trying to >> revector an interrupt that uses DS as a parameter (for example, the DOS >> interrupt (0x21)), then it becomes a major obstacle. > >This is NECESSARY for Turbo C / Turbo C++ / Borland C++ functions to >work correctly (they may reference static variables). No. It is HANDY. There are other ways that interrupt functions could be allowed to address static data. They would require special code generation and run more slowly, so I can understand why they did it that way. Indeed, the fact that one can access global variables should have tipped me off, and as soon as I found out what was happening, I knew why. >It is well >documented in the manuals. Maybe. I took a fast look and didn't see it. Considering the experiences I've had with Borland documentation in the past, I wasn't hopeful. >If you need the caller's DS (or any other register), it (they) are >available as arguments to your interrupt function. This is not an obstacle, >it is an essential feature. I am astounded that you are attempting to use >this complicated CPU-dependent and compiler-dependent feature without >CAREFULLY reading the manuals. I was attempting to throw together a fast test program to determine whether setvect(), which I was trying to use in an entirely separate program to revector int 21h to an assembly-language handler, was corrupting DOS. It was based on their example under setvect(), which worked fine as given but crashed the system when revectoring 0x21 to a function which simply called the old handler. When I revectored manually, fprintf() would emit a line of junk but the system didn't crash, and suddenly I was enlightened. The original problem turned out to be a stack misalignment error aggravated by a confused debugger. The debugger would hang when the new handler chained back to the original handler, which was NOT the location of the bug that took out the system when the debugger was not used. Thus, it appeared that something was munging part of DOS and the only candidate I had was setvect(), because the program worked fine without it and the new handler was not writing to anyplace it wasn't supposed to... After a day like that (I didn't identify the original problem until after posting the article), you may understand why I was feeling betrayed by my compiler. :) -- James W. Birdsall WORK: jwbirdsa@amc.com {uunet,uw-coco}!amc-gw!jwbirdsa HOME: {uunet,uw-coco}!amc-gw!picarefy!jwbirdsa OTHER: 71261.1731@compuserve.com "The OS shouldn't die every time the controller drools on a sector." -- a sysop =========== "For it is the doom of men that they forget." -- Merlin ===========