[comp.os.msdos.programmer] MS C/QC "_loadds" and stack checking

mlf@genrad.UUCP (Matt Fichtenbaum) (04/01/91)

Well, I thought I'd solved this before, but it turned up
again, so now I've _really_ solved it :-).

I used the mouse driver call (int 33h, func. 0Ch) to set a
routine that would be called to handle mouse interrupts.
According to the mouse driver documentation, the routine is
called with a far call, with DS set to the mouse driver's
data segment.

Fine.  MS C and QuickC (and Borland, too) provide the "_loadds"
keyword to tell the compiler to set DS appropriately when the
routine is entered.  Only, sometimes the program would crash
on a mouse interrupt.  Changing the order in which object
modules were linked sometimes helped.

Well, the problem is the "check stack" option of the Microsoft
compilers.  Programs call the stack checking routine on entry;
in a "loadds" routine, the stack check occurs _before_ the loadds.
If conditions are unfavorable, things fail.

Solution: (1) use the
#pragma check_stack(off)
macro to suppress stack checking around the handler, or (2) don't
use stack checking at all.  Or, (3), I suppose, use different
compilers.