VirtualBox

Ignore:
Timestamp:
Apr 14, 2023 3:17:44 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156854
Message:

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
4 edited

Legend:

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

  • trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.nasm

    • Property svn:mime-type set to text/x-asm
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c

    r80721 r99404  
    55  control is passed to OS waking up handler.
    66
    7   Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
     7  Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>
    88  Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
    99
     
    5959typedef union {
    6060  struct {
    61     UINT32  LimitLow    : 16;
    62     UINT32  BaseLow     : 16;
    63     UINT32  BaseMid     : 8;
    64     UINT32  Type        : 4;
    65     UINT32  System      : 1;
    66     UINT32  Dpl         : 2;
    67     UINT32  Present     : 1;
    68     UINT32  LimitHigh   : 4;
    69     UINT32  Software    : 1;
    70     UINT32  Reserved    : 1;
    71     UINT32  DefaultSize : 1;
    72     UINT32  Granularity : 1;
    73     UINT32  BaseHigh    : 8;
     61    UINT32    LimitLow    : 16;
     62    UINT32    BaseLow     : 16;
     63    UINT32    BaseMid     : 8;
     64    UINT32    Type        : 4;
     65    UINT32    System      : 1;
     66    UINT32    Dpl         : 2;
     67    UINT32    Present     : 1;
     68    UINT32    LimitHigh   : 4;
     69    UINT32    Software    : 1;
     70    UINT32    Reserved    : 1;
     71    UINT32    DefaultSize : 1;
     72    UINT32    Granularity : 1;
     73    UINT32    BaseHigh    : 8;
    7474  } Bits;
    75   UINT64  Uint64;
     75  UINT64    Uint64;
    7676} IA32_GDT;
    7777
     
    8282typedef union {
    8383  struct {
    84     UINT64  Present:1;                // 0 = Not present in memory, 1 = Present in memory
    85     UINT64  ReadWrite:1;              // 0 = Read-Only, 1= Read/Write
    86     UINT64  UserSupervisor:1;         // 0 = Supervisor, 1=User
    87     UINT64  WriteThrough:1;           // 0 = Write-Back caching, 1=Write-Through caching
    88     UINT64  CacheDisabled:1;          // 0 = Cached, 1=Non-Cached
    89     UINT64  Accessed:1;               // 0 = Not accessed, 1 = Accessed (set by CPU)
    90     UINT64  Reserved:1;               // Reserved
    91     UINT64  MustBeZero:2;             // Must Be Zero
    92     UINT64  Available:3;              // Available for use by system software
    93     UINT64  PageTableBaseAddress:40; // Page Table Base Address
    94     UINT64  AvabilableHigh:11;        // Available for use by system software
    95     UINT64  Nx:1;                     // No Execute bit
     84    UINT64    Present              : 1;  // 0 = Not present in memory, 1 = Present in memory
     85    UINT64    ReadWrite            : 1;  // 0 = Read-Only, 1= Read/Write
     86    UINT64    UserSupervisor       : 1;  // 0 = Supervisor, 1=User
     87    UINT64    WriteThrough         : 1;  // 0 = Write-Back caching, 1=Write-Through caching
     88    UINT64    CacheDisabled        : 1;  // 0 = Cached, 1=Non-Cached
     89    UINT64    Accessed             : 1;  // 0 = Not accessed, 1 = Accessed (set by CPU)
     90    UINT64    Reserved             : 1;  // Reserved
     91    UINT64    MustBeZero           : 2;  // Must Be Zero
     92    UINT64    Available            : 3;  // Available for use by system software
     93    UINT64    PageTableBaseAddress : 40; // Page Table Base Address
     94    UINT64    AvabilableHigh       : 11; // Available for use by system software
     95    UINT64    Nx                   : 1;  // No Execute bit
    9696  } Bits;
    9797  UINT64    Uint64;
     
    103103typedef union {
    104104  struct {
    105     UINT64  Present:1;                // 0 = Not present in memory, 1 = Present in memory
    106     UINT64  ReadWrite:1;              // 0 = Read-Only, 1= Read/Write
    107     UINT64  UserSupervisor:1;         // 0 = Supervisor, 1=User
    108     UINT64  WriteThrough:1;           // 0 = Write-Back caching, 1=Write-Through caching
    109     UINT64  CacheDisabled:1;          // 0 = Cached, 1=Non-Cached
    110     UINT64  Accessed:1;               // 0 = Not accessed, 1 = Accessed (set by CPU)
    111     UINT64  Dirty:1;                  // 0 = Not Dirty, 1 = written by processor on access to page
    112     UINT64  MustBe1:1;                // Must be 1
    113     UINT64  Global:1;                 // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
    114     UINT64  Available:3;              // Available for use by system software
    115     UINT64  PAT:1;                    //
    116     UINT64  MustBeZero:8;             // Must be zero;
    117     UINT64  PageTableBaseAddress:31; // Page Table Base Address
    118     UINT64  AvabilableHigh:11;        // Available for use by system software
    119     UINT64  Nx:1;                     // 0 = Execute Code, 1 = No Code Execution
     105    UINT64    Present              : 1;  // 0 = Not present in memory, 1 = Present in memory
     106    UINT64    ReadWrite            : 1;  // 0 = Read-Only, 1= Read/Write
     107    UINT64    UserSupervisor       : 1;  // 0 = Supervisor, 1=User
     108    UINT64    WriteThrough         : 1;  // 0 = Write-Back caching, 1=Write-Through caching
     109    UINT64    CacheDisabled        : 1;  // 0 = Cached, 1=Non-Cached
     110    UINT64    Accessed             : 1;  // 0 = Not accessed, 1 = Accessed (set by CPU)
     111    UINT64    Dirty                : 1;  // 0 = Not Dirty, 1 = written by processor on access to page
     112    UINT64    MustBe1              : 1;  // Must be 1
     113    UINT64    Global               : 1;  // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
     114    UINT64    Available            : 3;  // Available for use by system software
     115    UINT64    PAT                  : 1;  //
     116    UINT64    MustBeZero           : 8;  // Must be zero;
     117    UINT64    PageTableBaseAddress : 31; // Page Table Base Address
     118    UINT64    AvabilableHigh       : 11; // Available for use by system software
     119    UINT64    Nx                   : 1;  // 0 = Execute Code, 1 = No Code Execution
    120120  } Bits;
    121121  UINT64    Uint64;
     
    127127typedef union {
    128128  struct {
    129     UINT64  Present:1;                // 0 = Not present in memory, 1 = Present in memory
    130     UINT64  ReadWrite:1;              // 0 = Read-Only, 1= Read/Write
    131     UINT64  UserSupervisor:1;         // 0 = Supervisor, 1=User
    132     UINT64  WriteThrough:1;           // 0 = Write-Back caching, 1=Write-Through caching
    133     UINT64  CacheDisabled:1;          // 0 = Cached, 1=Non-Cached
    134     UINT64  Accessed:1;               // 0 = Not accessed, 1 = Accessed (set by CPU)
    135     UINT64  Dirty:1;                  // 0 = Not Dirty, 1 = written by processor on access to page
    136     UINT64  MustBe1:1;                // Must be 1
    137     UINT64  Global:1;                 // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
    138     UINT64  Available:3;              // Available for use by system software
    139     UINT64  PAT:1;                    //
    140     UINT64  MustBeZero:17;            // Must be zero;
    141     UINT64  PageTableBaseAddress:22; // Page Table Base Address
    142     UINT64  AvabilableHigh:11;        // Available for use by system software
    143     UINT64  Nx:1;                     // 0 = Execute Code, 1 = No Code Execution
     129    UINT64    Present              : 1;  // 0 = Not present in memory, 1 = Present in memory
     130    UINT64    ReadWrite            : 1;  // 0 = Read-Only, 1= Read/Write
     131    UINT64    UserSupervisor       : 1;  // 0 = Supervisor, 1=User
     132    UINT64    WriteThrough         : 1;  // 0 = Write-Back caching, 1=Write-Through caching
     133    UINT64    CacheDisabled        : 1;  // 0 = Cached, 1=Non-Cached
     134    UINT64    Accessed             : 1;  // 0 = Not accessed, 1 = Accessed (set by CPU)
     135    UINT64    Dirty                : 1;  // 0 = Not Dirty, 1 = written by processor on access to page
     136    UINT64    MustBe1              : 1;  // Must be 1
     137    UINT64    Global               : 1;  // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
     138    UINT64    Available            : 3;  // Available for use by system software
     139    UINT64    PAT                  : 1;  //
     140    UINT64    MustBeZero           : 17; // Must be zero;
     141    UINT64    PageTableBaseAddress : 22; // Page Table Base Address
     142    UINT64    AvabilableHigh       : 11; // Available for use by system software
     143    UINT64    Nx                   : 1;  // 0 = Execute Code, 1 = No Code Execution
    144144  } Bits;
    145145  UINT64    Uint64;
     
    151151//
    152152typedef struct {
    153   EFI_GUID  HeaderGuid;
    154   UINT32    MessageLength;
    155   UINT8     Data[1];
     153  EFI_GUID    HeaderGuid;
     154  UINT32      MessageLength;
     155  UINT8       Data[1];
    156156} SMM_COMMUNICATE_HEADER_32;
    157157
    158158typedef struct {
    159   EFI_GUID  HeaderGuid;
    160   UINT64    MessageLength;
    161   UINT8     Data[1];
     159  EFI_GUID    HeaderGuid;
     160  UINT64      MessageLength;
     161  UINT8       Data[1];
    162162} SMM_COMMUNICATE_HEADER_64;
    163163
     
    167167// Function prototypes
    168168//
     169
    169170/**
    170171  a ASM function to transfer control to OS.
     
    175176typedef
    176177VOID
    177 (EFIAPI *ASM_TRANSFER_CONTROL) (
     178(EFIAPI *ASM_TRANSFER_CONTROL)(
    178179  IN   UINT32           S3WakingVector,
    179180  IN   UINT32           AcpiLowMemoryBase
     
    226227EFIAPI
    227228AsmSetDataSelectors (
    228   IN UINT16   SelectorValue
     229  IN UINT16  SelectorValue
    229230  );
    230231
     
    232233// Globals
    233234//
    234 EFI_PEI_S3_RESUME2_PPI      mS3ResumePpi = { S3RestoreConfig2 };
    235 
    236 EFI_PEI_PPI_DESCRIPTOR mPpiList = {
     235EFI_PEI_S3_RESUME2_PPI  mS3ResumePpi = { S3RestoreConfig2 };
     236
     237EFI_PEI_PPI_DESCRIPTOR  mPpiList = {
    237238  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    238239  &gEfiPeiS3Resume2PpiGuid,
     
    240241};
    241242
    242 EFI_PEI_PPI_DESCRIPTOR mPpiListPostScriptTable = {
     243EFI_PEI_PPI_DESCRIPTOR  mPpiListPostScriptTable = {
    243244  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    244245  &gPeiPostScriptTablePpiGuid,
     
    246247};
    247248
    248 EFI_PEI_PPI_DESCRIPTOR mPpiListEndOfPeiTable = {
     249EFI_PEI_PPI_DESCRIPTOR  mPpiListEndOfPeiTable = {
    249250  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    250251  &gEfiEndOfPeiSignalPpiGuid,
     
    252253};
    253254
    254 EFI_PEI_PPI_DESCRIPTOR mPpiListS3SmmInitDoneTable = {
     255EFI_PEI_PPI_DESCRIPTOR  mPpiListS3SmmInitDoneTable = {
    255256  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
    256257  &gEdkiiS3SmmInitDoneGuid,
     
    261262// Global Descriptor Table (GDT)
    262263//
    263 GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = {
    264 /* selector { Global Segment Descriptor                              } */
    265 /* 0x00 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}},
    266 /* 0x08 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}},
    267 /* 0x10 */  {{0xFFFF, 0,  0,  0xB,  1,  0,  1,  0xF,  0,  0, 1,  1,  0}},
    268 /* 0x18 */  {{0xFFFF, 0,  0,  0x3,  1,  0,  1,  0xF,  0,  0, 1,  1,  0}},
    269 /* 0x20 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}},
    270 /* 0x28 */  {{0xFFFF, 0,  0,  0xB,  1,  0,  1,  0xF,  0,  0, 0,  1,  0}},
    271 /* 0x30 */  {{0xFFFF, 0,  0,  0x3,  1,  0,  1,  0xF,  0,  0, 0,  1,  0}},
    272 /* 0x38 */  {{0xFFFF, 0,  0,  0xB,  1,  0,  1,  0xF,  0,  1, 0,  1,  0}},
    273 /* 0x40 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}},
     264GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT  mGdtEntries[] = {
     265  /* selector { Global Segment Descriptor                              } */
     266  /* 0x00 */ {
     267    { 0,      0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0, 0 }
     268  },
     269  /* 0x08 */ {
     270    { 0,      0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0, 0 }
     271  },
     272  /* 0x10 */ {
     273    { 0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 0, 1, 1, 0 }
     274  },
     275  /* 0x18 */ {
     276    { 0xFFFF, 0, 0, 0x3, 1, 0, 1, 0xF, 0, 0, 1, 1, 0 }
     277  },
     278  /* 0x20 */ {
     279    { 0,      0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0, 0 }
     280  },
     281  /* 0x28 */ {
     282    { 0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 0, 0, 1, 0 }
     283  },
     284  /* 0x30 */ {
     285    { 0xFFFF, 0, 0, 0x3, 1, 0, 1, 0xF, 0, 0, 0, 1, 0 }
     286  },
     287  /* 0x38 */ {
     288    { 0xFFFF, 0, 0, 0xB, 1, 0, 1, 0xF, 0, 1, 0, 1, 0 }
     289  },
     290  /* 0x40 */ {
     291    { 0,      0, 0, 0,   0, 0, 0, 0,   0, 0, 0, 0, 0 }
     292  },
    274293};
    275294
    276 #define DATA_SEGEMENT_SELECTOR        0x18
     295#define DATA_SEGEMENT_SELECTOR  0x18
    277296
    278297//
    279298// IA32 Gdt register
    280299//
    281 GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR mGdt = {
     300GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR  mGdt = {
    282301  sizeof (mGdtEntries) - 1,
    283   (UINTN) mGdtEntries
    284   };
    285 
     302  (UINTN)mGdtEntries
     303};
    286304
    287305/**
     
    295313BOOLEAN
    296314IsLongModeWakingVector (
    297   IN ACPI_S3_CONTEXT                *AcpiS3Context
     315  IN ACPI_S3_CONTEXT  *AcpiS3Context
    298316  )
    299317{
    300318  EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE  *Facs;
    301319
    302   Facs = (EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) ((UINTN) (AcpiS3Context->AcpiFacsTable));
     320  Facs = (EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)((UINTN)(AcpiS3Context->AcpiFacsTable));
    303321  if ((Facs == NULL) ||
    304322      (Facs->Signature != EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
    305       ((Facs->FirmwareWakingVector == 0) && (Facs->XFirmwareWakingVector == 0)) ) {
     323      ((Facs->FirmwareWakingVector == 0) && (Facs->XFirmwareWakingVector == 0)))
     324  {
    306325    // Something wrong with FACS
    307326    return FALSE;
    308327  }
     328
    309329  if (Facs->XFirmwareWakingVector != 0) {
    310330    if ((Facs->Version == EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION) &&
    311331        ((Facs->Flags & EFI_ACPI_4_0_64BIT_WAKE_SUPPORTED_F) != 0) &&
    312         ((Facs->OspmFlags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0)) {
     332        ((Facs->OspmFlags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0))
     333    {
    313334      // Both BIOS and OS wants 64bit vector
    314       if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
    315         return TRUE;
    316       }
    317     }
    318   }
     335      ASSERT ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UINTN) == sizeof (UINT64)));
     336      return TRUE;
     337    }
     338  }
     339
    319340  return FALSE;
    320341}
     
    328349VOID
    329350SignalToSmmByCommunication (
    330   IN EFI_GUID   *HandlerType
     351  IN EFI_GUID  *HandlerType
    331352  )
    332353{
    333   EFI_STATUS                         Status;
    334   EFI_PEI_SMM_COMMUNICATION_PPI      *SmmCommunicationPpi;
    335   UINTN                              CommSize;
    336   SMM_COMMUNICATE_HEADER_32          Header32;
    337   SMM_COMMUNICATE_HEADER_64          Header64;
    338   VOID                               *CommBuffer;
     354  EFI_STATUS                     Status;
     355  EFI_PEI_SMM_COMMUNICATION_PPI  *SmmCommunicationPpi;
     356  UINTN                          CommSize;
     357  SMM_COMMUNICATE_HEADER_32      Header32;
     358  SMM_COMMUNICATE_HEADER_64      Header64;
     359  VOID                           *CommBuffer;
    339360
    340361  DEBUG ((DEBUG_INFO, "Signal %g to SMM - Enter\n", HandlerType));
     
    346367  // or (FeaturePcdGet (PcdDxeIplSwitchToLongMode)), DXE will switch to 64 bits.
    347368  //
    348   if ((sizeof(UINTN) == sizeof(UINT64)) || (FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
    349     CommBuffer = &Header64;
     369  if ((sizeof (UINTN) == sizeof (UINT64)) || (FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
     370    CommBuffer             = &Header64;
    350371    Header64.MessageLength = 0;
    351     CommSize = OFFSET_OF (SMM_COMMUNICATE_HEADER_64, Data);
     372    CommSize               = OFFSET_OF (SMM_COMMUNICATE_HEADER_64, Data);
    352373  } else {
    353     CommBuffer = &Header32;
     374    CommBuffer             = &Header32;
    354375    Header32.MessageLength = 0;
    355     CommSize = OFFSET_OF (SMM_COMMUNICATE_HEADER_32, Data);
    356   }
     376    CommSize               = OFFSET_OF (SMM_COMMUNICATE_HEADER_32, Data);
     377  }
     378
    357379  CopyGuid (CommBuffer, HandlerType);
    358380
     
    391413EFIAPI
    392414S3ResumeBootOs (
    393   IN ACPI_S3_CONTEXT                *AcpiS3Context,
    394   IN PEI_S3_RESUME_STATE            *PeiS3ResumeState
     415  IN ACPI_S3_CONTEXT      *AcpiS3Context,
     416  IN PEI_S3_RESUME_STATE  *PeiS3ResumeState
    395417  )
    396418{
     
    437459  // Get ACPI Table Address
    438460  //
    439   Facs = (EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) ((UINTN) (AcpiS3Context->AcpiFacsTable));
     461  Facs = (EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)((UINTN)(AcpiS3Context->AcpiFacsTable));
    440462
    441463  if ((Facs == NULL) ||
    442464      (Facs->Signature != EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
    443       ((Facs->FirmwareWakingVector == 0) && (Facs->XFirmwareWakingVector == 0)) ) {
     465      ((Facs->FirmwareWakingVector == 0) && (Facs->XFirmwareWakingVector == 0)))
     466  {
    444467    //
    445468    // Report Status code that no valid vector is found
     
    450473      );
    451474    CpuDeadLoop ();
    452     return ;
     475    return;
    453476  }
    454477
     
    456479  // Install EndOfPeiPpi
    457480  //
    458   PERF_INMODULE_BEGIN("EndOfPeiPpi");
     481  PERF_INMODULE_BEGIN ("EndOfPeiPpi");
    459482
    460483  Status = PeiServicesInstallPpi (&mPpiListEndOfPeiTable);
    461484  ASSERT_EFI_ERROR (Status);
    462485
    463   PERF_INMODULE_END("EndOfPeiPpi");
    464 
    465   PERF_INMODULE_BEGIN("EndOfS3Resume");
     486  PERF_INMODULE_END ("EndOfPeiPpi");
     487
     488  PERF_INMODULE_BEGIN ("EndOfS3Resume");
    466489
    467490  DEBUG ((DEBUG_INFO, "Signal EndOfS3Resume\n"));
     
    483506    // Switch to native waking vector
    484507    //
    485     TempStackTop = (UINTN)&TempStack + sizeof(TempStack);
     508    TempStackTop = (UINTN)&TempStack + sizeof (TempStack);
    486509    DEBUG ((
    487510      DEBUG_INFO,
     
    493516    if ((Facs->Version == EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION) &&
    494517        ((Facs->Flags & EFI_ACPI_4_0_64BIT_WAKE_SUPPORTED_F) != 0) &&
    495         ((Facs->OspmFlags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0)) {
     518        ((Facs->OspmFlags & EFI_ACPI_4_0_OSPM_64BIT_WAKE__F) != 0))
     519    {
    496520      //
    497521      // X64 long mode waking vector
    498522      //
    499       DEBUG ((DEBUG_INFO, "Transfer to 64bit OS waking vector - %x\r\n", (UINTN)Facs->XFirmwareWakingVector));
     523      DEBUG ((DEBUG_INFO, "Transfer from PEI to 64bit OS waking vector - %x\r\n", (UINTN)Facs->XFirmwareWakingVector));
    500524      if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
     525        //
     526        // 32bit PEI calls to 64bit OS S3 waking vector
     527        //
    501528        AsmEnablePaging64 (
    502529          0x38,
     
    507534          );
    508535      } else {
    509         //
    510         // Report Status code that no valid waking vector is found
    511         //
    512         REPORT_STATUS_CODE (
    513           EFI_ERROR_CODE | EFI_ERROR_MAJOR,
    514           (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_OS_WAKE_ERROR)
    515           );
    516         DEBUG (( EFI_D_ERROR, "Unsupported for 32bit DXE transfer to 64bit OS waking vector!\r\n"));
    517         ASSERT (FALSE);
    518         CpuDeadLoop ();
    519         return ;
     536        if (sizeof (UINTN) == sizeof (UINT64)) {
     537          //
     538          // 64bit PEI calls to 64bit OS S3 waking vector
     539          //
     540          SwitchStack (
     541            (SWITCH_STACK_ENTRY_POINT)(UINTN)Facs->XFirmwareWakingVector,
     542            NULL,
     543            NULL,
     544            (VOID *)(UINTN)TempStackTop
     545            );
     546        } else {
     547          //
     548          // Report Status code that no valid waking vector is found.
     549          // Note: 32bit PEI + 32bit DXE firmware calling to 64bit OS S3 waking vector is an invalid configuration.
     550          //
     551          REPORT_STATUS_CODE (
     552            EFI_ERROR_CODE | EFI_ERROR_MAJOR,
     553            (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_OS_WAKE_ERROR)
     554            );
     555          DEBUG ((DEBUG_ERROR, "Unsupported for 32bit DXE transfer to 64bit OS waking vector!\r\n"));
     556          ASSERT (FALSE);
     557          CpuDeadLoop ();
     558          return;
     559        }
    520560      }
    521561    } else {
     
    524564      //
    525565      DEBUG ((DEBUG_INFO, "Transfer to 32bit OS waking vector - %x\r\n", (UINTN)Facs->XFirmwareWakingVector));
    526       SwitchStack (
    527         (SWITCH_STACK_ENTRY_POINT) (UINTN) Facs->XFirmwareWakingVector,
    528         NULL,
    529         NULL,
    530         (VOID *)(UINTN)TempStackTop
    531         );
     566      if (sizeof (UINTN) == sizeof (UINT64)) {
     567        //
     568        // 64bit PEI calls to 32bit OS S3 waking vector
     569        //
     570        AsmDisablePaging64 (
     571          0x10,
     572          (UINT32)Facs->XFirmwareWakingVector,
     573          0,
     574          0,
     575          (UINT32)TempStackTop
     576          );
     577      } else {
     578        //
     579        // 32bit PEI calls to 32bit OS S3 waking vector
     580        //
     581        SwitchStack (
     582          (SWITCH_STACK_ENTRY_POINT)(UINTN)Facs->XFirmwareWakingVector,
     583          NULL,
     584          NULL,
     585          (VOID *)(UINTN)TempStackTop
     586          );
     587      }
    532588    }
    533589  } else {
     
    550606  // Never run to here
    551607  //
    552   CpuDeadLoop();
     608  CpuDeadLoop ();
    553609}
    554610
    555611/**
    556612  Restore S3 page table because we do not trust ACPINvs content.
    557   If BootScriptExector driver will not run in 64-bit mode, this function will do nothing.
     613  If BootScriptExecutor driver will not run in 64-bit mode, this function will do nothing.
    558614
    559615  @param S3NvsPageTableAddress   PageTableAddress in ACPINvs
     
    562618VOID
    563619RestoreS3PageTables (
    564   IN UINTN                                         S3NvsPageTableAddress,
    565   IN BOOLEAN                                       Build4GPageTableOnly
     620  IN UINTN    S3NvsPageTableAddress,
     621  IN BOOLEAN  Build4GPageTableOnly
    566622  )
    567623{
    568   if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
    569     UINT32                                        RegEax;
    570     UINT32                                        RegEdx;
    571     UINT8                                         PhysicalAddressBits;
    572     EFI_PHYSICAL_ADDRESS                          PageAddress;
    573     UINTN                                         IndexOfPml4Entries;
    574     UINTN                                         IndexOfPdpEntries;
    575     UINTN                                         IndexOfPageDirectoryEntries;
    576     UINT32                                        NumberOfPml4EntriesNeeded;
    577     UINT32                                        NumberOfPdpEntriesNeeded;
    578     PAGE_MAP_AND_DIRECTORY_POINTER                *PageMapLevel4Entry;
    579     PAGE_MAP_AND_DIRECTORY_POINTER                *PageMap;
    580     PAGE_MAP_AND_DIRECTORY_POINTER                *PageDirectoryPointerEntry;
    581     PAGE_TABLE_ENTRY                              *PageDirectoryEntry;
    582     VOID                                          *Hob;
    583     BOOLEAN                                       Page1GSupport;
    584     PAGE_TABLE_1G_ENTRY                           *PageDirectory1GEntry;
    585     UINT64                                        AddressEncMask;
     624  if ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UINTN) == sizeof (UINT64))) {
     625    UINT32                          RegEax;
     626    UINT32                          RegEdx;
     627    UINT8                           PhysicalAddressBits;
     628    EFI_PHYSICAL_ADDRESS            PageAddress;
     629    UINTN                           IndexOfPml4Entries;
     630    UINTN                           IndexOfPdpEntries;
     631    UINTN                           IndexOfPageDirectoryEntries;
     632    UINT32                          NumberOfPml4EntriesNeeded;
     633    UINT32                          NumberOfPdpEntriesNeeded;
     634    PAGE_MAP_AND_DIRECTORY_POINTER  *PageMapLevel4Entry;
     635    PAGE_MAP_AND_DIRECTORY_POINTER  *PageMap;
     636    PAGE_MAP_AND_DIRECTORY_POINTER  *PageDirectoryPointerEntry;
     637    PAGE_TABLE_ENTRY                *PageDirectoryEntry;
     638    VOID                            *Hob;
     639    BOOLEAN                         Page1GSupport;
     640    PAGE_TABLE_1G_ENTRY             *PageDirectory1GEntry;
     641    UINT64                          AddressEncMask;
    586642
    587643    //
     
    601657    // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.
    602658    //
    603     PageMap = (PAGE_MAP_AND_DIRECTORY_POINTER *)S3NvsPageTableAddress;
     659    PageMap                = (PAGE_MAP_AND_DIRECTORY_POINTER *)S3NvsPageTableAddress;
    604660    S3NvsPageTableAddress += SIZE_4KB;
    605661
    606662    Page1GSupport = FALSE;
    607     if (PcdGetBool(PcdUse1GPageTable)) {
     663    if (PcdGetBool (PcdUse1GPageTable)) {
    608664      AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
    609665      if (RegEax >= 0x80000001) {
     
    620676    Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
    621677    if (Hob != NULL) {
    622       PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
     678      PhysicalAddressBits = ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;
    623679    } else {
    624680      AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
    625681      if (RegEax >= 0x80000008) {
    626682        AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
    627         PhysicalAddressBits = (UINT8) RegEax;
     683        PhysicalAddressBits = (UINT8)RegEax;
    628684      } else {
    629685        PhysicalAddressBits = 36;
     
    645701    if (Build4GPageTableOnly) {
    646702      PhysicalAddressBits = 32;
    647       ZeroMem (PageMap, EFI_PAGES_TO_SIZE(2));
    648     }
     703      ZeroMem (PageMap, EFI_PAGES_TO_SIZE (2));
     704    }
     705
    649706    //
    650707    // Calculate the table entries needed.
     
    652709    if (PhysicalAddressBits <= 39) {
    653710      NumberOfPml4EntriesNeeded = 1;
    654       NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));
     711      NumberOfPdpEntriesNeeded  = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));
    655712    } else {
    656713      NumberOfPml4EntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 39));
    657       NumberOfPdpEntriesNeeded = 512;
     714      NumberOfPdpEntriesNeeded  = 512;
    658715    }
    659716
     
    666723      //
    667724      PageDirectoryPointerEntry = (PAGE_MAP_AND_DIRECTORY_POINTER *)S3NvsPageTableAddress;
    668       S3NvsPageTableAddress += SIZE_4KB;
     725      S3NvsPageTableAddress    += SIZE_4KB;
    669726
    670727      //
    671728      // Make a PML4 Entry
    672729      //
    673       PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry | AddressEncMask;
     730      PageMapLevel4Entry->Uint64         = (UINT64)(UINTN)PageDirectoryPointerEntry | AddressEncMask;
    674731      PageMapLevel4Entry->Bits.ReadWrite = 1;
    675       PageMapLevel4Entry->Bits.Present = 1;
     732      PageMapLevel4Entry->Bits.Present   = 1;
    676733
    677734      if (Page1GSupport) {
    678         PageDirectory1GEntry = (VOID *) PageDirectoryPointerEntry;
     735        PageDirectory1GEntry = (VOID *)PageDirectoryPointerEntry;
    679736
    680737        for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress += SIZE_1GB) {
     
    682739          // Fill in the Page Directory entries
    683740          //
    684           PageDirectory1GEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;
     741          PageDirectory1GEntry->Uint64         = (UINT64)PageAddress | AddressEncMask;
    685742          PageDirectory1GEntry->Bits.ReadWrite = 1;
    686           PageDirectory1GEntry->Bits.Present = 1;
    687           PageDirectory1GEntry->Bits.MustBe1 = 1;
     743          PageDirectory1GEntry->Bits.Present   = 1;
     744          PageDirectory1GEntry->Bits.MustBe1   = 1;
    688745        }
    689746      } else {
     
    693750          // So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.
    694751          //
    695           PageDirectoryEntry = (PAGE_TABLE_ENTRY *)S3NvsPageTableAddress;
     752          PageDirectoryEntry     = (PAGE_TABLE_ENTRY *)S3NvsPageTableAddress;
    696753          S3NvsPageTableAddress += SIZE_4KB;
    697754
     
    699756          // Fill in a Page Directory Pointer Entries
    700757          //
    701           PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask;
     758          PageDirectoryPointerEntry->Uint64         = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask;
    702759          PageDirectoryPointerEntry->Bits.ReadWrite = 1;
    703           PageDirectoryPointerEntry->Bits.Present = 1;
     760          PageDirectoryPointerEntry->Bits.Present   = 1;
    704761
    705762          for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress += SIZE_2MB) {
     
    707764            // Fill in the Page Directory entries
    708765            //
    709             PageDirectoryEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;
     766            PageDirectoryEntry->Uint64         = (UINT64)PageAddress | AddressEncMask;
    710767            PageDirectoryEntry->Bits.ReadWrite = 1;
    711             PageDirectoryEntry->Bits.Present = 1;
    712             PageDirectoryEntry->Bits.MustBe1 = 1;
     768            PageDirectoryEntry->Bits.Present   = 1;
     769            PageDirectoryEntry->Bits.MustBe1   = 1;
    713770          }
    714771        }
    715772      }
    716773    }
    717     return ;
     774
     775    return;
    718776  } else {
    719777    //
    720778    // If DXE is running 32-bit mode, no need to establish page table.
    721779    //
    722     return ;
     780    return;
    723781  }
    724782}
     
    740798  )
    741799{
    742   EFI_STATUS                 Status;
    743   PEI_SMM_ACCESS_PPI         *SmmAccess;
    744   UINTN                      Index;
    745   VOID                       *GuidHob;
    746   PEI_S3_RESUME_STATE        *PeiS3ResumeState;
    747   BOOLEAN                    InterruptStatus;
     800  EFI_STATUS           Status;
     801  PEI_SMM_ACCESS_PPI   *SmmAccess;
     802  UINTN                Index;
     803  VOID                 *GuidHob;
     804  PEI_S3_RESUME_STATE  *PeiS3ResumeState;
     805  BOOLEAN              InterruptStatus;
    748806
    749807  DEBUG ((DEBUG_INFO, "S3ResumeExecuteBootScript()\n"));
     
    768826
    769827    Status = PeiServicesLocatePpi (
    770                               &gPeiSmmAccessPpiGuid,
    771                               0,
    772                               NULL,
    773                               (VOID **) &SmmAccess
    774                               );
     828               &gPeiSmmAccessPpiGuid,
     829               0,
     830               NULL,
     831               (VOID **)&SmmAccess
     832               );
    775833    if (!EFI_ERROR (Status)) {
    776834      DEBUG ((DEBUG_INFO, "Close all SMRAM regions before executing boot script\n"));
     
    799857  }
    800858
    801   if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
     859  if ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UINTN) == sizeof (UINT64))) {
    802860    AsmWriteCr3 ((UINTN)AcpiS3Context->S3NvsPageTableAddress);
    803861  }
     
    820878  // Prepare data for return back
    821879  //
    822   PeiS3ResumeState = AllocatePool (sizeof(*PeiS3ResumeState));
     880  PeiS3ResumeState = AllocatePool (sizeof (*PeiS3ResumeState));
    823881  if (PeiS3ResumeState == NULL) {
    824882    REPORT_STATUS_CODE (
     
    828886    ASSERT (FALSE);
    829887  }
     888
    830889  DEBUG ((DEBUG_INFO, "PeiS3ResumeState - %x\r\n", PeiS3ResumeState));
    831890  PeiS3ResumeState->ReturnCs           = 0x10;
     
    866925    DEBUG ((DEBUG_INFO, "transfer control to Standalone Boot Script Executor\r\n"));
    867926    SwitchStack (
    868       (SWITCH_STACK_ENTRY_POINT) (UINTN) EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint,
     927      (SWITCH_STACK_ENTRY_POINT)(UINTN)EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint,
    869928      (VOID *)AcpiS3Context,
    870929      (VOID *)PeiS3ResumeState,
     
    876935  // Never run to here
    877936  //
    878   CpuDeadLoop();
     937  CpuDeadLoop ();
    879938}
     939
    880940/**
    881941  Restores the platform to its preboot configuration for an S3 resume and
     
    915975  )
    916976{
    917   EFI_STATUS                                    Status;
    918   PEI_SMM_ACCESS_PPI                            *SmmAccess;
    919   UINTN                                         Index;
    920   ACPI_S3_CONTEXT                               *AcpiS3Context;
    921   EFI_PHYSICAL_ADDRESS                          TempEfiBootScriptExecutorVariable;
    922   EFI_PHYSICAL_ADDRESS                          TempAcpiS3Context;
    923   BOOT_SCRIPT_EXECUTOR_VARIABLE                 *EfiBootScriptExecutorVariable;
    924   UINTN                                         VarSize;
    925   EFI_SMRAM_DESCRIPTOR                          *SmramDescriptor;
    926   SMM_S3_RESUME_STATE                           *SmmS3ResumeState;
    927   VOID                                          *GuidHob;
    928   BOOLEAN                                       Build4GPageTableOnly;
    929   BOOLEAN                                       InterruptStatus;
    930   IA32_CR0                                      Cr0;
    931 
    932   TempAcpiS3Context = 0;
     977  EFI_STATUS                     Status;
     978  PEI_SMM_ACCESS_PPI             *SmmAccess;
     979  UINTN                          Index;
     980  ACPI_S3_CONTEXT                *AcpiS3Context;
     981  EFI_PHYSICAL_ADDRESS           TempEfiBootScriptExecutorVariable;
     982  EFI_PHYSICAL_ADDRESS           TempAcpiS3Context;
     983  BOOT_SCRIPT_EXECUTOR_VARIABLE  *EfiBootScriptExecutorVariable;
     984  UINTN                          VarSize;
     985  EFI_SMRAM_DESCRIPTOR           *SmramDescriptor;
     986  SMM_S3_RESUME_STATE            *SmmS3ResumeState;
     987  VOID                           *GuidHob;
     988  BOOLEAN                        Build4GPageTableOnly;
     989  BOOLEAN                        InterruptStatus;
     990  IA32_CR0                       Cr0;
     991
     992  TempAcpiS3Context                 = 0;
    933993  TempEfiBootScriptExecutorVariable = 0;
    934994
     
    936996
    937997  VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
    938   Status = RestoreLockBox (
    939              &gEfiAcpiVariableGuid,
    940              &TempAcpiS3Context,
    941              &VarSize
    942              );
     998  Status  = RestoreLockBox (
     999              &gEfiAcpiVariableGuid,
     1000              &TempAcpiS3Context,
     1001              &VarSize
     1002              );
    9431003  ASSERT_EFI_ERROR (Status);
    9441004
     
    9531013  ASSERT (AcpiS3Context != NULL);
    9541014
    955   VarSize   = sizeof (EFI_PHYSICAL_ADDRESS);
    956   Status = RestoreLockBox (
    957              &gEfiBootScriptExecutorVariableGuid,
    958              &TempEfiBootScriptExecutorVariable,
    959              &VarSize
    960              );
     1015  VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
     1016  Status  = RestoreLockBox (
     1017              &gEfiBootScriptExecutorVariableGuid,
     1018              &TempEfiBootScriptExecutorVariable,
     1019              &VarSize
     1020              );
    9611021  ASSERT_EFI_ERROR (Status);
    9621022
     
    9681028  ASSERT_EFI_ERROR (Status);
    9691029
    970   EfiBootScriptExecutorVariable = (BOOT_SCRIPT_EXECUTOR_VARIABLE *) (UINTN) TempEfiBootScriptExecutorVariable;
     1030  EfiBootScriptExecutorVariable = (BOOT_SCRIPT_EXECUTOR_VARIABLE *)(UINTN)TempEfiBootScriptExecutorVariable;
    9711031  ASSERT (EfiBootScriptExecutorVariable != NULL);
    9721032
    973   DEBUG (( DEBUG_INFO, "AcpiS3Context = %x\n", AcpiS3Context));
    974   DEBUG (( DEBUG_INFO, "Waking Vector = %x\n", ((EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) ((UINTN) (AcpiS3Context->AcpiFacsTable)))->FirmwareWakingVector));
    975   DEBUG (( DEBUG_INFO, "AcpiS3Context->AcpiFacsTable = %x\n", AcpiS3Context->AcpiFacsTable));
    976   DEBUG (( DEBUG_INFO, "AcpiS3Context->IdtrProfile = %x\n", AcpiS3Context->IdtrProfile));
    977   DEBUG (( DEBUG_INFO, "AcpiS3Context->S3NvsPageTableAddress = %x\n", AcpiS3Context->S3NvsPageTableAddress));
    978   DEBUG (( DEBUG_INFO, "AcpiS3Context->S3DebugBufferAddress = %x\n", AcpiS3Context->S3DebugBufferAddress));
    979   DEBUG (( DEBUG_INFO, "AcpiS3Context->BootScriptStackBase = %x\n", AcpiS3Context->BootScriptStackBase));
    980   DEBUG (( DEBUG_INFO, "AcpiS3Context->BootScriptStackSize = %x\n", AcpiS3Context->BootScriptStackSize));
    981   DEBUG (( DEBUG_INFO, "EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint = %x\n", EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint));
     1033  DEBUG ((DEBUG_INFO, "AcpiS3Context = %x\n", AcpiS3Context));
     1034  DEBUG ((DEBUG_INFO, "Waking Vector = %x\n", ((EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)((UINTN)(AcpiS3Context->AcpiFacsTable)))->FirmwareWakingVector));
     1035  DEBUG ((DEBUG_INFO, "AcpiS3Context->AcpiFacsTable = %x\n", AcpiS3Context->AcpiFacsTable));
     1036  DEBUG ((DEBUG_INFO, "AcpiS3Context->IdtrProfile = %x\n", AcpiS3Context->IdtrProfile));
     1037  DEBUG ((DEBUG_INFO, "AcpiS3Context->S3NvsPageTableAddress = %x\n", AcpiS3Context->S3NvsPageTableAddress));
     1038  DEBUG ((DEBUG_INFO, "AcpiS3Context->S3DebugBufferAddress = %x\n", AcpiS3Context->S3DebugBufferAddress));
     1039  DEBUG ((DEBUG_INFO, "AcpiS3Context->BootScriptStackBase = %x\n", AcpiS3Context->BootScriptStackBase));
     1040  DEBUG ((DEBUG_INFO, "AcpiS3Context->BootScriptStackSize = %x\n", AcpiS3Context->BootScriptStackSize));
     1041  DEBUG ((DEBUG_INFO, "EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint = %x\n", EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint));
    9821042
    9831043  //
     
    9931053  }
    9941054
    995   if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
     1055  if ((FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (sizeof (UINTN) == sizeof (UINT64))) {
    9961056    //
    9971057    // Need reconstruct page table here, since we do not trust ACPINvs.
     
    10021062      Build4GPageTableOnly = TRUE;
    10031063    }
     1064
    10041065    RestoreS3PageTables ((UINTN)AcpiS3Context->S3NvsPageTableAddress, Build4GPageTableOnly);
    10051066  }
     
    10101071  GuidHob = GetFirstGuidHob (&gEfiAcpiVariableGuid);
    10111072  if (GuidHob != NULL) {
    1012     //
    1013     // Below SwitchStack/AsmEnablePaging64 function has
    1014     // assumption that it's in 32 bits mode now.
    1015     // Add ASSERT code to indicate this assumption.
    1016     //
    1017     ASSERT(sizeof (UINTN) == sizeof (UINT32));
    1018 
    10191073    Status = PeiServicesLocatePpi (
    1020                               &gPeiSmmAccessPpiGuid,
    1021                               0,
    1022                               NULL,
    1023                               (VOID **) &SmmAccess
    1024                               );
     1074               &gPeiSmmAccessPpiGuid,
     1075               0,
     1076               NULL,
     1077               (VOID **)&SmmAccess
     1078               );
    10251079    for (Index = 0; !EFI_ERROR (Status); Index++) {
    10261080      Status = SmmAccess->Open ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), SmmAccess, Index);
    10271081    }
    10281082
    1029     SmramDescriptor = (EFI_SMRAM_DESCRIPTOR *) GET_GUID_HOB_DATA (GuidHob);
     1083    SmramDescriptor  = (EFI_SMRAM_DESCRIPTOR *)GET_GUID_HOB_DATA (GuidHob);
    10301084    SmmS3ResumeState = (SMM_S3_RESUME_STATE *)(UINTN)SmramDescriptor->CpuStart;
    10311085
     
    10361090    SmmS3ResumeState->ReturnStackPointer = (EFI_PHYSICAL_ADDRESS)STACK_ALIGN_DOWN (&Status);
    10371091
    1038     DEBUG (( DEBUG_INFO, "SMM S3 Signature                = %x\n", SmmS3ResumeState->Signature));
    1039     DEBUG (( DEBUG_INFO, "SMM S3 Stack Base               = %x\n", SmmS3ResumeState->SmmS3StackBase));
    1040     DEBUG (( DEBUG_INFO, "SMM S3 Stack Size               = %x\n", SmmS3ResumeState->SmmS3StackSize));
    1041     DEBUG (( DEBUG_INFO, "SMM S3 Resume Entry Point       = %x\n", SmmS3ResumeState->SmmS3ResumeEntryPoint));
    1042     DEBUG (( DEBUG_INFO, "SMM S3 CR0                      = %x\n", SmmS3ResumeState->SmmS3Cr0));
    1043     DEBUG (( DEBUG_INFO, "SMM S3 CR3                      = %x\n", SmmS3ResumeState->SmmS3Cr3));
    1044     DEBUG (( DEBUG_INFO, "SMM S3 CR4                      = %x\n", SmmS3ResumeState->SmmS3Cr4));
    1045     DEBUG (( DEBUG_INFO, "SMM S3 Return CS                = %x\n", SmmS3ResumeState->ReturnCs));
    1046     DEBUG (( DEBUG_INFO, "SMM S3 Return Entry Point       = %x\n", SmmS3ResumeState->ReturnEntryPoint));
    1047     DEBUG (( DEBUG_INFO, "SMM S3 Return Context1          = %x\n", SmmS3ResumeState->ReturnContext1));
    1048     DEBUG (( DEBUG_INFO, "SMM S3 Return Context2          = %x\n", SmmS3ResumeState->ReturnContext2));
    1049     DEBUG (( DEBUG_INFO, "SMM S3 Return Stack Pointer     = %x\n", SmmS3ResumeState->ReturnStackPointer));
    1050     DEBUG (( DEBUG_INFO, "SMM S3 Smst                     = %x\n", SmmS3ResumeState->Smst));
    1051 
    1052     if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_32) {
     1092    DEBUG ((DEBUG_INFO, "SMM S3 Signature                = %x\n", SmmS3ResumeState->Signature));
     1093    DEBUG ((DEBUG_INFO, "SMM S3 Stack Base               = %x\n", SmmS3ResumeState->SmmS3StackBase));
     1094    DEBUG ((DEBUG_INFO, "SMM S3 Stack Size               = %x\n", SmmS3ResumeState->SmmS3StackSize));
     1095    DEBUG ((DEBUG_INFO, "SMM S3 Resume Entry Point       = %x\n", SmmS3ResumeState->SmmS3ResumeEntryPoint));
     1096    DEBUG ((DEBUG_INFO, "SMM S3 CR0                      = %x\n", SmmS3ResumeState->SmmS3Cr0));
     1097    DEBUG ((DEBUG_INFO, "SMM S3 CR3                      = %x\n", SmmS3ResumeState->SmmS3Cr3));
     1098    DEBUG ((DEBUG_INFO, "SMM S3 CR4                      = %x\n", SmmS3ResumeState->SmmS3Cr4));
     1099    DEBUG ((DEBUG_INFO, "SMM S3 Return CS                = %x\n", SmmS3ResumeState->ReturnCs));
     1100    DEBUG ((DEBUG_INFO, "SMM S3 Return Entry Point       = %x\n", SmmS3ResumeState->ReturnEntryPoint));
     1101    DEBUG ((DEBUG_INFO, "SMM S3 Return Context1          = %x\n", SmmS3ResumeState->ReturnContext1));
     1102    DEBUG ((DEBUG_INFO, "SMM S3 Return Context2          = %x\n", SmmS3ResumeState->ReturnContext2));
     1103    DEBUG ((DEBUG_INFO, "SMM S3 Return Stack Pointer     = %x\n", SmmS3ResumeState->ReturnStackPointer));
     1104    DEBUG ((DEBUG_INFO, "SMM S3 Smst                     = %x\n", SmmS3ResumeState->Smst));
     1105
     1106    //
     1107    // Directly do the switch stack when PEI and SMM env run in the same execution mode.
     1108    //
     1109    if (((SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_32) && (sizeof (UINTN) == sizeof (UINT32))) ||
     1110        ((SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_64) && (sizeof (UINTN) == sizeof (UINT64))))
     1111    {
    10531112      SwitchStack (
    10541113        (SWITCH_STACK_ENTRY_POINT)(UINTN)SmmS3ResumeState->SmmS3ResumeEntryPoint,
     
    10581117        );
    10591118    }
     1119
    10601120    if (SmmS3ResumeState->Signature == SMM_S3_RESUME_SMM_64) {
    10611121      //
     
    10861146        AsmWriteCr0 (Cr0.UintN);
    10871147      }
     1148
    10881149      AsmWriteCr3 ((UINTN)SmmS3ResumeState->SmmS3Cr3);
    10891150
     
    11031164        );
    11041165    }
    1105 
    1106   }
    1107 
    1108   S3ResumeExecuteBootScript (AcpiS3Context, EfiBootScriptExecutorVariable );
     1166  }
     1167
     1168  S3ResumeExecuteBootScript (AcpiS3Context, EfiBootScriptExecutorVariable);
    11091169  return EFI_SUCCESS;
    11101170}
     1171
    11111172/**
    11121173  Main entry for S3 Resume PEIM.
     
    11231184EFIAPI
    11241185PeimS3ResumeEntryPoint (
    1125   IN EFI_PEI_FILE_HANDLE       FileHandle,
    1126   IN CONST EFI_PEI_SERVICES    **PeiServices
     1186  IN EFI_PEI_FILE_HANDLE     FileHandle,
     1187  IN CONST EFI_PEI_SERVICES  **PeiServices
    11271188  )
    11281189{
     
    11371198  return EFI_SUCCESS;
    11381199}
    1139 
  • trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.nasm

    • Property svn:mime-type set to text/x-asm
Note: See TracChangeset for help on using the changeset viewer.

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