VirtualBox

Ignore:
Timestamp:
Mar 31, 2025 11:31:09 AM (5 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168237
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
1 added
6 edited

Legend:

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

  • trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspCommonLib/BaseFspCommonLib.inf

    r80721 r108794  
    1717[Sources]
    1818  FspCommonLib.c
     19  ReturnStatus.c
    1920
    2021[Packages]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c

    r105670 r108794  
    1616#pragma pack(1)
    1717
    18 //
    19 //   API Parameter                +0x34
    20 //   API return address           +0x30
    21 //
    22 //   push    FspInfoHeader        +0x2C
    23 //   pushfd                       +0x28
    24 //   cli
    25 //   pushad                       +0x24
    26 //   sub     esp, 8               +0x00
    27 //   sidt    fword ptr [esp]
    28 //
    2918typedef struct {
    3019  UINT16    IdtrLimit;
    3120  UINT32    IdtrBase;
    3221  UINT16    Reserved;
     22  UINT32    Cr0;
     23  UINT32    Cr3;
     24  UINT32    Cr4;
     25  UINT32    Efer;           // lower 32-bit of EFER since only NXE bit (BIT11) need to be restored.
    3326  UINT32    Registers[8];   // General Purpose Registers: Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx and Eax
    3427  UINT16    Flags[2];
     
    3831} CONTEXT_STACK;
    3932
    40 //
    41 //   API return address           +0xB8
    42 //   Reserved                     +0xB0
    43 //   push    API Parameter2       +0xA8
    44 //   push    API Parameter1       +0xA0
    45 //   push    FspInfoHeader        +0x98
    46 //   pushfq                       +0x90
    47 //   cli
    48 //   PUSHA_64                     +0x10
    49 //   sub     rsp, 16              +0x00
    50 //   sidt    [rsp]
    51 //
    5233typedef struct {
    5334  UINT64    Idtr[2];        // IDTR Limit - bit0:bi15, IDTR Base - bit16:bit79
     35  UINT64    Cr0;
     36  UINT64    Cr3;
     37  UINT64    Cr4;
     38  UINT64    Efer;
    5439  UINT64    Registers[16];  // General Purpose Registers: RDI, RSI, RBP, RSP, RBX, RDX, RCX, RAX, and R15 to R8
    5540  UINT32    Flags[2];
     
    9075  )
    9176{
    92   FSP_GLOBAL_DATA  *FspData;
    93 
    94   FspData = *(FSP_GLOBAL_DATA  **)(UINTN)PcdGet32 (PcdGlobalDataPointerAddress);
    95   return FspData;
     77  UINT32  FspDataAddress;
     78
     79  FspDataAddress = *(UINT32 *)(UINTN)PcdGet32 (PcdGlobalDataPointerAddress);
     80  return (FSP_GLOBAL_DATA *)(UINTN)FspDataAddress;
    9681}
    9782
     
    567552  FspData->StatusCode = StatusCode;
    568553}
    569 
    570 /**
    571   This function updates the return status of the FSP API with requested reset type and returns to Boot Loader.
    572 
    573   @param[in] FspResetType     Reset type that needs to returned as API return status
    574 
    575 **/
    576 VOID
    577 EFIAPI
    578 FspApiReturnStatusReset (
    579   IN EFI_STATUS  FspResetType
    580   )
    581 {
    582   volatile BOOLEAN  LoopUntilReset;
    583 
    584   LoopUntilReset = TRUE;
    585   DEBUG ((DEBUG_INFO, "FSP returning control to Bootloader with reset required return status %x\n", FspResetType));
    586   if (GetFspGlobalDataPointer ()->FspMode == FSP_IN_API_MODE) {
    587     ///
    588     /// Below code is not an infinite loop.The control will go back to API calling function in BootLoader each time BootLoader
    589     /// calls the FSP API without honoring the reset request by FSP
    590     ///
    591     do {
    592       SetFspApiReturnStatus (FspResetType);
    593       Pei2LoaderSwitchStack ();
    594       DEBUG ((DEBUG_ERROR, "!!!ERROR: FSP has requested BootLoader for reset. But BootLoader has not honored the reset\n"));
    595       DEBUG ((DEBUG_ERROR, "!!!ERROR: Please add support in BootLoader to honor the reset request from FSP\n"));
    596     } while (LoopUntilReset);
    597   }
    598 }
  • trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/BaseFspSwitchStackLib.inf

    r99404 r108794  
    3333  IoLib
    3434
    35 
    36 
     35[Pcd]
     36  gIntelFsp2PkgTokenSpaceGuid.PcdFspSaveRestorePageTableEnable
  • trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/Ia32/Stack.nasm

    r99404 r108794  
    1313
    1414extern ASM_PFX(SwapStack)
     15extern ASM_PFX(FeaturePcdGet (PcdFspSaveRestorePageTableEnable))
     16
     17; Page table related bits in CR0/CR4/EFER
     18%define CR0_PG_MASK          0x80010000  ; CR0.PG and CR0.WP
     19%define CR4_PG_MASK          0x10B0      ; CR4.PSE, CR4.PAE, CR4.PGE and CR4.LA57
     20%define EFER_PG_MASK         0x800       ; EFER.NXE
    1521
    1622;------------------------------------------------------------------------------
     
    5157    cli
    5258    pushad
     59
     60    ;
     61    ; Allocate 4x4 bytes on the stack.
     62    ;
     63    sub     esp, 16
     64    cmp     byte [dword ASM_PFX(FeaturePcdGet (PcdFspSaveRestorePageTableEnable))], 0
     65    jz      SkipPagetableSave
     66
     67    add     esp, 16
     68    ; Save EFER MSR lower 32 bits
     69    push   ecx
     70    push   eax
     71    mov    ecx, 0xC0000080
     72    rdmsr
     73    mov    edx, eax
     74    pop    eax
     75    pop    ecx
     76    push   edx
     77
     78    ; Save CR registers
     79    mov    eax, cr4
     80    push   eax
     81    mov    eax, cr3
     82    push   eax
     83    mov    eax, cr0
     84    push   eax
     85SkipPagetableSave:
     86
    5387    sub     esp, 8
    5488    sidt    [esp]
     
    6296    lidt    [esp]
    6397    add     esp, 8
     98
     99    cmp     byte [dword ASM_PFX(FeaturePcdGet (PcdFspSaveRestorePageTableEnable))], 0
     100    jz      SkipPagetableRestore
     101    ; [esp]    stores new cr0
     102    ; [esp+4]  stores new cr3
     103    ; [esp+8]  stores new cr4
     104    ; [esp+12] stores new Efer
     105    ;
     106    ; When new EFER.NXE == 1, the restore flow is: EFER --> CRx
     107    ; Otherwise: CRx --> EFER
     108    ; When new CR0.PG == 1, the restore flow for CRx is: CR3 --> CR4 --> CR0
     109    ; Otherwise, the restore flow is: CR0 --> CR3 --> CR4
     110    ;
     111    ; If NXE bit is changed to 1, change NXE before CR register
     112    ; This is because Nx bit in page table entry in new CR3 will be invalid
     113    ; if updating CR3 before EFER MSR.
     114    ;
     115    mov eax, [esp+12]
     116    bt  eax, 11
     117    jnc SkipEferLabel1
     118
     119    ; Restore EFER MSR
     120    mov    ecx, 0xC0000080
     121    rdmsr
     122    and    eax, ~EFER_PG_MASK
     123    mov    ebx, [esp+12]
     124    and    ebx, EFER_PG_MASK
     125    or     eax, ebx
     126    wrmsr
     127
     128SkipEferLabel1:
     129
     130    ;
     131    ; if new cr0 is to disable page table, change CR0 before CR3/CR4
     132    ;
     133    mov     eax, [esp]
     134    bt      eax, 31
     135    jc      SkipCr0Label1
     136
     137    ; Restore CR0
     138    mov     edx, cr0
     139    and     edx, ~CR0_PG_MASK
     140    mov     eax, [esp]
     141    and     eax, CR0_PG_MASK
     142    or      edx, eax
     143    mov     cr0, edx
     144
     145SkipCr0Label1:
     146
     147    ; Restore CR3/CR4
     148    mov     eax, [esp+4]
     149    mov     cr3, eax
     150
     151    mov     edx, cr4
     152    and     edx, ~CR4_PG_MASK
     153    mov     eax, [esp+8]
     154    and     eax, CR4_PG_MASK
     155    or      edx, eax
     156    mov     cr4, edx
     157
     158    ;
     159    ; if new cr0 is to enable page table, change CR0 after CR3/CR4
     160    ;
     161    mov     eax, [esp]
     162    bt      eax, 31
     163    jnc     SkipCr0Label2
     164
     165    ; Restore CR0
     166    mov     edx, cr0
     167    and     edx, ~CR0_PG_MASK
     168    mov     eax, [esp]
     169    and     eax, CR0_PG_MASK
     170    or      edx, eax
     171    mov     cr0, edx
     172
     173SkipCr0Label2:
     174    ;
     175    ; If NXE bit is changed to 0, change NXE after than CR regiser
     176    ;
     177    mov eax, [esp+12]
     178    bt  eax, 11
     179    jc SkipEferLabel2
     180
     181    ; Restore EFER MSR
     182    mov    ecx, 0xC0000080
     183    rdmsr
     184    and    eax, ~EFER_PG_MASK
     185    mov    ebx, [esp+12]
     186    and    ebx, EFER_PG_MASK
     187    or     eax, ebx
     188    wrmsr
     189
     190SkipEferLabel2:
     191SkipPagetableRestore:
     192
     193    ; pop page table related registers.
     194    add     esp, 16
     195
    64196    popad
    65197    popfd
  • trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm

    r105670 r108794  
    99;
    1010;------------------------------------------------------------------------------
    11 
     11    DEFAULT REL
    1212    SECTION .text
    1313
    1414%include    "PushPopRegsNasm.inc"
    1515
     16; Page table related bits in CR0/CR4/EFER
     17%define CR0_PG_MASK          0x80010000  ; CR0.PG and CR0.WP
     18%define CR4_PG_MASK          0x10B0      ; CR4.PSE, CR4.PAE, CR4.PGE and CR4.LA57
     19%define EFER_PG_MASK         0x800       ; EFER.NXE
     20
    1621extern ASM_PFX(SwapStack)
     22extern ASM_PFX(FeaturePcdGet (PcdFspSaveRestorePageTableEnable))
    1723
    1824;------------------------------------------------------------------------------
     
    5662    cli
    5763    PUSHA_64
     64
     65    ;
     66    ; Allocate 4x8 bytes on the stack.
     67    ;
     68    sub     rsp, 32
     69    lea     rdx, [ASM_PFX(FeaturePcdGet (PcdFspSaveRestorePageTableEnable))]
     70    mov     dl, byte [rdx]
     71    cmp     dl, 0
     72    jz      SkipPagetableSave
     73
     74    add     rsp, 32
     75    ; Save EFER MSR
     76    push   rcx
     77    push   rax
     78    mov    rcx, 0xC0000080
     79    rdmsr
     80    shl    rdx, 0x20
     81    or     rdx, rax
     82    pop    rax
     83    pop    rcx
     84    push   rdx
     85
     86    ; Save CR registers
     87    mov    rdx, cr4
     88    push   rdx
     89    mov    rdx, cr3
     90    push   rdx
     91    mov    rdx, cr0
     92    push   rdx
     93SkipPagetableSave:
     94
    5895    sub     rsp, 16
    5996    sidt    [rsp]
     
    69106    lidt    [rsp]
    70107    add     rsp, 16
     108
     109    lea     rax, [ASM_PFX(FeaturePcdGet (PcdFspSaveRestorePageTableEnable))]
     110    mov     al, byte [rax]
     111    cmp     al, 0
     112    jz      SkipPagetableRestore
     113    ; [rsp]    stores new cr0
     114    ; [rsp+8]  stores new cr3
     115    ; [rsp+16] stores new cr4
     116    ; [rsp+24] stores new Efer
     117    ;
     118    ; When new EFER.NXE == 1, the restore flow is: EFER --> CRx
     119    ; Otherwise: CRx --> EFER
     120    ;
     121    ; If NXE bit is changed to 1, change NXE before CR register
     122    ; This is because Nx bit in page table entry in new CR3 will be invalid
     123    ; if updating CR3 before EFER MSR.
     124    ;
     125    mov rax, [rsp + 24]
     126    bt  rax, 11
     127    jnc SkipEferLabel1
     128
     129    ; Restore EFER MSR
     130    mov    ecx, 0xC0000080
     131    rdmsr
     132    and    eax, ~EFER_PG_MASK
     133    mov    ebx, [rsp + 24]
     134    and    ebx, EFER_PG_MASK
     135    or     eax, ebx
     136    wrmsr
     137
     138SkipEferLabel1:
     139
     140    mov     rbx, [rsp]
     141    mov     rdx, cr0
     142    and     rdx, ~CR0_PG_MASK
     143    and     rbx, CR0_PG_MASK
     144    or      rdx, rbx
     145    mov     cr0, rdx
     146
     147    mov     rbx, [rsp + 8]
     148    mov     cr3, rbx
     149
     150    mov     rbx, [rsp + 16]
     151    mov     rdx, cr4
     152    and     rdx, ~CR4_PG_MASK
     153    and     rbx, CR4_PG_MASK
     154    or      rdx, rbx
     155    mov     cr4, rdx
     156
     157    ;
     158    ; If NXE bit is changed to 0, change NXE after than CR regiser
     159    ;
     160    mov rax, [rsp + 24]
     161    bt  rax, 11
     162    jc  SkipEferLabel2
     163
     164    ; Restore EFER MSR
     165    mov    ecx, 0xC0000080
     166    rdmsr
     167    and    eax, ~EFER_PG_MASK
     168    mov    ebx, [rsp + 24]
     169    and    ebx, EFER_PG_MASK
     170    or     eax, ebx
     171    wrmsr
     172
     173SkipEferLabel2:
     174SkipPagetableRestore:
     175    ; pop page table related registers.
     176    add     rsp, 32
     177
    71178    POPA_64
    72179    popfq
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