Mail Archives: djgpp/1997/03/04/15:12:12
>
>On Mon, 3 Mar 1997, Scott Fleischman wrote:
>
>> I am wondering why this code works fine in the Win95 Dos box, yet doesn't
>> work under Win95 msdos mode w/ cwsdpmi or in dos 6.22 w/ qemm unless I
>> change the line:
>> info.address = (long) addr + __djgpp_base_address;
>> to
>> info.address = (long) addr - __djgpp_base_address;
>> (or "... + __djgpp_conventional_base" since they are equivalent.)
>
>Why, because that's how you should use nearptrs! The correct way is
>to add the `__djgpp_conventional_base', NOT `__djgpp_base_address' (it
>is documented that way in the libc reference). You should never mess
>with `__djgpp_base_address' anyway.
>
>And btw, you should take the value of `__djgpp_conventional_base'
>immediately after a call to `__djgpp_nearptr_enable'. Your code calls
>`sbrk' between these two, which is unsafe (`sbrk' will sometimes move
>the base address).
>
Thank you for your reply but I diagree with never using __djgpp_base_address,
and in this case it is the right thing to use. If I use
__djgpp_conventional_base it doesn't work. But if instead I wanted
something like the address for 0xa0000 I would add __djgpp_conventional_base
to it.
Anyway, I got it to work right and here is the code (just in case you wish
to see it).
#include <dpmi.h>
#include <sys/nearptr.h>
#include <stdio.h>
int main()
{
int i, j, checksum;
__dpmi_meminfo info;
info.size = (__djgpp_selector_limit + 1) - 4096;
info.address = __djgpp_base_address + 4096;
if (__dpmi_lock_linear_region(&info))
{
printf ("Couldn't lock text and data\n");
return 0;
}
/* touch the entire image */
for (j=0 ; j<4 ; j++)
{
for(i=0x1000 ; i<(info.size - 16 * 0x1000) ; i += 4)
{
checksum += *(int *)i;
checksum += *(int *)(i + 16 * 0x1000);
}
}
printf("%d Kb locked.\n", info.size / 1024);
return 0;
}
- Raw text -