Intel 64 and IA-32 Architectures Software Developers Manual Volume 3A, System Programming Guide, Part 1
10-40 Vol. 3A
MEMORY CACHE CONTROL
FI;
ROF;
return FirstType;
ELSE return UNSUPPORTED;
FI;
If the processor does not support MTRRs, the function returns UNSUPPORTED. If the
MTRRs are not enabled, then the UC memory type is returned. If more than one
memory type corresponds to the specified range, a status of MIXED_TYPES is
returned. Otherwise, the memory type defined for the range (UC, WC, WT, WB, or
WP) is returned.
The pseudocode for the Get4KMemType() function in Example 10-5 obtains the
memory type for a single 4-KByte range at a given physical address. The sample
code determines whether an PHY_ADDRESS falls within a fixed range by comparing
the address with the known fixed ranges: 0 to 7FFFFH (64-KByte regions), 80000H to
BFFFFH (16-KByte regions), and C0000H to FFFFFH (4-KByte regions). If an address
falls within one of these ranges, the appropriate bits within one of its MTRRs deter-
mine the memory type.
Example 10-5. Get4KMemType() Pseudocode
IF IA32_MTRRCAP.FIX AND MTRRdefType.FE /* fixed registers enabled */
THEN IF PHY_ADDRESS is within a fixed range
return IA32_MTRR_FIX.Type;
FI;
FOR each variable-range MTRR in IA32_MTRRCAP.VCNT
IF IA32_MTRR_PHYSMASK.V = 0
THEN continue;
FI;
IF (PHY_ADDRESS AND IA32_MTRR_PHYSMASK.Mask) =
(IA32_MTRR_PHYSBASE.Base
AND IA32_MTRR_PHYSMASK.Mask)
THEN
return IA32_MTRR_PHYSBASE.Type;
FI;
ROF;
return MTRRdefType.Type;
10.11.7.2 MemTypeSet() Function
The MemTypeSet() function in Example 10-6 sets a MTRR for the physical memory
range specified by the parameters base and size to the type specified by type. The
base address and size are multiples of 4 KBytes and the size is not 0.