delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/17/03:23:31

Date: Thu, 17 Jun 1999 10:20:54 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Michael Stewart <mike AT reggin DOT freeserve DOT co DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: Selector code
In-Reply-To: <7k7qc5$pc2$1@taliesin.netcom.net.uk>
Message-ID: <Pine.SUN.3.91.990617102006.22717G-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Wed, 16 Jun 1999, Michael Stewart wrote:

> It creates a selector, given the location and size. So if you wanted a
> descriptor which spanned the VGA memory (0xa0000, 64000 bytes) you would
> call it like so.
> 
> if (make_ds (video_ds, 0xa0000, 64000))
>    return -1; /* Error making descriptor */

I think it might be useful.

> int make_ds (int &ds, int base, int limit) {
>    static char ds_data[8];

Why did you make the ds_data[] array static?

Also, I think it's better to declare it "unsigned char".

>    limit--;
>    ds_data[0] = limit & 0xff;
>    ds_data[1] = limit >> 8 & 0xff;

It might be better to make sure that if the size of the segment is
more than 1MB, the lower 12 bits in the limit you pass to
__dpmi_set_descriptor are set.  This is because the DPMI spec requires
such large segments to be page-aligned, and some servers will fail the
call otherwise.  Too many people posted here code that didn't work
because they failed to comply to that requirement, and it would be a
good idea to make this function take care of that for the user.

>    ds_data[6] = limit >> 16 & 0x0f + 0x40;

The 0x40 part is only correct for limits less than 64KB (and even then
I think it needs to be 0x41).  For larger segments, you need to make
it page-granular, so 0xc1 is the value in those cases.

>    ds_data[7] = 0x00;

This is only right for addresses in the first 16MB range.  Why the
limitation?

- Raw text -


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