www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/30/22:46:40

Xref: news2.mv.net comp.os.msdos.djgpp:5554 comp.os.msdos.programmer:26029
From: Wuschel <heiko DOT friedel AT phil DOT tu-chemnitz DOT de>
Newsgroups: comp.os.msdos.programmer,comp.os.msdos.djgpp
Subject: Re: Help please! protected mode "TSR"'s
Date: Sun, 30 Jun 1996 23:49:36 +0200
Organization: TU-Chemnitz
Lines: 112
Message-ID: <31D6F670.709@phil.tu-chemnitz.de>
References: <31D6CE63 DOT 353587C0 AT beattie DOT demon DOT co DOT uk>
NNTP-Posting-Host: tiwu.csn.tu-chemnitz.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Shaune Beattie wrote:
> 
> Hi,
> Basically I want to write a program that traps a HW interrupt while a
> DPMI32 program is running.
> Obviously writting a normal "real" mode TSR is no good as interrupts are
> passed to the protected mode first (and the program in question will
> also be hooking the same interrupt I want to).

[snip]

> however the program will be running under a dpmi v0.9 host.. and hence I
> can't use the 1.0 spec functions..
> 
> so somehow I need to kludge it...
> 
> my thought is that if I install a normal real mode tsr on an real mode
> interrupt that I know the target program will also call.. then I can
> then make calls to the dpmi host that has been loaded to run the target
> program, hopefully then what I can do is call the int 31H routines to
> obtain the real mode to protected mode switch routine.. call it.. then
> allocate some protected mode memory, allocate a descriptor and point it
> at that memory, setting it to be executable, 32bit etc.
> then copy the rest of the real mode tsr routine (which is actually the
> 32bit protected mode program) into that memory, finally calling into
> it..
> that program will then hook the protected mode interupts as normal etc.
> 
> first of all, this is pretty horendous.. any easier ways of doing it?
> secondly what are the chances of it working?

Depends, some dpmi hosts do not support multiple clients. (DOS- 
extenders etc.) IOW: never trust a DPMI host to exactly meet the specs!

Anyway, AFAIK INT 31 can be called only while in PM, so you should
try to mode switch via INT 2F -pointer (initial mode switch).
Then (hopefully) you can do INT 31 calls.

> can I call the real to protected mode switch routine whilst in a
> interrupt service routine? is this at all valid?

Dunno, just try it! Usually a DPMI host maintains a couple of
interrupt stacks so a nesting level of 4 or so should be no problem.

> what about the rest of
> the int 31H functions.. are these valid to call whilst in a real mode
> interupt service routine?

Normally: no, see above!

> do i actually need to bother with the copy.. or can i simply create a
> descriptor pointing at the rest of my code whereever it happens to be in
> dos memory?

The latter should work, especially while not running under windows,OS/2
or so...
(you pointed out that the DPMI-host is loaded by the target program)

Anyway, using the initial mode switch, the memory of your program
is already allocated (hopefully :) and the DPMI-host provided the 
selectors you need (CS,DS- do you really use multiple segments within a 
TSR?).

[snipped a bit]
> so one really stupid question.. what signifies the difference between 32
> and 16 bit code? once my code calls the real to protected mode switch..
> so it is running in protected mode.. is there anything stopping me
> simply executing 32bit code straight away?
> and hence ignore all the
> allocating memory and copying parts? or do I need to create a descriptor
> that marks the memory as being 32bit code to make the 16->32bit switch?

Never merge realmode/protected mode and 16/32 bit.
Once the 286 was introduced, there was only 16 bit PM-coding!

The way the code is handled by the CPU depends on the D- bit of
the current CS- descriptor, IOW, there is no need to _copy_, but
you must allocate a selector first, set it to the base of the
CS- descriptor the DPMI host was kind enough to create for you,
set the limit to whatever, and: set the (extended) access rights (as I
recall it was CH at INT 31) with the D-bit set. Then just do a far jump
using that selector to the next instruction of your code stream
and it'll execute in 32 bit mode.
BTW: it's not a trivial job to write that kind of mixed code even
in ASM. (overlapping use16 and use32 segments and stuff)
Isn't it much easier to code the interrupt handler in 16 bit also?

[remainder snipped]

So the method I would recommend is:

Hook the interrupt you know is called by the app.
(Hint: Do you know of any app that doesn't chain the timer interrupt?
 + AFAIK it _is_ valid to do INT 2F- calls from within a timer
 interrupt handler, so just check #2F until "DPMI present " is positive)

It may be neccessary to do a "set PSP" DOS- call, check it out!
If so, some additional work has to be done :(

Switch to PM using the DPMI- realmode entry point

Hook the HW- interrupt then.
(If the handler is 16 bit- code you do not need to allocate selectors
and so on, just set the new interrupt handler with current cs-selector)

Use the raw mode switch to go back to RM.

Continue processing the interrupt handler.

This may work/may not. (No warranty :), but hope it helps....

WUSCHEL

- Raw text -


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