Mail Archives: djgpp/1997/12/02/04:01:06
This is a multi-part message in MIME format.
--------------2E8774073ACA
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Rikard Bj=F6rklind wrote:
> =
> Hi! I am new to DJGPP.. I have programmed some pascal,
> but I want to use C instead... Now there is one problem..
> In real mode programs I know how to access memory.. like
> 0a000h:0abcdh .. but in pmode it is different, right? Now how do I do
> to adress mem in djgpp? in TMT-pascal, a pmode compiler, you
> add a variable called _zero to the offset. is it something similar
> in DJGPP?? Well, bye!
You don't need to do anything special at all to access protected mode
memory under DJGPP (or any DPMI program, for that matter). All
available physical and virtual memory on your computer is mapped into a
single linear virtual address space with a maximum size of 4 GB (4 x
1024 x 1024 x 1024 bytes). Practically, the maximum size of your
address space is limited by the memory provided by the DPMI host in
question (Win95 provides up to 64 MB, cwsdpmi provides up to 256 MB,
etc.).
How much does all of this matter to you? Not one bit. Go ahead and
malloc() as much memory as you want. Feel free to create 10 MB global
arrays. The DPMI interface handles all of the internal stuff completely
transparently. I'm attaching a fun little program you might want to try
that demonstrates this.
The _only_ case where you actually need to worry about the mechanics of
the DPMI interface is when you try to access memory-mapped devices in
conventional (real-mode) memory. This includes the VGA or text video
memory, interrupt tables, hardware ports, and other similar things. A
complete discussion of how to do this sort of work in protected mode
would be far too lengthy for an email message, but the DJGPP Frequently
Asked Questions list (v2/faq210b.zip from SimTel or online at
http://www.delorie.com/djgpp/v2faq/) discusses it in detail in chapters
10, 17, and 18, and gives additional pointers to more information. It's
a tremendously interesting bit of reading; I recommend you give it a
try.
Good luck!
-- =
John M. Aldrich <fighteer AT cs DOT com> =
* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
again.
* It doesn't necessarily do it in chronological order, though.
=
--- Douglas Adams
--------------2E8774073ACA
Content-Type: text/plain; charset=us-ascii; name="Lotsamem.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Lotsamem.c"
/* lotsamem.c */
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
char *p;
int megs, init;
printf( "How many megabytes would you like to allocate (1-256)? " );
if ( scanf( "%d", &megs ) < 1 || megs < 1 || megs > 256 )
printf( "That's not what I asked for, dufus.\n" );
else
{
printf( "Initialize the memory (1 = yes, 0 = no)? " );
scanf( "%d", &init );
if ( init )
p = calloc( 1, megs * 1048576 );
else
p = malloc( megs * 1048576 );
if ( p != NULL )
{
printf( "Wow! You just allocated %d megabytes!\n", megs );
free( p );
}
else
printf( "Whoops! You don't have enough memory available. Sorry.\n" );
}
return 0;
}
--------------2E8774073ACA--
- Raw text -