TSR's & DOS Interrupts 
Author Message
 TSR's & DOS Interrupts

Quote:

> Whats the trick? The books I have say that DOS interrupts are too unstable
> to use within a TSR. I tried and as far as I can tell they are right. My
> system hangs. What gives? Do I have to do all my file I/O with BIOS
> Interrupts within a TSR? That would be a drag.....<sigh>.

As far as I know (I programmed a few TSR's), you always have to
use the BIOS, because DOS is not re-entrant...

Maybe someone can explain better than me what it exactly
means that DOS is not re-entrant?

                        -- George



Wed, 20 Aug 1997 03:35:42 GMT  
 TSR's & DOS Interrupts

Quote:

> > Whats the trick? The books I have say that DOS interrupts are too unstable
> > to use within a TSR. I tried and as far as I can tell they are right. My
> > system hangs. What gives? Do I have to do all my file I/O with BIOS
> > Interrupts within a TSR? That would be a drag.....<sigh>.
> As far as I know (I programmed a few TSR's), you always have to
> use the BIOS, because DOS is not re-entrant...
> Maybe someone can explain better than me what it exactly
> means that DOS is not re-entrant?

  It simply means that some routine A can not be called while routine A
is already executing ... hmmm is that very clear?  The DOS interrupt
routines use internal variables that are used whenever that routine is
called.  Now say DOS is opening a file when you pop up your TSR.  But
your TSR wants to open a file using DOS so it calls that same routine.  
This will overwrite the data DOS was using for the first call ... not good!

  Whenever you are writing TSR's that use variables that are not on the  
stack then you should be sure that your code can not be called again.
You could do one of the following:                              

  1)  keep interrupts disabled (cli)
  2)  set a flag (say 'inhandler') to true on entrance

._______________________________________________________________________.
_        David Cronin                   _  _    University of Alberta   _
_-     Silent Avenger [TCS]            <o><o>          Canada          -_


._______________________________________________________________________.



Wed, 20 Aug 1997 10:25:33 GMT  
 TSR's & DOS Interrupts
Whats the trick? The books I have say that DOS interrupts are too unstable
to use within a TSR. I tried and as far as I can tell they are right. My
system hangs. What gives? Do I have to do all my file I/O with BIOS
Interrupts within a TSR? That would be a drag.....<sigh>.

Thanx for your help.
jwebb



Tue, 19 Aug 1997 22:20:10 GMT  
 TSR's & DOS Interrupts

Quote:


>> Whats the trick? The books I have say that DOS interrupts are too unstable
>> to use within a TSR. I tried and as far as I can tell they are right. My
>> system hangs. What gives? Do I have to do all my file I/O with BIOS
>> Interrupts within a TSR? That would be a drag.....<sigh>.
>As far as I know (I programmed a few TSR's), you always have to
>use the BIOS, because DOS is not re-entrant...

>Maybe someone can explain better than me what it exactly
>means that DOS is not re-entrant?

It means that an interrupt routine cannot interrupt a DOS
function (i.e. open a file) start a TSR that then does the
same thing (open a file). But it is even worse than this,
because DOS is essentially 3 functions because DOS has
3 stacks.

Getting around this is fairly simple. DOS has a flag that
tells you whether it is active or not and calls a routine
(Int 28h) when it is OK to make DOS calls. However,
there are also a lot of other minor details and gotcha's.

See the book, Undocumented DOS for a more complete
explanation.

Mike Schmit

-------------------------------------------------------------------

408-244-6826                    Pentium Processor Programming Tools
800-765-8086                    ISBN: 0-12-627230-1
-------------------------------------------------------------------



Thu, 21 Aug 1997 04:35:22 GMT  
 TSR's & DOS Interrupts

Quote:
>Maybe someone can explain better than me what it exactly
>means that DOS is not re-entrant?

DOS cannot be re-entered when DOS is currently doing something.  For
example if DOS is currently in int 21h, function 48h (allocate memory) then
DOS is considered 'busy' and cannot be re-entered.  If your program
attempted to call int 21h then DOS might crash because the internal stacks
and internal variables will be over-written by your service of DOS and when
you release processor control back to whatever program you interrupted, DOS
will have your variables in its memory locations to use for the original
program that was in DOS.  And it is *POSSIBLE* (more than likely really)
that this will cause some major error and DOS will crash.

Fox



Fri, 22 Aug 1997 09:54:34 GMT  
 TSR's & DOS Interrupts

Quote:
>Whats the trick? The books I have say that DOS interrupts are too unstable
>to use within a TSR. I tried and as far as I can tell they are right. My
>system hangs. What gives? Do I have to do all my file I/O with BIOS
>Interrupts within a TSR? That would be a drag.....<sigh>.

        DOS & BIOS are non-reentrant, that's why you cannot work
asynchronously without fine tricks.

        Probably the following can help (refer to Tech Help! or Ralf Brown
Interrupt list for more info):

        * intercept Int 28h. DOS calls it whenever it enters input waiting
loops. Character functions are forbidden to use, but everything else is OK>

        * use 'DOS Safe' flag (see the references to find it). When it's
raised, DOS is already in use and shouldn't be called.

        * intercept DOS 21h vector and trace whether DOS is called or not.

        * not to use BIOS directly. In this case, all you have to do is to
check whether DOS is running or not.

        Besides, you should:

        * preserve Mouse state, if you plan to use mouse withing your TSR.

        * preserve EMM state, if you use EMS withing your TSR.

        * handle DOS 24h/23h (Critical Error/Break) handlers *correctly* so
that underlying software would not crash.

        * correctly write all hardware ISRs, to install them, if necessary,
on pop-up and destall before pop-down.

        You can also use Multiplexor (Int 2Fh) to check whether your TSR is
already installed etc.

        Hope that will help. I can post (later, when I find it... I used it
too much ago) a skeleton of TSR which handles these problems.

        Best regards,

Konstantin.


P.S. Please *post*, not *email* whenever possible.



Fri, 22 Aug 1997 17:14:42 GMT  
 TSR's & DOS Interrupts


Quote:

> Whats the trick? The books I have say that DOS interrupts are too unstable
> to use within a TSR. I tried and as far as I can tell they are right. My
> system hangs. What gives? Do I have to do all my file I/O with BIOS
> Interrupts within a TSR? That would be a drag.....<sigh>.

There is a widely documented "undocumented" flag in DOS (called the indos
flag) that can be tested to see if it is in the middle of a DOS call
currently.  This was/is used by PRINT.COM (the original TSR ;).
See Rolf's interrupt list or Schulman's "Undocumented DOS" book.

--mark



Sat, 23 Aug 1997 01:46:48 GMT  
 TSR's & DOS Interrupts

Quote:

> There is a widely documented "undocumented" flag in DOS (called the indos
> flag) that can be tested to see if it is in the middle of a DOS call
> currently.  

This "undocumented" flag is, indeed, "widely documented."  It's even
covered in the official MS-DOS PROGRAMMER'S REFERENCE from Microsoft
(v5.0 and 6.0).

There is, by the way, a whole lot more to safely using DOS inside
a TSR than just checking the InDOS flag.  In particular, you must:

 * Check the Critical Error flag.
 * Serialize the BIOS disk interrupt (Int 13h).
 * Save and restore DOS Critical Error information.
 * Install your own Critical Error handler for the duration.
 * Install your own Ctrl-C handler for the duration.
 * Install your own Ctrl-Break handler for the duration.
 * Set the Current Process ID, to your TSR's PSP for the duration.
 * If you use the DTA, switch to your own DTA for the duration.

(All the items noted as "for the duration" involve saving the foreground
program's value, and then restoring it at exit.)

...and I'm probably leaving out a couple of things, since this is just
off the top of my head, and before coffee.

The very best exposition of the details involved is still the
"Memory-Resident Software" chapter of Schulman et. al's UNDOCUMENTED DOS
(Addison Wesley, 1994, ISBN 0-201-63287-X).  It's a must-read for anyone
interested in writing TSRs that access DOS services.

---
Glen Blankenship



Sun, 24 Aug 1997 03:27:39 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Dos & WIN32 TSR's

2. Chaining interrupt 2F and tsr's

3. Interrupts in TSR interrupt handlers

4. How to Creat Safe Tsr's under Dos and Win95

5. TSR's in Ms-Dos

6. Make a TSR don't detected by DOS

7. DOS interrupts & asm instructions

8. DOS interrupts & asm instructions

9. TSR's & VARIABLES

10. DOS Interrupt/BIOS interrupt function reference

11. TSR's & VARIABLES

12. TSR Interrupt problem

 

 
Powered by phpBB® Forum Software