www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/03/15:16:50

Message-Id: <199703031950.NAA59580@audumla.students.wisc.edu>
Mime-Version: 1.0
Date: Mon, 03 Mar 1997 13:51:19 -0600
To: djgpp AT delorie DOT com
From: Scott Fleischman <safleisc AT students DOT wisc DOT edu>
Subject: __djgpp_base_address

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.)

I compiled it simply with:   gcc ?.c -o ?.exe
where ? is the filename.

By working fine I mean printing out "5Kb locked." or whatever instead of
"couldn't lock ..."

When the line is changed, it no longer works in the Win95 dos box.



---Code start----
#include <dpmi.h>
#include <sys/nearptr.h>
#include <stdio.h>

int dos_lockmem(void *addr, int size)
{
        __dpmi_meminfo info;
        info.address = (long) addr + __djgpp_base_address;
        info.size = size;
        if (__dpmi_lock_linear_region(&info))
                return __dpmi_error;
        else
                return 0;
}

int main()
{
    int i, j, checksum, end_of_memory;
    if (!__djgpp_nearptr_enable()) { printf("Damn.\n"); return 0; }

    end_of_memory = (int)sbrk(0);

    if (dos_lockmem ((void *)0, end_of_memory - 0x1000))
    {
        printf ("Couldn't lock text and data\n");
        return 0;
    }

      /* touch the entire image */
    for (j=0 ; j<4 ; j++)
    {
        for(i=0x1000 ; i<(end_of_memory - 16 * 0x1000) ; i += 4)
        {
            checksum += *(int *)i;
            checksum += *(int *)(i + 16 * 0x1000);
        }
    }
    printf("%d Kb locked.\n", (end_of_memory - 0x1000) / 0x10000);
    return 0;
}
---Code end----

- Raw text -


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