[comp.os.msdos.programmer] Turbo C Interrupt Question

shearer@cis.udel.edu (Rob Shearer) (10/10/90)

I have hooked the INT 8 interrupt (IRQ 0, Clock_Tick Interrupt) on my 
PC.  Normaly I want the routine to happen on a set schedule..  but there
are times that I want the INT 8 routines to occur out of sync and I call
it from another part of my code with a geninterrupt(8);  (I take care
of the REAL Clock no matter what...).  Can you Gurus inform me how to
detect if the interrupt was hardware or software driven??  It is all
probably in the PIC... but ALL my reference books basically inform me that
there IS such a think as the PIC.  

(Before anyone tells me to hook INT 1C instead..  I NEED INT 8, that is why
I hooked it...  and if I can differentiate between a hw and sw interrupt
then life is fantastic!)

Thanks in Advance... 
Robb Shearer
shearer@sol.cis.udel.edu

stever@Octopus.COM (Steve Resnick ) (10/10/90)

In article <32923@nigel.ee.udel.edu> shearer@cis.udel.edu (Rob Shearer) writes:
>
>I have hooked the INT 8 interrupt (IRQ 0, Clock_Tick Interrupt) on my 
>PC.  Normaly I want the routine to happen on a set schedule..  but there
>are times that I want the INT 8 routines to occur out of sync and I call
>it from another part of my code with a geninterrupt(8);  (I take care
>of the REAL Clock no matter what...).  Can you Gurus inform me how to
>detect if the interrupt was hardware or software driven??  It is all
>probably in the PIC... but ALL my reference books basically inform me that
>there IS such a think as the PIC.  
>
>(Before anyone tells me to hook INT 1C instead..  I NEED INT 8, that is why
>I hooked it...  and if I can differentiate between a hw and sw interrupt
>then life is fantastic!)
>

According to Joe Campbell in "C Programmer's Guide to Serial Communication"
the 8259 PIC has a register which indicates any pending interrupts. To
read this input a byte from port 21H, since you want IRQ0 (Timer) test bit
0 to see if it is set. If it is, you have a pending timer interrupt, otherwise
the int 8 was called via a software int. I haven't tried this, but it seems
pretty straight forward. 

Hope this helps....
Steve


-- 
----------------------------------------------------------------------------
steve.resnick@f105.n143.z1.FIDONET.ORG - or - apple!camphq!105!steve.resnick
Flames, grammar errors, spelling errrors >/dev/nul
----------------------------------------------------------------------------

ekalenda@cup.portal.com (Edward John Kalenda) (10/11/90)

I may be wrong, but the way I do it is to look at the return address on the
stack. By examining the instruction it points to (actually the instruction
before) to see if it is an INT will tell me if it is hardware or software.
A better method is to have the interrupt handler call a second routine with a
flag parameter to indicate the hardware/software nature of the caller. When
you call from software, call the second routine instead of the handler.

Ed
ekalenda@cup.portal.com

Ralf.Brown@B.GP.CS.CMU.EDU (10/11/90)

In article <34729@cup.portal.com>, ekalenda@cup.portal.com (Edward John Kalenda) wrote:
}I may be wrong, but the way I do it is to look at the return address on the
}stack. By examining the instruction it points to (actually the instruction
}before) to see if it is an INT will tell me if it is hardware or software.

That isn't foolproof, of course.  The instruction prior to the interrupt
could end in "CD xx"....
--
UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=- 412-268-3053 (school) -=- FAX: ask
ARPA: ralf@cs.cmu.edu  BIT: ralf%cs.cmu.edu@CMUCCVMA  FIDO: 1:129/3.1
Disclaimer?    |   I was gratified to be able to answer promptly, and I did.
What's that?   |   I said I didn't know.  --Mark Twain

prs@io.UUCP (Paul Schmidt) (10/12/90)

In article <32923@nigel.ee.udel.edu> shearer@cis.udel.edu (Rob Shearer) writes:
>...
>                                       Can you Gurus inform me how to
>detect if the interrupt was hardware or software driven??  It is all
>probably in the PIC... but ALL my reference books basically inform me that
>there IS such a think as the PIC.  

You'll need Intel's reference manual for the 8259A. Maybe you could read
IBM's BIOS listing in the tech ref, too. 

But my opinion is you should try to find a different algorithm for 
doing this....

KRW1@Lehigh (10/12/90)

You can check the in-service register of the interrupt controller
to see if irq 0 is active.  Output 0bh to port 20h and read it back.
Bit zero will be 1 if the irq 0 is active (other, lower priority bits
may be set as well, so be sure to mask it).  -- Kevin