Changeset 58459 in vbox for trunk/src/VBox/Devices/EFI/Firmware/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug
- Timestamp:
- Oct 28, 2015 8:17:18 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/Firmware
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware
-
Property svn:mergeinfo
set to (toggle deleted branches)
/vendor/edk2/current 103735-103757
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/Firmware/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c
r48674 r58459 2 2 PE/Coff Extra Action library instances. 3 3 4 Copyright (c) 2010 , Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR> 5 5 This program and the accompanying materials 6 6 are licensed and made available under the terms and conditions of the BSD License … … 13 13 **/ 14 14 15 #include <Base.h> 16 #include <Library/PeCoffExtraActionLib.h> 17 #include <Library/DebugLib.h> 18 #include <Library/BaseLib.h> 19 #include <Library/IoLib.h> 20 #include <Library/PcdLib.h> 21 22 #include <ImageDebugSupport.h> 23 24 #define DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT 1 25 #define DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 2 15 #include <PeCoffExtraActionLib.h> 26 16 27 17 /** … … 48 38 49 39 /** 50 Performs additional actions after a PE/COFF image has been loaded and relocated.40 Common routine to report the PE/COFF image loading/relocating or unloading event. 51 41 52 42 If ImageContext is NULL, then ASSERT(). 53 43 54 44 @param ImageContext Pointer to the image context structure that describes the 55 PE/COFF image that has already been loaded and relocated. 45 PE/COFF image. 46 @param Signature IMAGE_LOAD_SIGNATURE or IMAGE_UNLOAD_SIGNATURE. 56 47 57 48 **/ 58 49 VOID 59 EFIAPI 60 PeCoffLoaderRelocateImageExtraAction ( 61 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext 62 ) 63 { 64 BOOLEAN InterruptState; 65 UINTN Dr0; 66 UINTN Dr1; 67 UINTN Dr2; 68 UINTN Dr3; 69 UINTN Dr7; 70 UINTN Cr4; 71 UINTN NewDr7; 72 UINT8 LoadImageMethod; 73 UINT8 DebugAgentStatus; 50 PeCoffLoaderExtraActionCommon ( 51 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, 52 IN UINTN Signature 53 ) 54 { 55 BOOLEAN InterruptState; 56 UINTN Dr0; 57 UINTN Dr1; 58 UINTN Dr2; 59 UINTN Dr3; 60 UINTN Dr7; 61 UINTN Cr4; 62 UINTN NewDr7; 63 UINT8 LoadImageMethod; 64 UINT8 DebugAgentStatus; 65 IA32_DESCRIPTOR IdtDescriptor; 66 IA32_IDT_GATE_DESCRIPTOR OriginalIdtEntry; 67 BOOLEAN IdtEntryHooked; 74 68 75 69 ASSERT (ImageContext != NULL); … … 84 78 InterruptState = SaveAndDisableInterrupts (); 85 79 80 IdtEntryHooked = FALSE; 81 LoadImageMethod = PcdGet8 (PcdDebugLoadImageMethod); 82 AsmReadIdtr (&IdtDescriptor); 83 if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) { 84 if (!CheckDebugAgentHandler (&IdtDescriptor, SOFT_INT_VECTOR_NUM)) { 85 // 86 // Do not trigger INT3 if Debug Agent did not setup IDT entries. 87 // 88 return; 89 } 90 } else { 91 if (!CheckDebugAgentHandler (&IdtDescriptor, IO_HW_BREAKPOINT_VECTOR_NUM)) { 92 // 93 // Save and update IDT entry for INT1 94 // 95 SaveAndUpdateIdtEntry1 (&IdtDescriptor, &OriginalIdtEntry); 96 IdtEntryHooked = TRUE; 97 } 98 } 99 86 100 // 87 101 // Save Debug Register State … … 95 109 96 110 // 97 // DR0 = IMAGE_LOAD_SIGNATURE111 // DR0 = Signature 98 112 // DR1 = The address of the Null-terminated ASCII string for the PE/COFF image's PDB file name 99 113 // DR2 = The pointer to the ImageContext structure … … 103 117 // 104 118 AsmWriteDr7 (0); 105 AsmWriteDr0 ( IMAGE_LOAD_SIGNATURE);106 AsmWriteDr1 ((UINTN) ImageContext->PdbPointer);107 AsmWriteDr2 ((UINTN) ImageContext);119 AsmWriteDr0 (Signature); 120 AsmWriteDr1 ((UINTN) ImageContext->PdbPointer); 121 AsmWriteDr2 ((UINTN) ImageContext); 108 122 AsmWriteDr3 (IO_PORT_BREAKPOINT_ADDRESS); 109 123 110 LoadImageMethod = PcdGet8 (PcdDebugLoadImageMethod);111 124 if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) { 112 125 AsmWriteDr7 (0x20000480); … … 133 146 // 134 147 NewDr7 = AsmReadDr7 (); 135 if (!IsDrxEnabled (0, NewDr7)) { 148 if (!IsDrxEnabled (0, NewDr7) && (AsmReadDr0 () == 0 || AsmReadDr0 () == Signature)) { 149 // 150 // If user changed Dr3 (by setting HW bp in the above exception handler, 151 // we will not set Dr0 to 0 in GO/STEP handler because the break cause is not IMAGE_LOAD/_UNLOAD. 152 // 136 153 AsmWriteDr0 (Dr0); 137 154 } 138 if (!IsDrxEnabled (1, NewDr7) ) {155 if (!IsDrxEnabled (1, NewDr7) && (AsmReadDr1 () == (UINTN) ImageContext->PdbPointer)) { 139 156 AsmWriteDr1 (Dr1); 140 157 } 141 if (!IsDrxEnabled (2, NewDr7) ) {158 if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN) ImageContext)) { 142 159 AsmWriteDr2 (Dr2); 143 160 } 144 if (!IsDrxEnabled (3, NewDr7) ) {161 if (!IsDrxEnabled (3, NewDr7) && (AsmReadDr3 () == IO_PORT_BREAKPOINT_ADDRESS)) { 145 162 AsmWriteDr3 (Dr3); 146 163 } … … 152 169 } 153 170 // 171 // Restore original IDT entry for INT1 if it was hooked. 172 // 173 if (IdtEntryHooked) { 174 RestoreIdtEntry1 (&IdtDescriptor, &OriginalIdtEntry); 175 } 176 // 154 177 // Restore the interrupt state 155 178 // 156 179 SetInterruptState (InterruptState); 180 } 181 182 /** 183 Performs additional actions after a PE/COFF image has been loaded and relocated. 184 185 @param ImageContext Pointer to the image context structure that describes the 186 PE/COFF image that has already been loaded and relocated. 187 188 **/ 189 VOID 190 EFIAPI 191 PeCoffLoaderRelocateImageExtraAction ( 192 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext 193 ) 194 { 195 PeCoffLoaderExtraActionCommon (ImageContext, IMAGE_LOAD_SIGNATURE); 157 196 } 158 197 … … 160 199 Performs additional actions just before a PE/COFF image is unloaded. Any resources 161 200 that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed. 162 163 If ImageContext is NULL, then ASSERT().164 201 165 202 @param ImageContext Pointer to the image context structure that describes the … … 173 210 ) 174 211 { 175 BOOLEAN InterruptState; 176 UINTN Dr0; 177 UINTN Dr1; 178 UINTN Dr2; 179 UINTN Dr3; 180 UINTN Dr7; 181 UINTN Cr4; 182 UINTN NewDr7; 183 UINT8 LoadImageMethod; 184 UINT8 DebugAgentStatus; 185 186 ASSERT (ImageContext != NULL); 187 188 if (ImageContext->PdbPointer != NULL) { 189 DEBUG((EFI_D_ERROR, " PDB = %a\n", ImageContext->PdbPointer)); 190 } 191 192 // 193 // Disable interrupts and save the current interrupt state 194 // 195 InterruptState = SaveAndDisableInterrupts (); 196 197 // 198 // Save Debug Register State 199 // 200 Dr0 = AsmReadDr0 (); 201 Dr1 = AsmReadDr1 (); 202 Dr2 = AsmReadDr2 (); 203 Dr3 = AsmReadDr3 (); 204 Dr7 = AsmReadDr7 (); 205 Cr4 = AsmReadCr4 (); 206 207 // 208 // DR0 = IMAGE_UNLOAD_SIGNATURE 209 // DR1 = The address of the Null-terminated ASCII string for the PE/COFF image's PDB file name 210 // DR2 = The pointer to the ImageContext structure 211 // DR3 = IO_PORT_BREAKPOINT_ADDRESS 212 // DR7 = Disables all HW breakpoints except for DR3 I/O port access of length 1 byte 213 // CR4 = Make sure DE(BIT3) is set 214 // 215 AsmWriteDr7 (0); 216 AsmWriteDr0 (IMAGE_UNLOAD_SIGNATURE); 217 AsmWriteDr1 ((UINTN)ImageContext->PdbPointer); 218 AsmWriteDr2 ((UINTN)ImageContext); 219 AsmWriteDr3 (IO_PORT_BREAKPOINT_ADDRESS); 220 221 LoadImageMethod = PcdGet8 (PcdDebugLoadImageMethod); 222 if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) { 223 AsmWriteDr7 (0x20000480); 224 AsmWriteCr4 (Cr4 | BIT3); 225 // 226 // Do an IN from IO_PORT_BREAKPOINT_ADDRESS to generate a HW breakpoint until the port 227 // returns a read value other than DEBUG_AGENT_IMAGE_WAIT 228 // 229 do { 230 DebugAgentStatus = IoRead8 (IO_PORT_BREAKPOINT_ADDRESS); 231 } while (DebugAgentStatus == DEBUG_AGENT_IMAGE_WAIT); 232 233 } else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) { 234 // 235 // Generate a software break point. 236 // 237 CpuBreakpoint (); 238 } 239 240 // 241 // Restore Debug Register State only when Host didn't change it inside exception handler. 242 // E.g.: User halts the target and sets the HW breakpoint while target is 243 // in the above exception handler 244 // 245 NewDr7 = AsmReadDr7 (); 246 if (!IsDrxEnabled (0, NewDr7)) { 247 AsmWriteDr0 (Dr0); 248 } 249 if (!IsDrxEnabled (1, NewDr7)) { 250 AsmWriteDr1 (Dr1); 251 } 252 if (!IsDrxEnabled (2, NewDr7)) { 253 AsmWriteDr2 (Dr2); 254 } 255 if (!IsDrxEnabled (3, NewDr7)) { 256 AsmWriteDr3 (Dr3); 257 } 258 if (AsmReadCr4 () == (Cr4 | BIT3)) { 259 AsmWriteCr4 (Cr4); 260 } 261 if (NewDr7 == 0x20000480) { 262 AsmWriteDr7 (Dr7); 263 } 264 265 // 266 // Restore the interrupt state 267 // 268 SetInterruptState (InterruptState); 269 } 212 PeCoffLoaderExtraActionCommon (ImageContext, IMAGE_UNLOAD_SIGNATURE); 213 } -
trunk/src/VBox/Devices/EFI/Firmware/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf
r48674 r58459 2 2 # PeCoffExtraAction Library to support source level debug. 3 3 # 4 # Copyright (c) 2010 , Intel Corporation. All rights reserved.<BR>4 # Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR> 5 5 # 6 6 # This program and the accompanying materials … … 17 17 INF_VERSION = 0x00010005 18 18 BASE_NAME = PeCoffExtraActionLib 19 MODULE_UNI_FILE = PeCoffExtraActionLib.uni 19 20 FILE_GUID = 8F01CBD5-E069-44d7-90C9-35F0318603AD 20 21 MODULE_TYPE = BASE … … 29 30 30 31 [Sources.common] 32 PeCoffExtraActionLib.h 31 33 PeCoffExtraActionLib.c 34 35 [Sources.IA32] 36 Ia32/IntHandlerFuncs.c 37 Ia32/IntHandler.asm 38 Ia32/IntHandler.S | GCC 39 40 [Sources.X64] 41 X64/IntHandlerFuncs.c 42 X64/IntHandler.asm 43 X64/IntHandler.S | GCC 32 44 33 45 [Packages] … … 42 54 43 55 [Pcd] 44 gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod 45 56 gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod ## CONSUMES 57
Note:
See TracChangeset
for help on using the changeset viewer.