test: axp64/debugsup.c File Reference

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

# debugsup.c File Reference

`#include "mi.h"`

Go to the source code of this file.

## Functions

PHARDWARE_PTE | MiCheckAddress (IN PVOID VirtualAddress, OUT PVOID *AccessAddress)
PVOID | MmDbgReadCheck (IN PVOID VirtualAddress)
PVOID | MmDbgWriteCheck (IN PVOID VirtualAddress, IN PHARDWARE_PTE Opaque)
VOID | MmDbgReleaseAddress (IN PVOID VirtualAddress, IN PHARDWARE_PTE Opaque)
PVOID64 | MmDbgReadCheck64 (IN PVOID64 VirtualAddress)
PVOID64 | MmDbgWriteCheck64 (IN PVOID64 VirtualAddress)
PVOID64 | MmDbgTranslatePhysicalAddress64 (IN PHYSICAL_ADDRESS PhysicalAddress)

## Function Documentation

PHARDWARE_PTE MiCheckAddress | ( | IN PVOID | VirtualAddress,
|  | OUT PVOID * | AccessAddress
| ) |

Definition at line 25 of file axp64/debugsup.c.

References Index, NULL, PAGE_SHIFT, PAGE_SIZE, PDI_MASK, and PTI_SHIFT.

Referenced by MmDbgReadCheck(), and MmDbgWriteCheck().

    00032                    :
    00033
    00034
    00035     This function checks the specified virtual address for accessibility
    00036     and returns a pointer to the hardware PTE that maps the virtual address
    00037     and a 43-bit superpage address at which the address can be accessed.
    00038
    00039 Arguments:
    00040
    00041     VirtualAddress - Supplies the virtual address to check.
    00042
    00043     AccessAddress - Supplies a pointer to a variable that receives the
    00044          43-bit superpage address at which the address can be accessed.
    00045
    00046 Return Value:
    00047
    00048     A value of NULL is returned if the address is invalid or not accessible.
    00049     Otherwise, a pointer to the PTE that maps the specified virtual address
    00050     is returned as the function value.
    00051
    00052 --*/
    00053
    00054 {
    00055
    00056     ULONG Index;
    00057     PHARDWARE_PTE Pdr1;
    00058     PHARDWARE_PTE Pdr2;
    00059     PHARDWARE_PTE Ptp;
    00060
    00061     //
    00062     // If the high order 21 bits of the virtual address are not all 1's or
    00063     // 0's, then the address is invalid. Otherwise, attempt to tranverse
    00064     // the page directory hierarchy.
    00065     //
    00066
    00067     if ((ULONG_PTR)(((LONG_PTR)VirtualAddress >> 43) + 1) > 1) {
    00068         return NULL;
    00069     }
    00070
    00071     //
    00072     // Compute the 43-bit superpage address of the level one page
    00073     // directory page and check to see if the level two page directory
    00074     // page is valid.
    00075     //
    00076
    00077     Pdr1 = (PHARDWARE_PTE)(KSEG43_BASE | (((PHARDWARE_PTE)PDE_SELFMAP)->PageFrameNumber << PAGE_SHIFT));
    00078     Index = (ULONG)(((ULONG_PTR)VirtualAddress >> PDI1_SHIFT) & PDI_MASK);
    00079     if (Pdr1[Index].Valid == 0) {
    00080         return NULL;
    00081     }
    00082
    00083     //
    00084     // Compute the 43-bit superpage address of the level two page
    00085     // directory page and check to see if the page table page is
    00086     // valid.
    00087     //
    00088
    00089     Pdr2 = (PHARDWARE_PTE)(KSEG43_BASE | (Pdr1[Index].PageFrameNumber << PAGE_SHIFT));
    00090     Index = (ULONG)(((ULONG_PTR)VirtualAddress >> PDI2_SHIFT) & PDI_MASK);
    00091     if (Pdr2[Index].Valid == 0) {
    00092         return NULL;
    00093     }
    00094
    00095     //
    00096     // Compute the 43-bit superpage address of the page table page and
    00097     // check to see if the data page is valid.
    00098
    00099     Ptp = (PHARDWARE_PTE)(KSEG43_BASE | (Pdr2[Index].PageFrameNumber << PAGE_SHIFT));
    00100     Index = (ULONG)(((ULONG_PTR)VirtualAddress >> PTI_SHIFT) & PDI_MASK);
    00101     if (Ptp[Index].Valid == 0) {
    00102         return NULL;
    00103     }
    00104
    00105     //
    00106     // Compute the 43-bit superpage address of the data page and return the
    00107     // address of the PTE that maps the data page as the function value.
    00108     //
    00109
    00110     *AccessAddress = (PVOID)(KSEG43_BASE |
    00111                                 (Ptp[Index].PageFrameNumber << PAGE_SHIFT) |
    00112                                 (ULONG_PTR)VirtualAddress & (PAGE_SIZE - 1));
    00113
    00114     return &Ptp[Index];
    00115 }

PVOID MmDbgReadCheck | ( | IN PVOID | VirtualAddress | ) |

Definition at line 118 of file axp64/debugsup.c.

References MI_IS_PHYSICAL_ADDRESS, MiCheckAddress(), and NULL.

    00124                    :
    00125
    00126     This routine returns the 43-bit superpage address which corresponds
    00127     to the specified virtual address if the specified virtual address
    00128     is readable.
    00129
    00130     N.B. This function should only be called at IRQL DISPATCH_LEVEL or
    00131          above.
    00132
    00133 Arguments:
    00134
    00135     VirtualAddress - Supplies the virtual address to check.
    00136
    00137 Return Value:
    00138
    00139     If the specified virtual address is invalid or not readable, then a
    00140     value of NULL is returned. Otherwise, the 43-bit superpage address
    00141     which corresponds to the specified virtual address is returned.
    00142
    00143 --*/
    00144
    00145 {
    00146
    00147     PVOID AccessAddress;
    00148
    00149     //
    00150     // If the address is within the 32- or 43-bit superpage regions, then
    00151     // the address is returned as the function value.
    00152     //
    00153
    00154     if (MI_IS_PHYSICAL_ADDRESS(VirtualAddress)) {
    00155         return VirtualAddress;
    00156     }
    00157
    00158     //
    00159     // Check if the specified virtual address if accessible. If the virtual
    00160     // address is accessible, then return the 43-bit superpage address which
    00161     // corresponds to the virtual address. Otherwise, return NULL.
    00162     //
    00163
    00164     if (MiCheckAddress(VirtualAddress, &AccessAddress) == NULL) {
    00165         return NULL;
    00166
    00167     } else {
    00168         return AccessAddress;
    00169     }
    00170 }

PVOID64 MmDbgReadCheck64 | ( | IN PVOID64 | VirtualAddress | ) |

Definition at line 335 of file axp64/debugsup.c.

References MmDbgReadCheck().

    00341                    :
    00342
    00343     This routine returns the 43-bit superpage address which corresponds
    00344     to the specified virtual address if the specified virtual address
    00345     is readable.
    00346
    00347     N.B. This function should only be called at IRQL DISPATCH_LEVEL or
    00348          above.
    00349
    00350 Arguments:
    00351
    00352     VirtualAddress - Supplies the virtual address to check.
    00353
    00354 Return Value:
    00355
    00356     If the specified virtual address is invalid or not readable, then a
    00357     value of NULL is returned. Otherwise, the 43-bit superpage address
    00358     which corresponds to the specified virtual address is returned.
    00359
    00360 --*/
    00361
    00362 {
    00363
    00364     return MmDbgReadCheck(VirtualAddress);
    00365 }

VOID MmDbgReleaseAddress | ( | IN PVOID | VirtualAddress,
|  | IN PHARDWARE_PTE | Opaque
| ) |

Definition at line 271 of file axp64/debugsup.c.

References ASSERT, KiFlushSingleTb(), MiGetPteAddress, MmIsAddressValid(), TRUE, and _MMPTE::u.

    00278                    :
    00279
    00280     i386/486 implementation specific:
    00281
    00282     This routine resets the specified virtual address access permissions
    00283     to its original state.
    00284
    00285 Arguments:
    00286
    00287     VirtualAddress - Supplies the virtual address to check.
    00288
    00289     Opaque - Supplies an opaque pointer.
    00290
    00291 Return Value:
    00292
    00293     None.
    00294
    00295 Environment:
    00296
    00297     Kernel mode IRQL at DISPATCH_LEVEL or greater.
    00298
    00299 --*/
    00300
    00301 {
    00302     MMPTE TempPte;
    00303     PMMPTE PointerPte;
    00304     PMMPTE InputPte;
    00305
    00306     InputPte = (PMMPTE)Opaque;
    00307
    00308     ASSERT (MmIsAddressValid (VirtualAddress));
    00309
    00310     if (InputPte->u.Long != 0) {
    00311
    00312         PointerPte = MiGetPteAddress (VirtualAddress);
    00313
    00314         TempPte = *InputPte;
    00315
    00316         // LWFIX: Need to make the write go to disk on trim but can't
    00317         // make it dirty here ! TempPte.u.Hard.Dirty = MM_PTE_DIRTY;
    00318
    00319         *PointerPte = TempPte;
    00320
    00321         //
    00322         // BUGBUG John Vert (jvert) 3/4/1999
    00323         //   KeFillEntryTb is liable to IPI the other processors. This is
    00324         //   definitely NOT what we want as the other processors are frozen
    00325         //   in the debugger and we will deadlock if we try and IPI them.
    00326         //   Just flush the the current processor instead.
    00327         //KeFillEntryTb ((PHARDWARE_PTE)PointerPte, VirtualAddress, TRUE);
    00328         KiFlushSingleTb(TRUE, VirtualAddress);
    00329     }
    00330
    00331     return;
    00332 }

PVOID64 MmDbgTranslatePhysicalAddress64 | ( | IN PHYSICAL_ADDRESS | PhysicalAddress | ) |

Definition at line 402 of file axp64/debugsup.c.

References KeProcessorLevel.

    00408                    :
    00409
    00410     ALPHA implementation specific:
    00411
    00412     The Alpha processor provides a direct-mapped address space called
    00413     the superpage.  The entire physical address space can be
    00414     addressed via the superpage.  This routine translates a physical
    00415     address to its corresponding superpage address.  Unfortunately,
    00416     the base superpage address is processor-dependent.  Therefore, we
    00417     have to compute it based on the processor level.  As new processors are
    00418     released, this routine will need to be updated.
    00419
    00420     This routine does not use PTEs.
    00421
    00422 Arguments:
    00423
    00424     PhysicalAddress - Supplies the physical address to translate.
    00425
    00426 Return Value:
    00427
    00428     The virtual (superpage) address which corresponds to the physical address.
    00429
    00430 Environment:
    00431
    00432     Kernel mode IRQL at DISPATCH_LEVEL or greater.
    00433
    00434 --*/
    00435
    00436 {
    00437     switch (KeProcessorLevel) {
    00438
    00439     case PROCESSOR_ALPHA_21064:
    00440     case PROCESSOR_ALPHA_21066:
    00441     case PROCESSOR_ALPHA_21068:
    00442         PhysicalAddress.QuadPart &= 0x00000003ffffffff;
    00443         PhysicalAddress.QuadPart |= 0xfffffc0000000000;
    00444         break;
    00445
    00446     case PROCESSOR_ALPHA_21164:
    00447     case PROCESSOR_ALPHA_21164PC:
    00448         PhysicalAddress.QuadPart &= 0x000000ffffffffff;
    00449         PhysicalAddress.QuadPart |= 0xfffffc0000000000;
    00450         break;
    00451
    00452     case PROCESSOR_ALPHA_21264:
    00453         PhysicalAddress.QuadPart &= 0x00000fffffffffff;
    00454         PhysicalAddress.QuadPart |= 0xffff800000000000;
    00455         break;
    00456
    00457     default:
    00458         return NULL64;
    00459
    00460     }
    00461
    00462     return (PVOID64)PhysicalAddress.QuadPart;
    00463 }
    }

PVOID MmDbgWriteCheck | ( | IN PVOID | VirtualAddress,
|  | IN PHARDWARE_PTE | Opaque
| ) |

Definition at line 173 of file axp64/debugsup.c.

References KiFlushSingleTb(), MI_IS_PHYSICAL_ADDRESS, MiCheckAddress(), NULL, TRUE, and _MMPTE::u.

    00180                    :
    00181
    00182     This routine returns the 43-bit superpage address which corresponds
    00183     to the specified virtual address if the specified virtual address is
    00184     writable.
    00185
    00186     N.B. This function should only be called at IRQL DISPATCH_LEVEL or
    00187          above.
    00188
    00189 Arguments:
    00190
    00191     VirtualAddress - Supplies the virtual address to check.
    00192
    00193     Opaque - Supplies a pointer to fill with an opaque value.
    00194
    00195 Return Value:
    00196
    00197     If the specified virtual address is invalid or not writable, then a
    00198     value of NULL is returned. Otherwise, the 43-bit superpage address
    00199     which corresponds to the specified virtual address is returned.
    00200
    00201 --*/
    00202
    00203 {
    00204     MMPTE PteContents;
    00205     PVOID AccessAddress;
    00206     PHARDWARE_PTE Pte;
    00207     PMMPTE InputPte;
    00208
    00209     InputPte = (PMMPTE)Opaque;
    00210
    00211     InputPte->u.Long = 0;
    00212
    00213     //
    00214     // If the address is within the 32- or 43-bit superpage regions, then
    00215     // the address is returned as the function value.
    00216     //
    00217
    00218     if (MI_IS_PHYSICAL_ADDRESS(VirtualAddress)) {
    00219         return VirtualAddress;
    00220     }
    00221
    00222     //
    00223     // Check if the specified virtual address if accessible. If the virtual
    00224     // address is accessible, then return the 43-bit superpage address which
    00225     // corresponds to the virtual address. Otherwise, return NULL.
    00226     //
    00227     //
    00228
    00229     Pte = MiCheckAddress(VirtualAddress, &AccessAddress);
    00230     if (Pte == NULL) {
    00231         return NULL;
    00232     }
    00233
    00234     if (Pte->Write == 0) {
    00235
    00236         //
    00237         // PTE is not writable, make it so.
    00238         //
    00239
    00240         PteContents = *(PMMPTE)Pte;
    00241
    00242         *InputPte = PteContents;
    00243
    00244         //
    00245         // Modify the PTE to ensure write permissions :
    00246         // turn on write and turn off fault on write.
    00247         //
    00248
    00249         PteContents.u.Hard.Write = 1;
    00250         PteContents.u.Hard.FaultOnWrite = 0;
    00251
    00252         *(PMMPTE)Pte = PteContents;
    00253
    00254         //
    00255         // BUGBUG John Vert (jvert) 3/4/1999
    00256         //   KeFillEntryTb is liable to IPI the other processors. This is
    00257         //   definitely NOT what we want as the other processors are frozen
    00258         //   in the debugger and we will deadlock if we try and IPI them.
    00259         //   Just flush the the current processor instead.
    00260         //KeFillEntryTb ((PHARDWARE_PTE)PointerPte, VirtualAddress, TRUE);
    00261         KiFlushSingleTb(TRUE, VirtualAddress);
    00262     }
    00263     else {
    00264         return AccessAddress;
    00265     }
    00266
    00267     return VirtualAddress;
    00268 }

PVOID64 MmDbgWriteCheck64 | ( | IN PVOID64 | VirtualAddress | ) |

Definition at line 368 of file axp64/debugsup.c.

References MmDbgWriteCheck().

    00374                    :
    00375
    00376     This routine returns the 43-bit superpage address which corresponds
    00377     to the specified virtual address if the specified virtual address is
    00378     writable.
    00379
    00380     N.B. This function should only be called at IRQL DISPATCH_LEVEL or
    00381          above.
    00382
    00383 Arguments:
    00384
    00385     VirtualAddress - Supplies the virtual address to check.
    00386
    00387 Return Value:
    00388
    00389     If the specified virtual address is invalid or not writable, then a
    00390     value of NULL is returned. Otherwise, the 43-bit superpage address
    00391     which corresponds to the specified virtual address is returned.
    00392
    00393 --*/
    00394
    00395 {
    00396     HARDWARE_PTE Opaque;
    00397
    00398     return MmDbgWriteCheck(VirtualAddress, &Opaque);
    00399 }