Mail Archives: djgpp/1997/08/19/13:11:48

From: Wojciech Galazka <wgalazka AT chem DOT uw DOT edu DOT pl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: how to convert real mode pointer into protected mode ?
Date: Tue, 19 Aug 1997 12:55:23 +0200
Organization: University of Warsaw
Lines: 91
Message-ID: <>
References: <33F82B88 DOT 642 AT chem DOT uw DOT edu DOT pl> <5tasf6$cvc AT dfw-ixnews12 DOT ix DOT netcom DOT com>
Mime-Version: 1.0
CC: wgalazka AT delorie DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

firewind wrote:
> I know very little about DOS stuff, having started with DJGPP. But, I do
> know some. :)  Are you sure the _far* functions aren't what you want? For
> example, here is the code to read the DOS InDOS flag:

Well, as I said <sys/farptr.h> probably cannot help. And why?
Here's the problem description.

Upon return from a real mode ISR I get a pointer in ES:DI
pointing to a structure in memory under 640 kB.
The size of the structure is not known in advance so I
cannot just call dosmemget to copy the struct into
my own  one.
The definition of the structure is something like

struct foo {
   short size
   struct { 
     short min
     short max
   } * minmax;	//holds a 'size' number of minmax structures

In real mode DOS program I'd simply write

struct foo * s;

void give struct(struct foo * p)
   p =MK_FP(ES,DI);

int main()
  give struct(s);
  for (i=0;i< s->size;i++)
  printf("min: %d, max: %d\n",s->min, s->max);
  return 0;

That is I don't have to allocate my own struct foo variable,
just point my pointer to the structure (lying somewhere
under 640 kB) to get its values.

This is not available under protected mode program.
I can obtain the ES:DI pair with a real mode address. 
But what I cannot know how to do is how to convert
a real mode address to protected mode one or having
protected mode selector and offset (= ES<<4 +DI) grab
the values (not copy) of the structure.

The API I'm trying to implement does not allow me
to require the user to allocate the space for a structure,
but jforces for ust to pass a pointer.

I'm not sure but maybe the solution might be as
1 So I got ES:DI, then
2 using farpoke read the value of s->size. then
3 use __dpmi_map_physical_memory (I can do this as I have both the size
and offset required by this call)
4 But can I use __dpmi_map_physical_memory to map
  memory below 1MB? I don't think so.
BTW AFAIK cwsdpmi.exe does support DPMI 1.0 functions, right? 

Another big problem is with the following case

struct foo2 {
  short size;
  struct {
    char *name;
    short value;
  } *s;        //  size number of structures

The problem is with char *name. as it points somewhere into dos memory.
As before I cannot just copy the whole structure but instead provide
a pointer to it.

Any ideas are highly appreciated. The required stuff is necessary to
write a DJGPP version of a packet driver sender/receiver.

Wojciech Galazka
Computer Security Advisor

- Raw text -

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