An Introduction To Intel Memory Management
An Introduction To Intel Memory Management
Management
Jeremy Pierre
[email protected]
An Introduction to Intel Memory Management 1
pointing to a Page Table which points to several individual pages. Intel compatible processor without segmentation, we cannot turn it off as
is possible with the paging mechanism. Originally, a segment was always
64k in size, and to address memory one needed to supply a two part ad-
Directory Table Linear Memory
dress composed of two words(16 bit values) separated by a colon such as
0x1000 0x1000 0xDEAD:BEEF. The first word is called the segment selector. The second
word is called the offset. So 0x0:1000 refers to the first segment in memory,
0x8000 0x2000
at an offset of 0x1000. The problem comes when you try to access memory
0x2000 0x3000 location 0x0:10000, as this is an offset bigger than 64k.
Since the 80386 processor, we have had a much more flexible imple-
mentation of segmentation. A segment can be any size needed, up to the
addressable limit of 4 gigabytes. Much like there are tables to keep track
of our linear memory pages, there are table structures to keep track of our
logical segments of memory. Two types of tables exist:
• Global Descriptor Table(GDT)
• Local Descriptor Table(LDT)
Each processor must have one and only one Global Descriptor Table(GDT)
The addresses in the table entries are the physical base addresses of each and it cannot be larger than 64k. The upside is that we can have one Local
page being pointed to, where the addresses listed in linear memory are Descriptor Table per process so that each process on our computer can
what software will see. The maximum amount of memory we can address have its very own logical memory address space, just as each process can
with a full Page Directory and full Page Tables under it totals 4 gigabytes, have its own linear address space.
assuming we are using the default page size of 4k 2 . Our GDT looks almost exactly like any LDT with one exception: the
Now for the location of Page Directories. The CR3 control register points first entry in the GDT must always be filled with zeros. This is for several
to the physical base of a Page Directory. This register is also known as the purposes such as debugging, access checks and so on. In any given LDT, the
Page Directory Base Register(PDBR). Since the CR3 register is changed entry 0 can be anything we want. The GDT and LDT’s contain segment
upon a hardware context switch 3 , we can actually create completely dif- descriptors that allow us to arbitrarily define the base address, size and
ferent linear memory maps for different programs running simultaneously. attributes of a segment for use by a process. The following figure illustrates
a few segment descriptors pointing to arbitrary linear memory locations.
Logical addressing using segmentation has been common on Intel proces-
sors almost from the beginning. To date, there is no way to operate an
2 There are extensions to the paging hardware on a number of processors since the
Pentium that allow 2 and 4 megabyte pages as well as an address space up to 64 giga-
bytes. See the bibliography for further documentation on which processors support this
as well as specifics of operation. LDT 1 2 3 4
3 A context switch, or task switch is when control of the processor changes to a
The empty boxes of linear memory represent arbitrarily sized segments. For an example, let us consider a segment with a base address of 0x0
The LDT boxes are individual segment descriptors. The numbers inside and a limit of 1 megabyte, or 0x100000. The following figure illustrates
the segment descriptors are called segment selectors. Specifying a logical the translation from logical to linear to physical address assuming we are
address is the same as it was 20 years ago, except the offset could be just looking for address 0x0004:1000. Note that our segment selector has bit 2
about anything. For example, if segment 1 had a size(or ”limit”) of 2 set with an index value of 0. This indicates that we are looking for the first
megabytes, the logical address 0x0001:00040558 is perfectly legitimate. segment in a Local Descriptor Table.
Our previous example is just fine, except that the supplied segment se-
lectors are completely incorrect. Segment selectors are still 16 bits long LDT Directory Table Linear Physical
just as they were 20 years ago. The difference is that now we use the first
0x0000 Paging 0x0000 0x200000 Page 1
three bits of a selector for some extra information like priviledge levels and
0x504000 0x301000 Page 2
indicating which table to use. Priviledge levels are beyond the scope of this
text, but the table inicator bit is important. The following figure illustrates
0x301000
two segment selectors at the binary level.
15 2 1 0
LDT
Index
Our LDT descriptor 0x0000 points to a base address of 0x0. The paging
mechanism translates this and passes us along to the Page Directory. Since
15 2 1 0 we are operating within the first 4 megabytes of address space it forwards
GDT 0 us to the first page table. The offset we supplied is the first byte in the
Index
second page, so the translation passes us along the chain through linear
process can use exactly the same logical address space for every operation,
but maintain separate linear memory regions to avoid tampering.
References
[1] Intel Architecture Software Developer’s Manual, Intel Corporation
[2] Hans-Peter Messmer: The Indispensable PC Hardware Book,
Addison-Wesley, 2002