Mail Archives: djgpp/1998/04/03/11:16:06
MNR. LE SMITH writes:
> could someone please (briefly) explain to me what the difference is
> between linear and physical memory addresses.
There are two levels of memory virtualisation in the 386 protected
mode architecture.
In hardware terms you have physical memory: this refers directly to
specific locations in your ram chips, and counts upwards from zero.
Some special physical memory locations may be used to access other
devices, for example 0xA0000-0xB0000 refers to the VGA framebuffer
memory, and there may be an SVGA linear framebuffer or memory mapped
I/O registers at some higher addresses.
On top of this physical memory, the paging tables are used to
rearrange it into what is called logical memory. Logical memory also
starts from zero and counts up from there, but each 4k logical page
can be mapped onto any part of the physical memory, or marked to
indicate that it doesn't actually exist at all. This is how it is
possible to use disk space to emulate real memory: certain pages of
the linear address space can be marked as invalid, and then when the
program tries to access them an exception will be generated, at which
point the DPMI server can swap some physical memory out to disk, read
other data in to the space it just freed up, and then rearrange the
linear <-> physical mapping tables to reflect this change.
At the highest level, the segmentation system is used to translate
a linear address into the kind of virtual memory address used by a
djgpp program. A selector is created to access a particular part
of the linear memory, given a base address and size, and loaded into
the segment registers, after which all the pointers used by your
program will be offset by the base of this selector. This allows
a program to be loaded into any part of the linear memory, or even
moved around while it is running, without any of its internal
addresses being changed, and also prevents you from accessing illegal
memory because you can't easily write outside the limits set by this
selector.
Shawn Hargreaves.
- Raw text -