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:
2 edited

Legend:

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

  • trunk/src/VBox/Devices/EFI/Firmware/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c

    r48674 r58459  
    22  SEC Core Debug Agent Library instance implementition.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, 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
     
    1515#include "SecPeiDebugAgentLib.h"
    1616
    17 CONST BOOLEAN                MultiProcessorDebugSupport = FALSE;
    18 
    19 /**
    20   Get pointer to Mailbox from IDT entry before memory is ready.
     17GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN  mSkipBreakpoint = FALSE;
     18
     19
     20GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi = {
     21  &mVectorHandoffInfoDebugAgent[0]
     22};
     23
     24//
     25// Ppis to be installed
     26//
     27GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR           mVectorHandoffInfoPpiList[] = {
     28  {
     29    (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
     30    &gEfiVectorHandoffInfoPpiGuid,
     31    &mVectorHandoffInfoPpi
     32  }
     33};
     34
     35GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList[1] = {
     36  {
     37    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
     38    &gEfiPeiMemoryDiscoveredPpiGuid,
     39    DebugAgentCallbackMemoryDiscoveredPpi
     40  }
     41};
     42
     43/**
     44  Check if debug agent support multi-processor.
     45
     46  @retval TRUE    Multi-processor is supported.
     47  @retval FALSE   Multi-processor is not supported.
     48
     49**/
     50BOOLEAN
     51MultiProcessorDebugSupport (
     52  VOID
     53  )
     54{
     55  return FALSE;
     56}
     57
     58/**
     59  Read the Attach/Break-in symbols from the debug port.
     60
     61  @param[in]  Handle         Pointer to Debug Port handle.
     62  @param[out] BreakSymbol    Returned break symbol.
     63
     64  @retval EFI_SUCCESS        Read the symbol in BreakSymbol.
     65  @retval EFI_NOT_FOUND      No read the break symbol.
     66
     67**/
     68EFI_STATUS
     69DebugReadBreakSymbol (
     70  IN  DEBUG_PORT_HANDLE      Handle,
     71  OUT UINT8                  *BreakSymbol
     72  )
     73{
     74  EFI_STATUS                 Status;
     75  DEBUG_PACKET_HEADER        DebugHeader;
     76  UINT8                      *Data8;
     77
     78  *BreakSymbol = 0;
     79  //
     80  // If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty.
     81  //
     82  Data8 = (UINT8 *) &DebugHeader;
     83  while (TRUE) {
     84    //
     85    // If start symbol is not received
     86    //
     87    if (!DebugPortPollBuffer (Handle)) {
     88      //
     89      // If no data in Debug Port, exit
     90      //
     91      break;
     92    }
     93    //
     94    // Try to read the start symbol
     95    //
     96    DebugPortReadBuffer (Handle, Data8, 1, 0);
     97    if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {
     98      *BreakSymbol = *Data8;
     99      DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *BreakSymbol);
     100      return EFI_SUCCESS;
     101    }
     102    if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {
     103      Status = ReadRemainingBreakPacket (Handle, &DebugHeader);
     104      if (Status == EFI_SUCCESS) {
     105        *BreakSymbol = DebugHeader.Command;
     106        DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer break symbol received %x", *BreakSymbol);
     107        return EFI_SUCCESS;
     108      }
     109      if (Status == EFI_TIMEOUT) {
     110        break;
     111      }
     112    }
     113  }
     114
     115  return EFI_NOT_FOUND;
     116}
     117
     118/**
     119  Get the pointer to location saved Mailbox pointer from IDT entry.
    21120
    22121**/
    23122VOID *
    24 GetMailboxPointerInIdtEntry (
     123GetLocationSavedMailboxPointerInIdtEntry (
    25124  VOID
    26125  )
    27126{
    28   IA32_IDT_GATE_DESCRIPTOR   *IdtEntry;
    29   IA32_DESCRIPTOR            IdtDescriptor;
    30   UINTN                      Mailbox;
    31 
    32   AsmReadIdtr (&IdtDescriptor);
    33   IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
    34 
    35   Mailbox = IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + (IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16);
    36   return (VOID *) Mailbox;
     127  UINTN                     *MailboxLocation;
     128
     129  MailboxLocation = (UINTN *) GetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR);
     130  //
     131  // *MailboxLocation is the pointer to Mailbox
     132  //
     133  VerifyMailboxChecksum ((DEBUG_AGENT_MAILBOX *) (*MailboxLocation));
     134  return MailboxLocation;
    37135}
    38136
     
    40138  Set the pointer of Mailbox into IDT entry before memory is ready.
    41139
    42   @param[in]  Mailbox       The pointer of Mailbox.
     140  @param[in]  MailboxLocation    Pointer to location saved Mailbox pointer.
    43141
    44142**/
    45143VOID
    46 SetMailboxPointerInIdtEntry (
    47   IN VOID                    *Mailbox
    48   )
    49 {
    50   IA32_IDT_GATE_DESCRIPTOR   *IdtEntry;
    51   IA32_DESCRIPTOR            IdtDescriptor;
    52 
    53   AsmReadIdtr (&IdtDescriptor);
    54   IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
    55 
    56   IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow  = (UINT16)(UINTN)Mailbox;
    57   IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)Mailbox >> 16);
    58 }
    59 
    60 /**
    61   Get the pointer to Mailbox from IDT entry and build the Mailbox into GUIDed Hob
    62   after memory is ready.
    63 
    64   @return Pointer to Mailbox.
    65 
    66 **/
    67 DEBUG_AGENT_MAILBOX *
    68 BuildMailboxHob (
     144SetLocationSavedMailboxPointerInIdtEntry (
     145  IN VOID                  *MailboxLocation
     146  )
     147{
     148  SetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR, MailboxLocation);
     149}
     150
     151/**
     152  Get the location of Mailbox pointer from the GUIDed HOB.
     153
     154  @return Pointer to the location saved Mailbox pointer.
     155
     156**/
     157UINT64 *
     158GetMailboxLocationFromHob (
    69159  VOID
    70160  )
    71161{
    72   DEBUG_AGENT_MAILBOX       *Mailbox;
    73 
    74   Mailbox = (DEBUG_AGENT_MAILBOX *) GetMailboxPointerInIdtEntry ();
    75 
    76   return BuildGuidDataHob (
    77            &gEfiDebugAgentGuid,
    78            Mailbox,
    79            sizeof (DEBUG_AGENT_MAILBOX)
    80            );
     162  EFI_HOB_GUID_TYPE        *GuidHob;
     163
     164  GuidHob = GetFirstGuidHob (&gEfiDebugAgentGuid);
     165  if (GuidHob == NULL) {
     166    return NULL;
     167  }
     168  return (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
    81169}
    82170
     
    92180  )
    93181{
    94   return (DEBUG_AGENT_MAILBOX *) GetMailboxPointerInIdtEntry ();
     182  UINT64               DebugPortHandle;
     183  UINT64               *MailboxLocationInIdt;
     184  UINT64               *MailboxLocationInHob;
     185  DEBUG_AGENT_MAILBOX  *Mailbox;
     186
     187  //
     188  // Get mailbox from IDT entry firstly
     189  //
     190  MailboxLocationInIdt = GetLocationSavedMailboxPointerInIdtEntry ();
     191  Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInIdt);
     192  //
     193  // Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() nested
     194  //
     195  if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1 ||
     196      Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL) {
     197    //
     198    // If mailbox was setup in SEC or the current CPU arch is different from the init arch
     199    // Debug Agent initialized, return the mailbox from IDT entry directly.
     200    // Otherwise, we need to check the mailbox location saved in GUIDed HOB further.
     201    //
     202    return Mailbox;
     203  }
     204
     205  MailboxLocationInHob = GetMailboxLocationFromHob ();
     206  //
     207  // Compare mailbox in IDT enry with mailbox in HOB,
     208  // need to fix mailbox location if HOB moved by PEI CORE
     209  //
     210  if (MailboxLocationInHob != MailboxLocationInIdt && MailboxLocationInHob != NULL) {
     211    Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInHob);
     212    //
     213    // Fix up Debug Port handler and save new mailbox in IDT entry
     214    //
     215    Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));
     216    DebugPortHandle = (UINT64)((UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));
     217    UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
     218    *MailboxLocationInHob = (UINT64)(UINTN)Mailbox;
     219    SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob);
     220    //
     221    // Clean CheckMailboxInHob flag
     222    //
     223    Mailbox->DebugFlag.Bits.CheckMailboxInHob = 0;
     224    UpdateMailboxChecksum (Mailbox);
     225  }
     226
     227  return Mailbox;
    95228}
    96229
     
    107240{
    108241  DEBUG_AGENT_MAILBOX    *DebugAgentMailbox;
    109  
    110   DebugAgentMailbox = (DEBUG_AGENT_MAILBOX *)GetMailboxPointerInIdtEntry ();
     242
     243  DebugAgentMailbox = GetMailboxPointer ();
    111244
    112245  return (DEBUG_PORT_HANDLE) (UINTN)(DebugAgentMailbox->DebugPortHandle);
     
    114247
    115248/**
    116   Trigger one software interrupt to debug agent to handle it.
    117 
    118   @param Signature       Software interrupt signature.
    119 
    120 **/
    121 VOID
    122 TriggerSoftInterrupt (
    123   UINT32                 Signature
    124   )
    125 {
    126   UINTN                  Dr0;
    127   UINTN                  Dr1;
    128 
    129   //
    130   // Save Debug Register State
    131   //
    132   Dr0 = AsmReadDr0 ();
    133   Dr1 = AsmReadDr1 ();
    134 
    135   //
    136   // DR0 = Signature
    137   //
    138   AsmWriteDr0 (SOFT_INTERRUPT_SIGNATURE);
    139   AsmWriteDr1 (Signature);
    140 
    141   //
    142   // Do INT3 to communicate with HOST side
    143   //
    144   CpuBreakpoint ();
    145 
    146   //
    147   // Restore Debug Register State only when Host didn't change it inside exception handler.
    148   //   Dr registers can only be changed by setting the HW breakpoint.
    149   //
    150   AsmWriteDr0 (Dr0);
    151   AsmWriteDr1 (Dr1);
    152 
     249  Debug Agent provided notify callback function on Memory Discovered PPI.
     250
     251  @param[in] PeiServices      Indirect reference to the PEI Services Table.
     252  @param[in] NotifyDescriptor Address of the notification descriptor data structure.
     253  @param[in] Ppi              Address of the PPI that was installed.
     254
     255  @retval EFI_SUCCESS If the function completed successfully.
     256
     257**/
     258EFI_STATUS
     259EFIAPI
     260DebugAgentCallbackMemoryDiscoveredPpi (
     261  IN EFI_PEI_SERVICES                     **PeiServices,
     262  IN EFI_PEI_NOTIFY_DESCRIPTOR            *NotifyDescriptor,
     263  IN VOID                                 *Ppi
     264  )
     265{
     266  EFI_STATUS                     Status;
     267  DEBUG_AGENT_MAILBOX            *Mailbox;
     268  BOOLEAN                        InterruptStatus;
     269  EFI_PHYSICAL_ADDRESS           Address;
     270  DEBUG_AGENT_MAILBOX            *NewMailbox;
     271  UINT64                         *MailboxLocationInHob;
     272
     273  //
     274  // Save and disable original interrupt status
     275  //
     276  InterruptStatus = SaveAndDisableInterrupts ();
     277
     278  //
     279  // Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer
     280  //
     281  Status = PeiServicesAllocatePages (
     282             EfiACPIMemoryNVS,
     283             EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),
     284             &Address
     285             );
     286  ASSERT_EFI_ERROR (Status);
     287  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
     288  //
     289  // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
     290  // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
     291  // reallocates the HOB.
     292  //
     293  Mailbox = GetMailboxPointer ();
     294  CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
     295  CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));
     296  //
     297  // Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one
     298  //
     299  MailboxLocationInHob = GetMailboxLocationFromHob ();
     300  ASSERT (MailboxLocationInHob != NULL);
     301  *MailboxLocationInHob = (UINT64)(UINTN)NewMailbox;
     302  SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob);
     303  //
     304  // Update Debug Port Handle in new Mailbox
     305  //
     306  UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));
     307  //
     308  // Set physical memory ready flag
     309  //
     310  SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
     311
     312  if (IsHostAttached ()) {
     313    //
     314    // Trigger one software interrupt to inform HOST
     315    //
     316    TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
     317  }
     318
     319  //
     320  // Restore interrupt state.
     321  //
     322  SetInterruptState (InterruptStatus);
     323
     324  return EFI_SUCCESS;
    153325}
    154326
     
    193365{
    194366  DEBUG_AGENT_MAILBOX              *Mailbox;
     367  DEBUG_AGENT_MAILBOX              *NewMailbox;
    195368  DEBUG_AGENT_MAILBOX              MailboxInStack;
    196369  DEBUG_AGENT_PHASE2_CONTEXT       Phase2Context;
    197370  DEBUG_AGENT_CONTEXT_POSTMEM_SEC  *DebugAgentContext;
     371  EFI_STATUS                       Status;
     372  IA32_DESCRIPTOR                  *Ia32Idtr;
     373  IA32_IDT_ENTRY                   *Ia32IdtEntry;
     374  UINT64                           DebugPortHandle;
     375  UINT64                           MailboxLocation;
     376  UINT64                           *MailboxLocationPointer;
     377  EFI_PHYSICAL_ADDRESS             Address;
    198378
    199379  DisableInterrupts ();
     
    205385    InitializeDebugIdt ();
    206386
     387    MailboxLocation = (UINT64)(UINTN)&MailboxInStack;
    207388    Mailbox = &MailboxInStack;
    208389    ZeroMem ((VOID *) Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
    209 
    210390    //
    211391    // Get and save debug port handle and set the length of memory block.
    212392    //
    213     SetMailboxPointerInIdtEntry ((VOID *) Mailbox);
     393    SetLocationSavedMailboxPointerInIdtEntry (&MailboxLocation);
     394    //
     395    // Force error message could be printed during the first shakehand between Target/HOST.
     396    //
     397    SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DEBUG_AGENT_ERROR);
     398    //
     399    // Save init arch type when debug agent initialized
     400    //
     401    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
    214402
    215403    InitializeDebugTimer ();
    216404
     405    Phase2Context.InitFlag = InitFlag;
    217406    Phase2Context.Context  = Context;
    218407    Phase2Context.Function = Function;
    219408    DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);
    220 
    221409    //
    222410    // If reaches here, it means Debug Port initialization failed.
     
    227415
    228416  case DEBUG_AGENT_INIT_POSTMEM_SEC:
    229 
     417    Mailbox = GetMailboxPointer ();
    230418    //
    231419    // Memory has been ready
    232420    //
    233     if (IsHostConnected()) {
     421    SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
     422    if (IsHostAttached ()) {
    234423      //
    235424      // Trigger one software interrupt to inform HOST
     
    237426      TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
    238427    }
    239 
     428    //
     429    // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
     430    //
     431    Status = PeiServicesInstallPpi (&mVectorHandoffInfoPpiList[0]);
     432    if (EFI_ERROR (Status)) {
     433      DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
     434      CpuDeadLoop ();
     435    }
     436    //
     437    // Fix up Debug Port handle address and mailbox address
     438    //
    240439    DebugAgentContext = (DEBUG_AGENT_CONTEXT_POSTMEM_SEC *) Context;
    241 
    242     Mailbox = (DEBUG_AGENT_MAILBOX *) GetMailboxPointerInIdtEntry ();
    243     Mailbox->DebugPortHandle = Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset;
    244 
    245     Mailbox = BuildMailboxHob ();
    246     Mailbox = (DEBUG_AGENT_MAILBOX *) ((UINTN) Mailbox + DebugAgentContext->HeapMigrateOffset);
    247 
    248     SetMailboxPointerInIdtEntry ((VOID *) Mailbox);
    249 
    250     EnableInterrupts ();
    251 
     440    if (DebugAgentContext != NULL) {
     441      DebugPortHandle = (UINT64)(UINT32)(Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset);
     442      UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
     443      Mailbox = (DEBUG_AGENT_MAILBOX *) ((UINTN) Mailbox + DebugAgentContext->StackMigrateOffset);
     444      MailboxLocation = (UINT64)(UINTN)Mailbox;
     445      //
     446      // Build mailbox location in HOB and fix-up its address
     447      //
     448      MailboxLocationPointer = BuildGuidDataHob (
     449                                 &gEfiDebugAgentGuid,
     450                                 &MailboxLocation,
     451                                 sizeof (UINT64)
     452                                 );
     453      MailboxLocationPointer = (UINT64 *) ((UINTN) MailboxLocationPointer + DebugAgentContext->HeapMigrateOffset);
     454    } else {
     455      //
     456      // DebugAgentContext is NULL. Then, Mailbox can directly be copied into memory.
     457      // Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer
     458      //
     459      Status = PeiServicesAllocatePages (
     460                 EfiACPIMemoryNVS,
     461                 EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),
     462                 &Address
     463                 );
     464      if (EFI_ERROR (Status)) {
     465        DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to allocate pages!\n"));
     466        CpuDeadLoop ();
     467      }
     468      NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
     469      //
     470      // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
     471      // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
     472      // reallocates the HOB.
     473      //
     474      CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
     475      CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));
     476      UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));
     477      MailboxLocation = (UINT64)(UINTN)NewMailbox;
     478      //
     479      // Build mailbox location in HOB
     480      //
     481      MailboxLocationPointer = BuildGuidDataHob (
     482                                 &gEfiDebugAgentGuid,
     483                                 &MailboxLocation,
     484                                 sizeof (UINT64)
     485                                 );
     486    }
     487    //
     488    // Update IDT entry to save the location saved mailbox pointer
     489    //
     490    SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
    252491    break;
    253492
     493  case DEBUG_AGENT_INIT_PEI:
     494    if (Context == NULL) {
     495      DEBUG ((EFI_D_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
     496      CpuDeadLoop ();
     497    }
     498    //
     499    // Check if Debug Agent has initialized before
     500    //
     501    if (IsDebugAgentInitialzed()) {
     502      DEBUG ((EFI_D_WARN, "Debug Agent: It has already initialized in SEC Core!\n"));
     503      break;
     504    }
     505    //
     506    // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
     507    //
     508    Status = PeiServicesInstallPpi (&mVectorHandoffInfoPpiList[0]);
     509    if (EFI_ERROR (Status)) {
     510      DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
     511      CpuDeadLoop ();
     512    }
     513    //
     514    // Set up IDT entries
     515    //
     516    InitializeDebugIdt ();
     517    //
     518    // Build mailbox in HOB and setup Mailbox Set In Pei flag
     519    //
     520    Mailbox = AllocateZeroPool (sizeof (DEBUG_AGENT_MAILBOX));
     521    MailboxLocation = (UINT64)(UINTN)Mailbox;
     522    MailboxLocationPointer = BuildGuidDataHob (
     523                               &gEfiDebugAgentGuid,
     524                               &MailboxLocation,
     525                               sizeof (UINT64)
     526                               );
     527
     528    InitializeDebugTimer ();
     529    //
     530    // Update IDT entry to save the location pointer saved mailbox pointer
     531    //
     532    SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
     533    //
     534    // Save init arch type when debug agent initialized
     535    //
     536    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
     537    //
     538    // Register for a callback once memory has been initialized.
     539    // If memery has been ready, the callback funtion will be invoked immediately
     540    //
     541    Status = PeiServicesNotifyPpi (&mMemoryDiscoveredNotifyList[0]);
     542    if (EFI_ERROR (Status)) {
     543      DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to register memory discovered callback function!\n"));
     544      CpuDeadLoop ();
     545    }
     546    //
     547    // Set HOB check flag if memory has not been ready yet
     548    //
     549    if (GetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY) == 0) {
     550      SetDebugFlag (DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB, 1);
     551    }
     552
     553    Phase2Context.InitFlag = InitFlag;
     554    Phase2Context.Context  = Context;
     555    Phase2Context.Function = Function;
     556    DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);
     557
     558    FindAndReportModuleImageInfo (4);
     559
     560    break;
     561
     562  case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:
     563    if (Context == NULL) {
     564      DEBUG ((EFI_D_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
     565      CpuDeadLoop ();
     566    } else {
     567      Ia32Idtr =  (IA32_DESCRIPTOR *) Context;
     568      Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
     569      MailboxLocationPointer = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
     570                                                (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
     571      Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer);
     572      //
     573      // Mailbox should valid and setup before executing thunk code
     574      //
     575      VerifyMailboxChecksum (Mailbox);
     576
     577      DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)Mailbox->DebugPortHandle, NULL);
     578      UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
     579      //
     580      // Set up IDT entries
     581      //
     582      InitializeDebugIdt ();
     583      //
     584      // Update IDT entry to save location pointer saved the mailbox pointer
     585      //
     586      SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
     587
     588      FindAndReportModuleImageInfo (4);
     589    }
     590    break;
     591
    254592  default:
    255 
    256     //
    257     // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
     593    //
     594    // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
    258595    // Debug Agent library instance.
    259596    //
     
    261598    CpuDeadLoop ();
    262599    break;
    263 
    264   }
     600  }
     601
     602  //
     603  // Enable CPU interrupts so debug timer interrupts can be delivered
     604  //
     605  EnableInterrupts ();
    265606
    266607  //
     
    269610  if (Function != NULL) {
    270611    Function (Context);
     612  }
     613  //
     614  // Set return status for DEBUG_AGENT_INIT_PEI
     615  //
     616  if (InitFlag == DEBUG_AGENT_INIT_PEI && Context != NULL) {
     617    *(EFI_STATUS *)Context = EFI_SUCCESS;
    271618  }
    272619}
     
    289636{
    290637  DEBUG_AGENT_PHASE2_CONTEXT *Phase2Context;
     638  UINT64                     *MailboxLocation;
    291639  DEBUG_AGENT_MAILBOX        *Mailbox;
    292640  EFI_SEC_PEI_HAND_OFF       *SecCoreData;
    293 
    294   Mailbox = GetMailboxPointerInIdtEntry ();
    295   Mailbox->DebugPortHandle = (UINT64) (UINTN)DebugPortHandle;
     641  UINT16                     BufferSize;
     642  UINT64                     NewDebugPortHandle;
     643
     644  Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *) Context;
     645  MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry ();
     646  Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
     647  BufferSize = PcdGet16(PcdDebugPortHandleBufferSize);
     648  if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI) {
     649    NewDebugPortHandle = (UINT64)(UINTN)AllocateCopyPool (BufferSize, DebugPortHandle);
     650  } else {
     651    NewDebugPortHandle = (UINT64)(UINTN)DebugPortHandle;
     652  }
     653  UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, NewDebugPortHandle);
    296654
    297655  //
     
    300658  TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);
    301659
    302   //
    303   // If Temporary RAM region is below 128 MB, then send message to
    304   // host to disable low memory filtering.
    305   //
    306   Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *) Context;
    307   SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;
    308   if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB && IsHostConnected ()) {
    309     TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
    310   }
    311 
    312   //
    313   // Enable CPU interrupts so debug timer interrupts can be delivered
    314   //
    315   EnableInterrupts ();
    316 
    317   //
    318   // Call continuation function if it is not NULL.
    319   //
    320   if (Phase2Context->Function != NULL) {
     660  if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PREMEM_SEC) {
     661    //
     662    // If Temporary RAM region is below 128 MB, then send message to
     663    // host to disable low memory filtering.
     664    //
     665    SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;
     666    if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB && IsHostAttached ()) {
     667      SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
     668      TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
     669    }
     670    //
     671    // Enable CPU interrupts so debug timer interrupts can be delivered
     672    //
     673    EnableInterrupts ();
     674    //
     675    // Call continuation function if it is not NULL.
     676    //
    321677    Phase2Context->Function (Phase2Context->Context);
    322678  }
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