www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/25/21:48:23

Message-Id: <199904260148.SAA28421@geocities.com>
From: cssl AT geocities DOT com
Sender: cssl AT mail DOT geocities DOT com
To: djgpp AT delorie DOT com
Date: Mon, 26 Apr 1999 03:40:22 GMT0BST
MIME-Version: 1.0
Subject: Hooking interrupts: VERY strange behaviour !
X-mailer: Pegasus Mail v3.31
Reply-To: djgpp AT delorie DOT com

Hello All.

I'm doing some tests on IRQ hooking, and I've got some strange results. 
The following program (partially copied from PDMLWP sources) on my 
machine, the FIRST time it's run it prints "cnt=1", all the following 
times it prints "cnt=7" or "cnt=8", that's the result I'm expecting...

Can some1 please help me ?

#include <dos.h>
#include <dpmi.h>
#include <go32.h>
#include <stdio.h>
#include <unistd.h>

#define IRQ8	0x70

static void
setRTC (int value)
{
 unsigned char shtuff;
 disable();
 outportb(0x70, 0x0A);	/* output status a   */
 shtuff = inportb(0x71);/* get current status */
 outportb(0x70, 0x0A);	/* outputing to status a */
 outportb(0x71, (shtuff&0xF0)|(value&0x0F));
 enable();
}

static void
startIRQ8 (void)
{
  unsigned char shtuff;
  disable ();

  shtuff = inportb(0xA1);	/* Enable PIC interrupts */
  outportb(0xA1, shtuff & ~1);

  outportb (0x70, 0x0B);        /* status B */
  shtuff= 0x40 | inportb (0x71);/* get status & mask off interrupt enable bit */
  outportb (0x70, 0x0B);        /* status B again */
  outportb (0x71, shtuff);      /* output new value */
  outportb (0x70, 0x0C);        /* status C */
  inportb (0x71);               /* ack interrupt */

  enable ();
}

static void
stopIRQ8 (void)
{
  unsigned char shtuff;
  disable ();

  shtuff = inportb(0xA1);	/* Disable PIC interrupts */
  outportb(0xA1, shtuff | 1);

  outportb (0x70, 0x0B);        /* status B */
  shtuff= 0xBF & inportb (0x71);/* get status & mask off interrupt enable bit */
  outportb (0x70, 0x0B);        /* status B again */
  outportb (0x71, shtuff);      /* output new value */
  outportb (0x70, 0x0C);        /* status C */
  inportb (0x71);               /* ack interrupt */

  enable ();
}

static int cnt=0;

void proc(void)
{
 cnt++;
}

int main(void)
{
 _go32_dpmi_seginfo old, new;
 _go32_dpmi_get_protected_mode_interrupt_vector(IRQ8, &old);

 new.pm_selector=_go32_my_cs();
 new.pm_offset=(int)proc;
 _go32_dpmi_chain_protected_mode_interrupt_vector(IRQ8, &new);

 setRTC(0x0E);	// 4Hz

 startIRQ8();

 sleep(2);

 stopIRQ8();

 printf("cnt=%d\n", cnt);

 _go32_dpmi_set_protected_mode_interrupt_vector(IRQ8, &old);

 return 0;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019