VirtualBox

Ignore:
Timestamp:
Oct 28, 2015 8:17:18 PM (9 years ago)
Author:
vboxsync
Message:

EFI/Firmware: 'svn merge /vendor/edk2/UDK2010.SR1 /vendor/edk2/current .', reverting and removing files+dirs listed in ReadMe.vbox, resolving conflicts with help from ../UDK2014.SP1/. This is a raw untested merge.

Location:
trunk/src/VBox/Devices/EFI/Firmware
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/Firmware

  • trunk/src/VBox/Devices/EFI/Firmware/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c

    r48674 r58459  
    22  PE/Coff Extra Action library instances.
    33
    4   Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1313**/
    1414
    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>
    2616
    2717/**
     
    4838
    4939/**
    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.
    5141
    5242  If ImageContext is NULL, then ASSERT().
    53 
     43 
    5444  @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.
    5647
    5748**/
    5849VOID
    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;
     50PeCoffLoaderExtraActionCommon (
     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;
    7468
    7569  ASSERT (ImageContext != NULL);
     
    8478  InterruptState = SaveAndDisableInterrupts ();
    8579
     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 
    86100  //
    87101  // Save Debug Register State
     
    95109
    96110  //
    97   // DR0 = IMAGE_LOAD_SIGNATURE
     111  // DR0 = Signature
    98112  // DR1 = The address of the Null-terminated ASCII string for the PE/COFF image's PDB file name
    99113  // DR2 = The pointer to the ImageContext structure
     
    103117  //
    104118  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);
    108122  AsmWriteDr3 (IO_PORT_BREAKPOINT_ADDRESS);
    109123
    110   LoadImageMethod = PcdGet8 (PcdDebugLoadImageMethod);
    111124  if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) {
    112125    AsmWriteDr7 (0x20000480);
     
    133146  //
    134147  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    //
    136153    AsmWriteDr0 (Dr0);
    137154  }
    138   if (!IsDrxEnabled (1, NewDr7)) {
     155  if (!IsDrxEnabled (1, NewDr7) && (AsmReadDr1 () == (UINTN) ImageContext->PdbPointer)) {
    139156    AsmWriteDr1 (Dr1);
    140157  }
    141   if (!IsDrxEnabled (2, NewDr7)) {
     158  if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN) ImageContext)) {
    142159    AsmWriteDr2 (Dr2);
    143160  }
    144   if (!IsDrxEnabled (3, NewDr7)) {
     161  if (!IsDrxEnabled (3, NewDr7) && (AsmReadDr3 () == IO_PORT_BREAKPOINT_ADDRESS)) {
    145162    AsmWriteDr3 (Dr3);
    146163  }
     
    152169  }
    153170  //
     171  // Restore original IDT entry for INT1 if it was hooked.
     172  //
     173  if (IdtEntryHooked) {
     174    RestoreIdtEntry1 (&IdtDescriptor, &OriginalIdtEntry);
     175  }
     176  //
    154177  // Restore the interrupt state
    155178  //
    156179  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**/
     189VOID
     190EFIAPI
     191PeCoffLoaderRelocateImageExtraAction (
     192  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext
     193  )
     194{
     195  PeCoffLoaderExtraActionCommon (ImageContext, IMAGE_LOAD_SIGNATURE);
    157196}
    158197
     
    160199  Performs additional actions just before a PE/COFF image is unloaded.  Any resources
    161200  that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
    162 
    163   If ImageContext is NULL, then ASSERT().
    164201
    165202  @param  ImageContext  Pointer to the image context structure that describes the
     
    173210  )
    174211{
    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  
    22#  PeCoffExtraAction Library to support source level debug.
    33#
    4 #  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
     4#  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55#
    66#  This program and the accompanying materials
     
    1717  INF_VERSION                    = 0x00010005
    1818  BASE_NAME                      = PeCoffExtraActionLib
     19  MODULE_UNI_FILE                = PeCoffExtraActionLib.uni
    1920  FILE_GUID                      = 8F01CBD5-E069-44d7-90C9-35F0318603AD
    2021  MODULE_TYPE                    = BASE
     
    2930
    3031[Sources.common]
     32  PeCoffExtraActionLib.h
    3133  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
    3244
    3345[Packages]
     
    4254
    4355[Pcd]
    44   gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod
    45  
     56  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod    ## CONSUMES
     57
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette