3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The
8 full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "LegacyBiosInterface.h"
19 Assign drive number to legacy HDD drives prior to booting an EFI
20 aware OS so the OS can access drives without an EFI driver.
21 Note: BBS compliant drives ARE NOT available until this call by
24 @param This Protocol instance pointer.
25 @param BbsCount Number of BBS_TABLE structures
26 @param BbsTable List BBS entries
28 @retval EFI_SUCCESS Drive numbers assigned
33 LegacyBiosPrepareToBootEfi (
34 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
36 OUT BBS_TABLE
**BbsTable
40 // Shadow All Opion ROM
42 LegacyBiosShadowAllLegacyOproms (This
);
48 To boot from an unconventional device like parties and/or execute
51 @param This Protocol instance pointer.
52 @param Attributes How to interpret the other input parameters
53 @param BbsEntry The 0-based index into the BbsTable for the
55 @param BeerData Pointer to the 128 bytes of ram BEER data.
56 @param ServiceAreaData Pointer to the 64 bytes of raw Service Area data.
57 The caller must provide a pointer to the specific
58 Service Area and not the start all Service Areas.
59 EFI_INVALID_PARAMETER if error. Does NOT return if no error.
64 LegacyBiosBootUnconventionalDevice (
65 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
66 IN UDC_ATTRIBUTES Attributes
,
69 IN VOID
*ServiceAreaData
72 return EFI_INVALID_PARAMETER
;
77 Attempt to legacy boot the BootOption. If the EFI contexted has been
78 compromised this function will not return.
80 @param This Protocol instance pointer.
81 @param BbsDevicePath EFI Device Path from BootXXXX variable.
82 @param LoadOptionsSize Size of LoadOption in size.
83 @param LoadOptions LoadOption from BootXXXX variable
85 @retval EFI_SUCCESS Removable media not present
90 LegacyBiosLegacyBoot (
91 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
92 IN BBS_BBS_DEVICE_PATH
*BbsDevicePath
,
93 IN UINT32 LoadOptionsSize
,
97 return EFI_UNSUPPORTED
;
101 Build the E820 table.
103 @param Private Legacy BIOS Instance data
104 @param Size Size of E820 Table
106 @retval EFI_SUCCESS It should always work.
110 LegacyBiosBuildE820 (
111 IN LEGACY_BIOS_INSTANCE
*Private
,
122 @param This Protocol instance pointer.
123 @param HddCount Number of HDD_INFO structures
124 @param HddInfo Onboard IDE controller information
125 @param BbsCount Number of BBS_TABLE structures
126 @param BbsTable List BBS entries
128 @retval EFI_SUCCESS Tables returned
129 @retval EFI_NOT_FOUND resource not found
130 @retval EFI_DEVICE_ERROR can not get BBS table
135 LegacyBiosGetBbsInfo (
136 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
137 OUT UINT16
*HddCount
,
138 OUT HDD_INFO
**HddInfo
,
139 OUT UINT16
*BbsCount
,
140 OUT BBS_TABLE
**BbsTable
143 return EFI_UNSUPPORTED
;
147 Fill in the standard BDA for Keyboard LEDs
149 @param This Protocol instance pointer.
150 @param Leds Current LED status
152 @retval EFI_SUCCESS It should always work.
157 LegacyBiosUpdateKeyboardLedStatus (
158 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
162 return EFI_UNSUPPORTED
;
166 Relocate this image under 4G memory for IPF.
168 @param ImageHandle Handle of driver image.
169 @param SystemTable Pointer to system table.
171 @retval EFI_SUCCESS Image successfully relocated.
172 @retval EFI_ABORTED Failed to relocate image.
176 RelocateImageUnder4GIfNeeded (
177 IN EFI_HANDLE ImageHandle
,
178 IN EFI_SYSTEM_TABLE
*SystemTable
182 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
184 EFI_PHYSICAL_ADDRESS LoadedImageBase
;
185 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
186 EFI_PHYSICAL_ADDRESS MemoryAddress
;
187 EFI_HANDLE NewImageHandle
;
189 Status
= gBS
->HandleProtocol (
191 &gEfiLoadedImageProtocolGuid
,
192 (VOID
*) &LoadedImage
195 if (!EFI_ERROR (Status
)) {
196 LoadedImageBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) LoadedImage
->ImageBase
;
197 if (LoadedImageBase
> 0xffffffff) {
198 NumberOfPages
= (UINTN
) (DivU64x32(LoadedImage
->ImageSize
, EFI_PAGE_SIZE
) + 1);
201 // Allocate buffer below 4GB here
203 Status
= AllocateLegacyMemory (
206 NumberOfPages
, // do we have to convert this to pages??
209 if (EFI_ERROR (Status
)) {
213 ZeroMem (&ImageContext
, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT
));
214 ImageContext
.Handle
= (VOID
*)(UINTN
)LoadedImageBase
;
215 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
218 // Get information about the image being loaded
220 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
221 if (EFI_ERROR (Status
)) {
224 ImageContext
.ImageAddress
= (PHYSICAL_ADDRESS
)MemoryAddress
;
226 // Align buffer on section boundary
228 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
229 ImageContext
.ImageAddress
&= ~((PHYSICAL_ADDRESS
)ImageContext
.SectionAlignment
- 1);
232 // Load the image to our new buffer
234 Status
= PeCoffLoaderLoadImage (&ImageContext
);
235 if (EFI_ERROR (Status
)) {
236 gBS
->FreePages (MemoryAddress
, NumberOfPages
);
241 // Relocate the image in our new buffer
243 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
244 if (EFI_ERROR (Status
)) {
245 gBS
->FreePages (MemoryAddress
, NumberOfPages
);
250 // Create a new handle with gEfiCallerIdGuid to be used as the ImageHandle fore the reloaded image
252 NewImageHandle
= NULL
;
253 Status
= gBS
->InstallProtocolInterface (
256 EFI_NATIVE_INTERFACE
,
261 // Flush the instruction cache so the image data is written before we execute it
263 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, (UINTN
)ImageContext
.ImageSize
);
265 Status
= ((EFI_IMAGE_ENTRY_POINT
)(UINTN
)(ImageContext
.EntryPoint
)) (NewImageHandle
, SystemTable
);
266 if (EFI_ERROR (Status
)) {
267 gBS
->FreePages (MemoryAddress
, NumberOfPages
);
271 // return error directly the BS will unload this image