[comp.os.msdos.programmer] Is _chain_int safe in MSC 5.1?

cyamamot@kilroy.jpl.nasa.gov (Cliff Yamamoto) (02/28/91)

Greetings!

I'm about to redirect some interrupts into some code I'm hooking
onto Int 8 or 1C.  When I comes down to calling the 'savedintvector'
I'd like to call it safely.  Can I just call it or should I call it
through the _chain_int function?

I'm also using _dos_setvect and _dos_getvect which use the Int 21 interface
but I'm still don't understand where a new stack is created for the
interrupt routine.  Since DOS is not reentrant, I know its stack has to be
left alone while the interrupt uses its own stack.  Does _dos_setvect
and _dos_getvect take care of creating and deleting a new stack for me?

The reason I'm wondering whether to use _chain_int or not is because I'm
not sure exactly what it does.  I just don't want to risk clobbering the
DOS stack (which probably isn't very big) if my interrupt routine starts
using the stack heavily.  I don't intend to call any DOS routines in my
interrupt.

BTW. What the heck does the keyword 'interrupt' mean in MSC 5.1?  I can't
     find it described anywhere.  Does this somehow take care of keeping
     the DOS stack in order for me?

Any info or pointers to good literature/PD code would be appreciated.

Regards,
Cliff Yamamoto
----------------------------------------+--------------------------------------
Email:  cyamamot@kilroy.jpl.nasa.gov    |     cyamamot@grissom.jpl.nasa.gov
        cyamamot@jato.jpl.nasa.gov      |     cky@euclid.jpl.nasa.gov
        cky@hydra.jpl.nasa.gov          |     
----------------------------------------+--------------------------------------
MaBell: (818) 354-1242 - off.   (818) 354-6042 - alt.   (818) 354-6426 - lab.

rkl@cbnewsh.att.com (kevin.laux) (02/28/91)

In article <1991Feb28.081734.21649@elroy.jpl.nasa.gov>, cyamamot@kilroy.jpl.nasa.gov (Cliff Yamamoto) writes:
> Greetings!
> 
> I'm about to redirect some interrupts into some code I'm hooking
> onto Int 8 or 1C.  When I comes down to calling the 'savedintvector'
> I'd like to call it safely.  Can I just call it or should I call it
> through the _chain_int function?

	You must chain to it, especially as you are working with the system
timer ticks.

> I'm also using _dos_setvect and _dos_getvect which use the Int 21 interface
> but I'm still don't understand where a new stack is created for the
> interrupt routine.  Since DOS is not reentrant, I know its stack has to be
> left alone while the interrupt uses its own stack.  Does _dos_setvect
> and _dos_getvect take care of creating and deleting a new stack for me?

	_dos_setvect only take care of insuring that the interrupt vector is
installed under safe conditions.  It's not suprizing that you don't understand
where a new stack is created because there isn't one created.  An interrupt
handler gets the stack that was in use at the time the interrupt occured, be
it in DOS or in an application program or whatever.  If you need your own
stack, you have to do it yourself.

> The reason I'm wondering whether to use _chain_int or not is because I'm
> not sure exactly what it does.  I just don't want to risk clobbering the
> DOS stack (which probably isn't very big) if my interrupt routine starts
> using the stack heavily.  I don't intend to call any DOS routines in my
> interrupt.
>
> BTW. What the heck does the keyword 'interrupt' mean in MSC 5.1?  I can't
>      find it described anywhere.  Does this somehow take care of keeping
>      the DOS stack in order for me?

	The 'interrupt' (or _interrupt in MSC 6.0) keyword tells the compiler
that your function is an interrupt handler and causes code to be generated
that sandwiches the code you write.  What happens is that upon entry to the
function all the registers are pushed onto the stack and then AX gets loaded
with your program's data segment which is then moved to DS.  When the function
'returns' all the previously pushed registers get popped off the stack and
an IRET instruction is used instead of the normal RET.  As stated above,
the stack in use is the one when the interrupt happened.

	_chain_int pops the registers off the stack that were pushed upon
entry to your interrupt function and then does a far jmp to the vector that
you called _chain_int with.  It does not return as the handler it vectored
to will do an IRET (or an RETF 2, if it needs to return with CPU Flags (un)set)
to end the interrupt.

> Any info or pointers to good literature/PD code would be appreciated.

	Try the _DOS Programmer's Reference, 2nd Ed_, published by Que.
ISBN is 0-88022-458-4.  Also _Undocumented DOS_, published by Addison/Wesley.
ISBN is 0-201-57064-5.  This book is also discussed in the March 1991 issue
of Byte.

-- 
________________________________________________________________________________

	R. Kevin Laux				Email: rkl1@hound.att.com
	AT&T Bell Labs				Voice: (908) 949-1160