Xref: utzoo comp.os.msdos.programmer:5188 alt.msdos.programmer:2699 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!cbnewsc!tjr From: tjr@cbnewsc.att.com (thomas.j.roberts) Newsgroups: comp.os.msdos.programmer,alt.msdos.programmer Subject: Re: Notes about Borland C++ interrupt keyword Message-ID: <1991May21.140557.16018@cbnewsc.att.com> Date: 21 May 91 14:05:57 GMT References: <1991May20.171545.23591@amc.com> Organization: AT&T Bell Laboratories Lines: 40 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). It is well documented in the manuals. 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. Note that unlike normal C functions, modifying the parameters to an interrupt function within the function will change the values of registers used by the caller upon its return - great care is needed! READ THE MANUAL! The truly hard thing to do is to chain to the previous interrupt handler with the caller's registers, and arrange for the previous handler to return registers to the caller (this is usually what you want to do when "wrapping" int 21H, et al). Borland did not include an appropriate function in the library (I believe it would really need to be a "psuedo-function", as its semantics could not be those of a normal C function). Thus, to do this you must use assembly language to restore the stack and registers and then jump to the previous handler's address (without modifying ANY registers!). It can be done, but is subtle..... Tom Roberts att!ihlpl!tjrob TJROB@IHLPL.ATT.COM