delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/24/03:20:08

Date: Mon, 24 Mar 1997 11:00:25 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Neil Stone <Neil_Stone AT CyberServices DOT Com>
cc: djgpp AT delorie DOT com
Subject: Re: Hooking int 21h and other stuff
In-Reply-To: <3335D83A.2CC9@CyberServices.Com>
Message-ID: <Pine.SUN.3.91.970324104713.1059M-100000@is>
MIME-Version: 1.0

On Mon, 24 Mar 1997, Neil Stone wrote:

> I have been trying to hook the DOS interrupt, 21h, but have been
> unsuccessful in my attempts.  I have been able to hook other interrupts
> of interest, keyboard, timer, etc.  But no matter what I do my computer
> always crashes when hooking the DOS one.  Are then any special
> precautions I should take, what registers do I need to save and restore
> before calling the old ISR?

You should begin by reading section 18.9 of the DJGPP FAQ list (available 
as v2/faq210b.zip from the same place you get DJGPP), especially the part 
thereof which describes how to hook interrupts in real mode.  Int 21h is 
a software interrupt, so it's not reflected to protected mode like 
hardware ints are; therefore, you will have to either write a real-mode 
code for your handler, or use the wrappers provided by DJGPP.  In any 
case, you need to install a *real-mode* interrupt handler, not a 
protected-mode one.

> I haven't actually tried this in DJGPP, I
> tried it at college - I'm 16, using TC 3.0 but I don't think DJGPP would
> be much different.

It's *very* different, because DPMI rules for hooking a real-mode 
interrupt are tricky.  In fact, I'd advise against hooking Int 21h at 
all, unless you have no other way of achieving your goals otherwise.  
For starters, the DJGPP wrappers are non-reentrant, so you will need to 
either augment them or roll your own.

> Does it need to be locked?

Locking it will solve a lot of problems, yes.  If it isn't locked, its 
code and/or data might not be present when Int 21h is issued, so the DPMI 
host will issue a DOS call to page the handler in, and since DOS is 
non-reentrant, your program will immediately depart into the never-never 
land...

> I have a DOS segment:offset address how do I get a selector:offset and
> how do I use this selector to access memory.

Not enough details to answer that.  Please describe the setup in which 
you need this.  Is that in the real-mode handler?  Is that in your 
program outside the Int 21h handler?  Which part of DOS memory do you 
need to access?

- Raw text -


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