00001 /*++ 00002 00003 Copyright (c) 1989 Microsoft Corporation 00004 Copyright (c) 1993 IBM Corporation 00005 00006 Module Name: 00007 00008 debugsup.c 00009 00010 Abstract: 00011 00012 This module contains routines which provide support for the 00013 kernel debugger. 00014 00015 Author: 00016 00017 Lou Perazzoli (loup) 02-Aug-90 00018 00019 Modified for PowerPC by Mark Mergen (mergen@watson.ibm.com) 6-Oct-93 00020 00021 Revision History: 00022 00023 --*/ 00024 00025 #include "mi.h" 00026 00027 PVOID 00028 MmDbgReadCheck ( 00029 IN PVOID VirtualAddress 00030 ) 00031 00032 /*++ 00033 00034 Routine Description: 00035 00036 PowerPC implementation specific: 00037 00038 This routine returns the virtual address which is valid (mapped) 00039 for read access. 00040 00041 The address may be within the PowerPC kernel BAT or may be 00042 otherwise valid and readable. 00043 00044 Arguments: 00045 00046 VirtualAddress - Supplies the virtual address to check. 00047 00048 Return Value: 00049 00050 Returns NULL if the address is not valid or readable, otherwise 00051 returns the virtual address. 00052 00053 Environment: 00054 00055 Kernel mode IRQL at DISPATCH_LEVEL or greater. 00056 00057 --*/ 00058 00059 { 00060 if ((VirtualAddress >= (PVOID)KSEG0_BASE) && 00061 (VirtualAddress < (PVOID)KSEG2_BASE)) { 00062 return VirtualAddress; 00063 } 00064 00065 if ((VirtualAddress >= (PVOID)KIPCR) && 00066 (VirtualAddress < (PVOID)(KIPCR2 + PAGE_SIZE))) { 00067 return VirtualAddress; 00068 } 00069 00070 if (!MmIsAddressValid (VirtualAddress)) { 00071 return NULL; 00072 } 00073 00074 return VirtualAddress; 00075 } 00076 00077 PVOID 00078 MmDbgWriteCheck ( 00079 IN PVOID VirtualAddress 00080 ) 00081 00082 /*++ 00083 00084 Routine Description: 00085 00086 PowerPC implementation specific: 00087 00088 This routine returns the virtual address which is valid (mapped) 00089 for write access. 00090 00091 The address may be within the PowerPC kernel BAT or may be 00092 otherwise valid and writable. 00093 00094 Arguments: 00095 00096 VirtualAddress - Supplies the virtual address to check. 00097 00098 Return Value: 00099 00100 Returns NULL if the address is not valid or writable, otherwise 00101 returns the virtual address. 00102 00103 Environment: 00104 00105 Kernel mode IRQL at DISPATCH_LEVEL or greater. 00106 00107 --*/ 00108 00109 { 00110 PMMPTE PointerPte; 00111 00112 if ((VirtualAddress >= (PVOID)KSEG0_BASE) && 00113 (VirtualAddress < (PVOID)KSEG2_BASE)) { 00114 return VirtualAddress; 00115 } 00116 00117 if ((VirtualAddress >= (PVOID)KIPCR) && 00118 (VirtualAddress < (PVOID)(KIPCR2 + PAGE_SIZE))) { 00119 return VirtualAddress; 00120 } 00121 00122 if (!MmIsAddressValid (VirtualAddress)) { 00123 return NULL; 00124 } 00125 00126 // 00127 // This is being added back in permanently since the PowerPC 00128 // hardware debug registers break in before the instruction 00129 // is executed. This will generally allow the kernel debugger 00130 // to step over the instruction that triggered the hardware 00131 // debug register breakpoint. 00132 // 00133 00134 if (VirtualAddress <= MM_HIGHEST_USER_ADDRESS) { 00135 00136 // This code is similar in spirit to that in the MIPS version. 00137 // It returns a writable alias for breakpoints in user pages. 00138 // However, it uses the virtual address reserved for the debugger, 00139 // rather than the wired-in KSEG0 translation available in MIPS. 00140 // 00141 // N.B. Microsoft says kernel debugger can't do user code at all. 00142 00143 return MmDbgTranslatePhysicalAddress ( 00144 MmGetPhysicalAddress (VirtualAddress) ); 00145 } 00146 00147 PointerPte = MiGetPteAddress (VirtualAddress); 00148 if (PointerPte->u.Hard.Write == 0) { 00149 return NULL; 00150 } 00151 00152 return VirtualAddress; 00153 } 00154 00155 PVOID64 00156 MmDbgReadCheck64 ( 00157 IN PVOID64 VirtualAddress 00158 ) 00159 00160 /*++ 00161 00162 Routine Description: 00163 00164 PowerPC implementation specific: 00165 00166 This routine returns the virtual address which is valid (mapped) 00167 for read access. 00168 00169 The address may be within the PowerPC kernel BAT or may be 00170 otherwise valid and readable. 00171 00172 NO 64-bit suport, return NULL. 00173 00174 Arguments: 00175 00176 VirtualAddress - Supplies the virtual address to check. 00177 00178 Return Value: 00179 00180 Returns NULL if the address is not valid or readable, otherwise 00181 returns the virtual address. 00182 00183 Environment: 00184 00185 Kernel mode IRQL at DISPATCH_LEVEL or greater. 00186 00187 --*/ 00188 00189 { 00190 return NULL; 00191 } 00192 00193 PVOID64 00194 MmDbgWriteCheck64 ( 00195 IN PVOID64 VirtualAddress 00196 ) 00197 00198 /*++ 00199 00200 Routine Description: 00201 00202 PowerPC implementation specific: 00203 00204 This routine returns the virtual address which is valid (mapped) 00205 for write access. 00206 00207 The address may be within the PowerPC kernel BAT or may be 00208 otherwise valid and writable. 00209 00210 NO 64-bit suport, return NULL. 00211 00212 Arguments: 00213 00214 VirtualAddress - Supplies the virtual address to check. 00215 00216 Return Value: 00217 00218 Returns NULL if the address is not valid or writable, otherwise 00219 returns the virtual address. 00220 00221 Environment: 00222 00223 Kernel mode IRQL at DISPATCH_LEVEL or greater. 00224 00225 --*/ 00226 00227 { 00228 00229 return NULL; 00230 } 00231 00232 PVOID 00233 MmDbgTranslatePhysicalAddress ( 00234 IN PHYSICAL_ADDRESS PhysicalAddress 00235 ) 00236 00237 /*++ 00238 00239 Routine Description: 00240 00241 PowerPC implementation specific: 00242 00243 This routine maps the specified physical address and returns 00244 the virtual address which maps the physical address. 00245 00246 The next call to MmDbgTranslatePhyiscalAddress removes the 00247 previous phyiscal address translation, hence on a single 00248 physical address can be examined at a time (can't cross page 00249 boundaries). 00250 00251 Arguments: 00252 00253 PhysicalAddress - Supplies the phyiscal address to map and translate. 00254 00255 Return Value: 00256 00257 The virtual address which corresponds to the phyiscal address. 00258 00259 Environment: 00260 00261 Kernel mode IRQL at DISPATCH_LEVEL or greater. 00262 00263 --*/ 00264 00265 { 00266 PVOID BaseAddress; 00267 00268 BaseAddress = MiGetVirtualAddressMappedByPte (MmDebugPte); 00269 00270 KiFlushSingleTb (TRUE, BaseAddress); 00271 00272 *MmDebugPte = ValidKernelPte; 00273 MmDebugPte->u.Hard.PageFrameNumber = PhysicalAddress.LowPart >> PAGE_SHIFT; 00274 00275 return (PVOID)((ULONG)BaseAddress + BYTE_OFFSET(PhysicalAddress.LowPart)); 00276 }