delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/15/22:08:21

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: jumping into linear memory and across programs in protected mode
Date: Fri, 15 May 1998 22:03:37 +0100
Organization: None
Message-ID: <33f6nHAp2KX1EwxV@talula.demon.co.uk>
References: <6jh9c7$2p8$1 AT news DOT LF DOT net>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 63
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Timo Bingmann writes:
>I have written two TSR programs needing to communcate with each other.

Sounds like fun :-)

>Is it possible in DPMI to call an other protected mode C function my 
>linear memory reference?

Not by linear address (unless you enable the nearptr hack, but that
would cause a lot of problems because you would end up running code from
one program while the selector for the other was loaded), and not in C,
but I'm fairly sure that this can be done with an asm call.

Using the ljmp instruction, you can make a far call to code in something
other than the current code segment. This takes a __dpmi_paddr structure
as the parameter, which contains a 48 bit seg:offset pointer. This
selector will need to be the same %cs value as used by the program you
are calling, or some other selector with the same base address (you can
use DPMI functions to create such a thing).

Once this call arrives in your other TSR, you will need to load new %ds,
%es, and %ss selectors, and a new stack pointer, before any C code can
be executed. This isn't too hard to do as long as you are very careful
what order you load things in, ie:

- push all registers onto the old stack

- load the data selector and stack pointer values for your new program
from a global variable into a spare register (because %ds is currently
pointing at the old program, this must use a %cs override).

- save the old stack selector and pointer into some other registers

- load the new selector and stack pointer into %ds, %es, %ss, and %esp

- push the old stack selector and pointer from the temp registers onto
the new stack

Now you should be able to call C functions from the new program!

To restore the previous state before returning to your first TSR, do the
same things in reverse:

- pop the old stack selector and pointer

- pop all the other registers off the restored stack

Disclaimer: I have never tried anything like this myself, but the
principles are very similar to how you set up an interrupt handler
wrapper (see the irqwrap.s file from Allegro for an example of such a
thing).

>But I don't know how to get the linear address of the program selector out
>of the DPMI server?

Use __dpmi_get_segment_base_address(). But this isn't useful for you:
the processor never works directly with linear addresses, so you must
create a selector for the memory region before you can access it.


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Miracles are nothing if you've got the wrong intentions" - Mike Keneally

- Raw text -


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