test: ki386.h File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# ki386.h File Reference

Go to the source code of this file.

## Classes

struct | _IDENTITY_MAP

## Defines

#define | MAX_IDENTITYMAP_ALLOCATIONS 30
#define | PPI_BITS 0
#define | PDI_BITS 10
#define | PTI_BITS 10
#define | PPI_MASK ((1 << PPI_BITS) - 1)
#define | PDI_MASK ((1 << PDI_BITS) - 1)
#define | PTI_MASK ((1 << PTI_BITS) - 1)
#define | KiGetPpeIndex(va) ((((ULONG)(va)) >> PPI_SHIFT) & PPI_MASK)
#define | KiGetPdeIndex(va) ((((ULONG)(va)) >> PDI_SHIFT) & PDI_MASK)
#define | KiGetPteIndex(va) ((((ULONG)(va)) >> PTI_SHIFT) & PTI_MASK)

## Typedefs

typedef _IDENTITY_MAP | IDENTITY_MAP
typedef _IDENTITY_MAP * | PIDENTITY_MAP

## Functions

VOID | Ki386ClearIdentityMap (PIDENTITY_MAP IdentityMap)
VOID | Ki386EnableTargetLargePage (PIDENTITY_MAP IdentityMap)
BOOLEAN | Ki386CreateIdentityMap (IN OUT PIDENTITY_MAP IdentityMap, IN PVOID StartVa, IN PVOID EndVa)
BOOLEAN | Ki386EnableCurrentLargePage (IN ULONG IdentityAddr, IN ULONG IdentityCr3)

## Variables

PVOID | Ki386EnableCurrentLargePageEnd

## Define Documentation

#define KiGetPdeIndex | ( | va |  | ) | ((((ULONG)(va)) >> PDI_SHIFT) & PDI_MASK)

| Definition at line 53 of file ki386.h. Referenced by Ki386MapAddress().

#define KiGetPpeIndex | ( | va |  | ) | ((((ULONG)(va)) >> PPI_SHIFT) & PPI_MASK)

| Definition at line 52 of file ki386.h. Referenced by Ki386MapAddress().

#define KiGetPteIndex | ( | va |  | ) | ((((ULONG)(va)) >> PTI_SHIFT) & PTI_MASK)

| Definition at line 54 of file ki386.h. Referenced by Ki386MapAddress().

#define MAX_IDENTITYMAP_ALLOCATIONS 30

| Definition at line 2 of file ki386.h.

#define PDI_BITS 10

| Definition at line 44 of file ki386.h.

#define PDI_MASK ((1 << PDI_BITS) - 1)

| Definition at line 49 of file ki386.h. Referenced by MiCheckAddress().

#define PPI_BITS 0

| Definition at line 43 of file ki386.h. Referenced by Ki386CreateIdentityMap().

#define PPI_MASK ((1 << PPI_BITS) - 1)

| Definition at line 48 of file ki386.h.

#define PTI_BITS 10

| Definition at line 45 of file ki386.h.

#define PTI_MASK ((1 << PTI_BITS) - 1)

| Definition at line 50 of file ki386.h.

## Typedef Documentation

typedef struct _IDENTITY_MAP IDENTITY_MAP

| Referenced by KiInitMachineDependent().

typedef struct _IDENTITY_MAP * PIDENTITY_MAP

## Function Documentation

VOID Ki386ClearIdentityMap | ( | PIDENTITY_MAP | IdentityMap | ) |

BOOLEAN Ki386CreateIdentityMap | ( | IN OUT PIDENTITY_MAP | IdentityMap,
|  | IN PVOID | StartVa,
|  | IN PVOID | EndVa
| ) |

Definition at line 54 of file largepag.c.

References FALSE, Ki386BuildIdentityBuffer(), Ki386ConvertPte(), Ki386MapAddress(), MmGetPhysicalAddress(), PAGE_SIZE, PPI_BITS, PTES_PER_PAGE, and TRUE.

Referenced by KiInitMachineDependent().

    00059 {
    00060 /*++
    00061
    00062     This function creates an identity mapping for a region of memory.
    00063
    00064     If the region of memory passed in includes memory that lies above
    00065     4G, then a new buffer is allocated below 4G.
    00066
    00067 Arguments:
    00068
    00069     IdentityMap - Pointer to the structure which will be filled with the newly
    00070                   created top-level directory address.  It also provides
    00071                   storage for the pointers used in alloating and freeing the
    00072                   memory.
    00073
    00074     StartVa - Pointer to the first byte of the region of memory that is to be
    00075               memory mapped.
    00076
    00077     EndVa - Pointer to the byte immediately after the last byte of the region
    00078             that is to be memory mapped.
    00079
    00080 Return Value:
    00081
    00082     TRUE if the function succeeds, FALSE otherwise.
    00083
    00084     Note - Ki386ClearIdentityMap() should be called even on FALSE return to
    00085     free any memory allocated.
    00086
    00087 --*/
    00088
    00089     ULONG pageDirectoryIndex;
    00090     ULONG pagesToMap;
    00091     PCHAR currentVa;
    00092     ULONG length;
    00093     BOOLEAN result;
    00094     PHARDWARE_PTE pageDirectory;
    00095     PHARDWARE_PTE pageDirectoryEntry;
    00096     PHYSICAL_ADDRESS identityAddress;
    00097
    00098 #if defined(_X86PAE_)
    00099
    00100     ULONG pageDirectoryPointerTableIndex;
    00101     PHARDWARE_PTE pageDirectoryPointerTable;
    00102     PHARDWARE_PTE pageDirectoryPointerTableEntry;
    00103
    00104 #endif
    00105
    00106     //
    00107     // Initialize the IdentityMap structure to a known state.
    00108     //
    00109
    00110     RtlZeroMemory( IdentityMap, sizeof(IDENTITY_MAP) );
    00111     length = (PCHAR)EndVa - (PCHAR)StartVa;
    00112
    00113     //
    00114     // Get the physical address of the input buffer (or suitable copy).
    00115     //
    00116
    00117     identityAddress = Ki386BuildIdentityBuffer( IdentityMap,
    00118                                                 StartVa,
    00119                                                 length,
    00120                                                 &pagesToMap );
    00121     if( identityAddress.QuadPart == 0) {
    00122
    00123         //
    00124         // The input buffer was not contiguous or not below 4G, and a
    00125         // suitable buffer could not be allocated.
    00126         //
    00127
    00128         return FALSE;
    00129     }
    00130
    00131     IdentityMap->IdentityAddr = identityAddress.LowPart;
    00132
    00133     //
    00134     // Set up the mappings.
    00135     //
    00136
    00137     currentVa = StartVa;
    00138     do {
    00139
    00140         //
    00141         // Map in the virtual address
    00142         //
    00143
    00144         result = Ki386MapAddress( IdentityMap,
    00145                                   (ULONG)currentVa,
    00146                                   identityAddress );
    00147         if (result == FALSE) {
    00148             return FALSE;
    00149         }
    00150
    00151         //
    00152         // Map in the identity (physical) address
    00153         //
    00154
    00155         result = Ki386MapAddress( IdentityMap,
    00156                                   identityAddress.LowPart,
    00157                                   identityAddress );
    00158         if (result == FALSE) {
    00159             return FALSE;
    00160         }
    00161
    00162         //
    00163         // Advance both the Va and identityAddress pointers in anticipation
    00164         // of mapping in another page.
    00165         //
    00166
    00167         currentVa += PAGE_SIZE;
    00168         identityAddress.QuadPart += PAGE_SIZE;
    00169         pagesToMap -= 1;
    00170
    00171     } while (pagesToMap > 0);
    00172
    00173     //
    00174     // Now go through the page directory pointer table and page directories,
    00175     // converting virtual page frames to physical ones.
    00176     //
    00177
    00178 #if defined(_X86PAE_)
    00179
    00180     //
    00181     // This PAE-only outer loop walks the page directory pointer table entries
    00182     // and processes each valid page directory referenced.
    00183     //
    00184
    00185     pageDirectoryPointerTable = IdentityMap->TopLevelDirectory;
    00186     for (pageDirectoryPointerTableIndex = 0;
    00187          pageDirectoryPointerTableIndex < (1 << PPI_BITS);
    00188          pageDirectoryPointerTableIndex++) {
    00189
    00190         pageDirectoryPointerTableEntry =
    00191             &pageDirectoryPointerTable[ pageDirectoryPointerTableIndex ];
    00192
    00193         if (pageDirectoryPointerTableEntry->Valid == 0) {
    00194             continue;
    00195         }
    00196
    00197         pageDirectory =
    00198             (PHARDWARE_PTE)Ki386ConvertPte( pageDirectoryPointerTableEntry );
    00199
    00200 #else
    00201         pageDirectory = IdentityMap->TopLevelDirectory;
    00202 #endif
    00203
    00204         for (pageDirectoryIndex = 0;
    00205              pageDirectoryIndex < PTES_PER_PAGE;
    00206              pageDirectoryIndex++) {
    00207
    00208             pageDirectoryEntry = &pageDirectory[ pageDirectoryIndex ];
    00209             if (pageDirectoryEntry->Valid == 0) {
    00210                 continue;
    00211             }
    00212
    00213             Ki386ConvertPte( pageDirectoryEntry );
    00214         }
    00215
    00216 #if defined(_X86PAE_)
    00217     }
    00218 #endif
    00219
    00220     identityAddress = MmGetPhysicalAddress( IdentityMap->TopLevelDirectory );
    00221     IdentityMap->IdentityCR3 = identityAddress.LowPart;
    00222
    00223     return TRUE;
    00224 }

BOOLEAN Ki386EnableCurrentLargePage | ( | IN ULONG | IdentityAddr,
|  | IN ULONG | IdentityCr3
| ) |

| Referenced by Ki386EnableTargetLargePage(), and KiInitMachineDependent().

VOID Ki386EnableTargetLargePage | ( | PIDENTITY_MAP | IdentityMap | ) |

| Referenced by KiInitMachineDependent().

## Variable Documentation

PVOID Ki386EnableCurrentLargePageEnd

| Definition at line 36 of file ki386.h. Referenced by KiInitMachineDependent().