VirtualBox

Ignore:
Timestamp:
Mar 31, 2025 11:31:09 AM (2 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:
2 edited

Legend:

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

  • 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