Changeset 108794 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library
- Timestamp:
- Mar 31, 2025 11:31:09 AM (5 weeks ago)
- svn:sync-xref-src-repo-rev:
- 168237
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-164365 /vendor/edk2/current 103735-103757,103769-103776,129194-168232
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspCommonLib/BaseFspCommonLib.inf
r80721 r108794 17 17 [Sources] 18 18 FspCommonLib.c 19 ReturnStatus.c 19 20 20 21 [Packages] -
trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
r105670 r108794 16 16 #pragma pack(1) 17 17 18 //19 // API Parameter +0x3420 // API return address +0x3021 //22 // push FspInfoHeader +0x2C23 // pushfd +0x2824 // cli25 // pushad +0x2426 // sub esp, 8 +0x0027 // sidt fword ptr [esp]28 //29 18 typedef struct { 30 19 UINT16 IdtrLimit; 31 20 UINT32 IdtrBase; 32 21 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. 33 26 UINT32 Registers[8]; // General Purpose Registers: Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx and Eax 34 27 UINT16 Flags[2]; … … 38 31 } CONTEXT_STACK; 39 32 40 //41 // API return address +0xB842 // Reserved +0xB043 // push API Parameter2 +0xA844 // push API Parameter1 +0xA045 // push FspInfoHeader +0x9846 // pushfq +0x9047 // cli48 // PUSHA_64 +0x1049 // sub rsp, 16 +0x0050 // sidt [rsp]51 //52 33 typedef struct { 53 34 UINT64 Idtr[2]; // IDTR Limit - bit0:bi15, IDTR Base - bit16:bit79 35 UINT64 Cr0; 36 UINT64 Cr3; 37 UINT64 Cr4; 38 UINT64 Efer; 54 39 UINT64 Registers[16]; // General Purpose Registers: RDI, RSI, RBP, RSP, RBX, RDX, RCX, RAX, and R15 to R8 55 40 UINT32 Flags[2]; … … 90 75 ) 91 76 { 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; 96 81 } 97 82 … … 567 552 FspData->StatusCode = StatusCode; 568 553 } 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 status574 575 **/576 VOID577 EFIAPI578 FspApiReturnStatusReset (579 IN EFI_STATUS FspResetType580 )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 BootLoader589 /// calls the FSP API without honoring the reset request by FSP590 ///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 33 33 IoLib 34 34 35 36 35 [Pcd] 36 gIntelFsp2PkgTokenSpaceGuid.PcdFspSaveRestorePageTableEnable -
trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/Ia32/Stack.nasm
r99404 r108794 13 13 14 14 extern ASM_PFX(SwapStack) 15 extern 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 15 21 16 22 ;------------------------------------------------------------------------------ … … 51 57 cli 52 58 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 85 SkipPagetableSave: 86 53 87 sub esp, 8 54 88 sidt [esp] … … 62 96 lidt [esp] 63 97 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 128 SkipEferLabel1: 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 145 SkipCr0Label1: 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 173 SkipCr0Label2: 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 190 SkipEferLabel2: 191 SkipPagetableRestore: 192 193 ; pop page table related registers. 194 add esp, 16 195 64 196 popad 65 197 popfd -
trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm
r105670 r108794 9 9 ; 10 10 ;------------------------------------------------------------------------------ 11 11 DEFAULT REL 12 12 SECTION .text 13 13 14 14 %include "PushPopRegsNasm.inc" 15 15 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 16 21 extern ASM_PFX(SwapStack) 22 extern ASM_PFX(FeaturePcdGet (PcdFspSaveRestorePageTableEnable)) 17 23 18 24 ;------------------------------------------------------------------------------ … … 56 62 cli 57 63 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 93 SkipPagetableSave: 94 58 95 sub rsp, 16 59 96 sidt [rsp] … … 69 106 lidt [rsp] 70 107 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 138 SkipEferLabel1: 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 173 SkipEferLabel2: 174 SkipPagetableRestore: 175 ; pop page table related registers. 176 add rsp, 32 177 71 178 POPA_64 72 179 popfq
Note:
See TracChangeset
for help on using the changeset viewer.