3 Copyright (c) 2006 - 2012, 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 #ifndef _LEGACY_BIOS_INTERFACE_
17 #define _LEGACY_BIOS_INTERFACE_
20 #include <FrameworkDxe.h>
22 #include <Guid/SmBios.h>
23 #include <Guid/Acpi.h>
24 #include <Guid/DxeServices.h>
25 #include <Guid/LegacyBios.h>
26 #include <Guid/StatusCodeDataTypeId.h>
27 #include <Guid/ImageAuthentication.h>
29 #include <Protocol/BlockIo.h>
30 #include <Protocol/LoadedImage.h>
31 #include <Protocol/PciIo.h>
32 #include <Protocol/Cpu.h>
33 #include <Protocol/Timer.h>
34 #include <Protocol/IsaIo.h>
35 #include <Protocol/LegacyRegion2.h>
36 #include <Protocol/SimpleTextIn.h>
37 #include <Protocol/LegacyInterrupt.h>
38 #include <Protocol/LegacyBios.h>
39 #include <Protocol/DiskInfo.h>
40 #include <Protocol/GenericMemoryTest.h>
41 #include <Protocol/LegacyBiosPlatform.h>
42 #include <Protocol/DevicePath.h>
43 #include <Protocol/Legacy8259.h>
44 #include <Protocol/PciRootBridgeIo.h>
46 #include <Library/BaseLib.h>
47 #include <Library/DebugLib.h>
48 #include <Library/UefiLib.h>
49 #include <Library/BaseMemoryLib.h>
50 #include <Library/ReportStatusCodeLib.h>
51 #include <Library/UefiRuntimeServicesTableLib.h>
52 #include <Library/HobLib.h>
53 #include <Library/UefiDriverEntryPoint.h>
54 #include <Library/MemoryAllocationLib.h>
55 #include <Library/UefiBootServicesTableLib.h>
56 #include <Library/IoLib.h>
57 #include <Library/PcdLib.h>
58 #include <Library/DevicePathLib.h>
59 #include <Library/DxeServicesTableLib.h>
60 #include <Library/PeCoffLib.h>
61 #include <Library/CacheMaintenanceLib.h>
62 #include <Library/DebugAgentLib.h>
65 // BUGBUG: This entry maybe changed to PCD in future and wait for
66 // redesign of BDS library
68 #define MAX_BBS_ENTRIES 0x100
72 // (These apply only to errors with the thunk and not to the code that was
76 #define THUNK_ERR_A20_UNSUP 0x01
77 #define THUNK_ERR_A20_FAILED 0x02
80 // Vector base definitions
83 // 8259 Hardware definitions
85 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
86 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
89 // The original PC used INT8-F for master PIC. Since these mapped over
90 // processor exceptions TIANO moved the master PIC to INT68-6F.
92 // The vector base for slave PIC is set as 0x70 for PC-AT compatibility.
94 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
95 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
98 // When we call CSM16 functions, some CSM16 use es:[offset + 0xabcd] to get data passed from CSM32,
99 // offset + 0xabcd could overflow which exceeds 0xFFFF which is invalid in real mode.
100 // So this will keep offset as small as possible to avoid offset overflow in real mode.
102 #define NORMALIZE_EFI_SEGMENT(_Adr) (UINT16) (((UINTN) (_Adr)) >> 4)
103 #define NORMALIZE_EFI_OFFSET(_Adr) (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xf)
109 #define LEGACY_BDA_TRACE 0x000
110 #define LEGACY_BIOS_TRACE 0x040
111 #define LEGACY_BOOT_TRACE 0x080
112 #define LEGACY_CMOS_TRACE 0x0C0
113 #define LEGACY_IDE_TRACE 0x100
114 #define LEGACY_MP_TRACE 0x140
115 #define LEGACY_PCI_TRACE 0x180
116 #define LEGACY_SIO_TRACE 0x1C0
118 #define LEGACY_PCI_TRACE_000 LEGACY_PCI_TRACE + 0x00
119 #define LEGACY_PCI_TRACE_001 LEGACY_PCI_TRACE + 0x01
120 #define LEGACY_PCI_TRACE_002 LEGACY_PCI_TRACE + 0x02
121 #define LEGACY_PCI_TRACE_003 LEGACY_PCI_TRACE + 0x03
122 #define LEGACY_PCI_TRACE_004 LEGACY_PCI_TRACE + 0x04
123 #define LEGACY_PCI_TRACE_005 LEGACY_PCI_TRACE + 0x05
124 #define LEGACY_PCI_TRACE_006 LEGACY_PCI_TRACE + 0x06
125 #define LEGACY_PCI_TRACE_007 LEGACY_PCI_TRACE + 0x07
126 #define LEGACY_PCI_TRACE_008 LEGACY_PCI_TRACE + 0x08
127 #define LEGACY_PCI_TRACE_009 LEGACY_PCI_TRACE + 0x09
128 #define LEGACY_PCI_TRACE_00A LEGACY_PCI_TRACE + 0x0A
129 #define LEGACY_PCI_TRACE_00B LEGACY_PCI_TRACE + 0x0B
130 #define LEGACY_PCI_TRACE_00C LEGACY_PCI_TRACE + 0x0C
131 #define LEGACY_PCI_TRACE_00D LEGACY_PCI_TRACE + 0x0D
132 #define LEGACY_PCI_TRACE_00E LEGACY_PCI_TRACE + 0x0E
133 #define LEGACY_PCI_TRACE_00F LEGACY_PCI_TRACE + 0x0F
135 #define BDA_VIDEO_MODE 0x49
142 UINT32 ShadowAddress
;
146 } ROM_INSTANCE_ENTRY
;
149 // Values for RealModeGdt
151 #if defined (MDE_CPU_IA32)
153 #define NUM_REAL_GDT_ENTRIES 3
154 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
155 #define INITIAL_VALUE_BELOW_1K 0x0
157 #elif defined (MDE_CPU_X64)
159 #define NUM_REAL_GDT_ENTRIES 8
160 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
161 #define INITIAL_VALUE_BELOW_1K 0x0
163 #elif defined (MDE_CPU_IPF)
165 #define NUM_REAL_GDT_ENTRIES 3
166 #define CONVENTIONAL_MEMORY_TOP 0x80000 // 512 KB
167 #define INITIAL_VALUE_BELOW_1K 0xff
174 // Define what a processor GDT looks like
187 UINT32 DefaultSize
: 1;
188 UINT32 Granularity
: 1;
202 // Define what a processor descriptor looks like
203 // This data structure must be kept in sync with ASM STRUCT in Thunk.inc
218 #define LOW_STACK_SIZE (8 * 1024) // 8k?
219 #define EFI_MAX_E820_ENTRY 100
220 #define FIRST_INSTANCE 1
221 #define NOT_FIRST_INSTANCE 0
223 #if defined (MDE_CPU_IA32)
226 // Space for the code
227 // The address of Code is also the beginning of the relocated Thunk code
229 CHAR8 Code
[4096]; // ?
231 // The address of the Reverse Thunk code
232 // Note that this member CONTAINS the address of the relocated reverse thunk
233 // code unlike the member variable 'Code', which IS the address of the Thunk
236 UINT32 LowReverseThunkStart
;
239 // Data for the code (cs releative)
241 DESCRIPTOR32 GdtDesc
; // Protected mode GDT
242 DESCRIPTOR32 IdtDesc
; // Protected mode IDT
246 UINT32 LowCodeSelector
; // Low code selector in GDT
247 UINT32 LowDataSelector
; // Low data selector in GDT
249 DESCRIPTOR32 RealModeIdtDesc
;
252 // real-mode GDT (temporary GDT with two real mode segment descriptors)
254 GDT32 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
255 DESCRIPTOR32 RealModeGdtDesc
;
258 // Members specifically for the reverse thunk
259 // The RevReal* members are used to store the current state of real mode
260 // before performing the reverse thunk. The RevFlat* members must be set
261 // before calling the reverse thunk assembly code.
266 DESCRIPTOR32 RevRealIdtDesc
;
267 UINT16 RevFlatDataSelector
; // Flat data selector in GDT
271 // A low memory stack
273 CHAR8 Stack
[LOW_STACK_SIZE
];
276 // Stack for flat mode after reverse thunk
277 // @bug - This may no longer be necessary if the reverse thunk interface
278 // is changed to have the flat stack in a different location.
280 CHAR8 RevThunkStack
[LOW_STACK_SIZE
];
283 // Legacy16 Init memory map info
285 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
287 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
289 CHAR8 InterruptRedirectionCode
[32];
290 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
291 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
292 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
295 #elif defined (MDE_CPU_X64)
299 // Space for the code
300 // The address of Code is also the beginning of the relocated Thunk code
302 CHAR8 Code
[4096]; // ?
305 // Data for the code (cs releative)
307 DESCRIPTOR64 X64GdtDesc
; // Protected mode GDT
308 DESCRIPTOR64 X64IdtDesc
; // Protected mode IDT
313 DESCRIPTOR32 RealModeIdtDesc
;
314 DESCRIPTOR32 RealModeGdtDesc
;
317 // real-mode GDT (temporary GDT with two real mode segment descriptors)
319 GDT64 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
320 UINT64 PageMapLevel4
;
323 // A low memory stack
325 CHAR8 Stack
[LOW_STACK_SIZE
];
328 // Legacy16 Init memory map info
330 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
332 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
334 CHAR8 InterruptRedirectionCode
[32];
335 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
336 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
337 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
340 #elif defined (MDE_CPU_IPF)
344 // Space for the code
345 // The address of Code is also the beginning of the relocated Thunk code
347 CHAR8 Code
[4096]; // ?
349 // The address of the Reverse Thunk code
350 // Note that this member CONTAINS the address of the relocated reverse thunk
351 // code unlike the member variable 'Code', which IS the address of the Thunk
354 UINT32 LowReverseThunkStart
;
357 // Data for the code (cs releative)
359 DESCRIPTOR32 GdtDesc
; // Protected mode GDT
360 DESCRIPTOR32 IdtDesc
; // Protected mode IDT
364 UINT32 LowCodeSelector
; // Low code selector in GDT
365 UINT32 LowDataSelector
; // Low data selector in GDT
367 DESCRIPTOR32 RealModeIdtDesc
;
370 // real-mode GDT (temporary GDT with two real mode segment descriptors)
372 GDT32 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
373 DESCRIPTOR32 RealModeGdtDesc
;
376 // Members specifically for the reverse thunk
377 // The RevReal* members are used to store the current state of real mode
378 // before performing the reverse thunk. The RevFlat* members must be set
379 // before calling the reverse thunk assembly code.
384 DESCRIPTOR32 RevRealIdtDesc
;
385 UINT16 RevFlatDataSelector
; // Flat data selector in GDT
389 // A low memory stack
391 CHAR8 Stack
[LOW_STACK_SIZE
];
394 // Stack for flat mode after reverse thunk
395 // @bug - This may no longer be necessary if the reverse thunk interface
396 // is changed to have the flat stack in a different location.
398 CHAR8 RevThunkStack
[LOW_STACK_SIZE
];
401 // Legacy16 Init memory map info
403 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
405 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
407 CHAR8 InterruptRedirectionCode
[32];
408 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
409 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
410 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
416 // PnP Expansion Header
427 UINT16 ProductNamePointer
;
431 UINT8 DeviceIndicators
;
433 UINT16 DisconnectVector
;
436 UINT16 StaticResourceVector
;
437 } LEGACY_PNP_EXPANSION_HEADER
;
453 UINTN ManufacturerString
;
454 UINTN ProductNameString
;
455 } LEGACY_ROM_AND_BBS_TABLE
;
458 // Structure how EFI has mapped a devices HDD drive numbers.
459 // Boot to EFI aware OS or shell requires this mapping when
460 // 16-bit CSM assigns drive numbers.
461 // This mapping is ignored booting to a legacy OS.
468 UINT8 StartDriveNumber
;
469 UINT8 EndDriveNumber
;
470 } LEGACY_EFI_HDD_TABLE
;
473 // This data is passed to Leacy16Boot
476 EfiAcpiAddressRangeMemory
= 1,
477 EfiAcpiAddressRangeReserved
= 2,
478 EfiAcpiAddressRangeACPI
= 3,
479 EfiAcpiAddressRangeNVS
= 4
480 } EFI_ACPI_MEMORY_TYPE
;
485 EFI_ACPI_MEMORY_TYPE Type
;
493 EFI_ACPI_MEMORY_TYPE Type
;
498 extern BBS_TABLE
*mBbsTable
;
500 extern EFI_GENERIC_MEMORY_TEST_PROTOCOL
*gGenMemoryTest
;
505 #define CMOS_0A 0x0a ///< Status register A
506 #define CMOS_0D 0x0d ///< Status register D
507 #define CMOS_0E 0x0e ///< Diagnostic Status
508 #define CMOS_0F 0x0f ///< Shutdown status
509 #define CMOS_10 0x10 ///< Floppy type
510 #define CMOS_12 0x12 ///< IDE type
511 #define CMOS_14 0x14 ///< Same as BDA 40:10
512 #define CMOS_15 0x15 ///< Low byte of base memory in 1k increments
513 #define CMOS_16 0x16 ///< High byte of base memory in 1k increments
514 #define CMOS_17 0x17 ///< Low byte of 1MB+ memory in 1k increments - max 15 MB
515 #define CMOS_18 0x18 ///< High byte of 1MB+ memory in 1k increments - max 15 MB
516 #define CMOS_19 0x19 ///< C: extended drive type
517 #define CMOS_1A 0x1a ///< D: extended drive type
518 #define CMOS_2E 0x2e ///< Most significient byte of standard checksum
519 #define CMOS_2F 0x2f ///< Least significient byte of standard checksum
520 #define CMOS_30 0x30 ///< CMOS 0x17
521 #define CMOS_31 0x31 ///< CMOS 0x18
522 #define CMOS_32 0x32 ///< Century byte
525 // 8254 Timer registers
527 #define TIMER0_COUNT_PORT 0x40
528 #define TIMER1_COUNT_PORT 0x41
529 #define TIMER2_COUNT_PORT 0x42
530 #define TIMER_CONTROL_PORT 0x43
533 // Timer 0, Read/Write LSB then MSB, Square wave output, binary count use.
535 #define TIMER0_CONTROL_WORD 0x36
537 #define LEGACY_BIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('L', 'B', 'I', 'T')
542 EFI_LEGACY_BIOS_PROTOCOL LegacyBios
;
544 EFI_HANDLE ImageHandle
;
547 // CPU Architectural Protocol
549 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
552 // Timer Architectural Protocol
554 EFI_TIMER_ARCH_PROTOCOL
*Timer
;
555 BOOLEAN TimerUses8254
;
558 // Protocol to Lock and Unlock 0xc0000 - 0xfffff
560 EFI_LEGACY_REGION2_PROTOCOL
*LegacyRegion
;
562 EFI_LEGACY_BIOS_PLATFORM_PROTOCOL
*LegacyBiosPlatform
;
565 // Interrupt control for thunk and PCI IRQ
567 EFI_LEGACY_8259_PROTOCOL
*Legacy8259
;
570 // PCI Interrupt PIRQ control
572 EFI_LEGACY_INTERRUPT_PROTOCOL
*LegacyInterrupt
;
575 // Generic Memory Test
577 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenericMemoryTest
;
580 // TRUE if PCI Interupt Line registers have been programmed.
582 BOOLEAN PciInterruptLine
;
585 // Code space below 1MB needed by thunker to transition to real mode.
586 // Contains stack and real mode code fragments
588 LOW_MEMORY_THUNK
*IntThunk
;
591 // Starting shadow address of the Legacy BIOS
594 UINT32 LegacyBiosImageSize
;
597 // Start of variables used by CsmItp.mac ITP macro file and/os LegacyBios
602 // $EFI Legacy16 code entry info in memory < 1 MB;
604 EFI_COMPATIBILITY16_TABLE
*Legacy16Table
;
605 VOID
*Legacy16InitPtr
;
606 VOID
*Legacy16BootPtr
;
607 VOID
*InternalIrqRoutingTable
;
608 UINT32 NumberIrqRoutingEntries
;
611 UINT32 NumberHddControllers
;
614 // Cached copy of Legacy16 entry point
616 UINT16 Legacy16CallSegment
;
617 UINT16 Legacy16CallOffset
;
620 // Returned from $EFI and passed in to OPROMS
622 UINT16 PnPInstallationCheckSegment
;
623 UINT16 PnPInstallationCheckOffset
;
628 EFI_E820_ENTRY E820Table
[EFI_MAX_E820_ENTRY
];
629 UINT32 NumberE820Entries
;
632 // True if legacy VGA INT 10h handler installed
634 BOOLEAN VgaInstalled
;
637 // Number of IDE drives
642 // Current Free Option ROM space. An option ROM must NOT go past
648 // Save Legacy16 unexpected interrupt vector. Reprogram INT 68-6F from
649 // EFI values to legacy value just before boot.
651 UINT32 BiosUnexpectedInt
;
652 UINT32 ThunkSavedInt
[8];
654 LEGACY_EFI_HDD_TABLE
*LegacyEfiHddTable
;
655 UINT16 LegacyEfiHddTableIndex
;
662 // Indicate that whether GenericLegacyBoot is entered or not
664 BOOLEAN LegacyBootEntered
;
667 // CSM16 PCI Interface Version
669 UINT16 Csm16PciInterfaceVersion
;
671 } LEGACY_BIOS_INSTANCE
;
684 40:0E-0E Ebda segment
685 40:10-11 MachineConfig
687 40:13-14 MemSize below 1MB
688 40:15-16 Bda15_16 - skip
689 40:17 Keyboard Shift status
690 40:18-19 Bda18_19 - skip
691 40:1A-1B Key buffer head
692 40:1C-1D Key buffer tail
693 40:1E-3D Bda1E_3D- key buffer -skip
694 40:3E-3F FloppyData 3E = Calibration status 3F = Motor status
696 40:41-74 Bda41_74 - skip
697 40:75 Number of HDD drives
698 40:76-77 Bda76_77 - skip
699 40:78-79 78 = Lpt1 timeout, 79 = Lpt2 timeout
700 40:7A-7B 7A = Lpt3 timeout, 7B = Lpt4 timeout
701 40:7C-7D 7C = Com1 timeout, 7D = Com2 timeout
702 40:7E-7F 7E = Com3 timeout, 7F = Com4 timeout
703 40:80-81 Pointer to start of key buffer
704 40:82-83 Pointer to end of key buffer
705 40:84-87 Bda84_87 - skip
706 40:88 HDD Data Xmit rate
708 40:90 Floppy data rate
710 40:96 Keyboard Status
723 UINT16 MachineConfig
;
726 UINT8 Bda15_16
[0x02];
728 UINT8 Bda18_19
[0x02];
731 UINT16 Bda1E_3D
[0x10];
734 UINT8 Bda41_74
[0x34];
735 UINT8 NumberOfDrives
;
736 UINT8 Bda76_77
[0x02];
737 UINT16 Lpt1_2Timeout
;
738 UINT16 Lpt3_4Timeout
;
739 UINT16 Com1_2Timeout
;
740 UINT16 Com3_4Timeout
;
745 UINT8 Bda89_8F
[0x07];
747 UINT8 Bda91_95
[0x05];
748 UINT8 KeyboardStatus
;
753 #define LEGACY_BIOS_INSTANCE_FROM_THIS(this) CR (this, LEGACY_BIOS_INSTANCE, LegacyBios, LEGACY_BIOS_INSTANCE_SIGNATURE)
756 Thunk to 16-bit real mode and execute a software interrupt with a vector
757 of BiosInt. Regs will contain the 16-bit register context on entry and
760 @param This Protocol instance pointer.
761 @param BiosInt Processor interrupt vector to invoke
762 @param Regs Register contexted passed into (and returned) from thunk to
765 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
767 @retval TRUE There was a BIOS erro in the target code.
773 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
775 IN EFI_IA32_REGISTER_SET
*Regs
780 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
781 16-bit register context on entry and exit. Arguments can be passed on
784 @param This Protocol instance pointer.
785 @param Segment Segemnt of 16-bit mode call
786 @param Offset Offset of 16-bit mdoe call
787 @param Regs Register contexted passed into (and returned) from
789 @param Stack Caller allocated stack used to pass arguments
790 @param StackSize Size of Stack in bytes
792 @retval FALSE Thunk completed, and there were no BIOS errors in
793 the target code. See Regs for status.
794 @retval TRUE There was a BIOS erro in the target code.
799 LegacyBiosFarCall86 (
800 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
803 IN EFI_IA32_REGISTER_SET
*Regs
,
810 Test to see if a legacy PCI ROM exists for this device. Optionally return
811 the Legacy ROM instance for this PCI device.
813 @param This Protocol instance pointer.
814 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
816 @param RomImage Return the legacy PCI ROM for this device
817 @param RomSize Size of ROM Image
818 @param Flags Indicates if ROM found and if PC-AT.
820 @retval EFI_SUCCESS Legacy Option ROM availible for this device
821 @retval EFI_UNSUPPORTED Legacy Option ROM not supported.
826 LegacyBiosCheckPciRom (
827 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
828 IN EFI_HANDLE PciHandle
,
829 OUT VOID
**RomImage
, OPTIONAL
830 OUT UINTN
*RomSize
, OPTIONAL
836 Assign drive number to legacy HDD drives prior to booting an EFI
837 aware OS so the OS can access drives without an EFI driver.
838 Note: BBS compliant drives ARE NOT available until this call by
841 @param This Protocol instance pointer.
842 @param BbsCount Number of BBS_TABLE structures
843 @param BbsTable List BBS entries
845 @retval EFI_SUCCESS Drive numbers assigned
850 LegacyBiosPrepareToBootEfi (
851 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
852 OUT UINT16
*BbsCount
,
853 OUT BBS_TABLE
**BbsTable
858 To boot from an unconventional device like parties and/or execute
861 @param This Protocol instance pointer.
862 @param Attributes How to interpret the other input parameters
863 @param BbsEntry The 0-based index into the BbsTable for the parent
865 @param BeerData Pointer to the 128 bytes of ram BEER data.
866 @param ServiceAreaData Pointer to the 64 bytes of raw Service Area data.
867 The caller must provide a pointer to the specific
868 Service Area and not the start all Service Areas.
869 EFI_INVALID_PARAMETER if error. Does NOT return if no error.
874 LegacyBiosBootUnconventionalDevice (
875 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
876 IN UDC_ATTRIBUTES Attributes
,
879 IN VOID
*ServiceAreaData
884 Load a legacy PC-AT OPROM on the PciHandle device. Return information
885 about how many disks were added by the OPROM and the shadow address and
886 size. DiskStart & DiskEnd are INT 13h drive letters. Thus 0x80 is C:
888 @param This Protocol instance pointer.
889 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
890 be loaded. This value is NULL if RomImage is
891 non-NULL. This is the normal case.
892 @param RomImage A PCI PC-AT ROM image. This argument is non-NULL
893 if there is no hardware associated with the ROM
894 and thus no PciHandle, otherwise is must be NULL.
895 Example is PXE base code.
896 @param Flags Indicates if ROM found and if PC-AT.
897 @param DiskStart Disk number of first device hooked by the ROM. If
898 DiskStart is the same as DiskEnd no disked were
900 @param DiskEnd Disk number of the last device hooked by the ROM.
901 @param RomShadowAddress Shadow address of PC-AT ROM
902 @param RomShadowedSize Size of RomShadowAddress in bytes
904 @retval EFI_SUCCESS Legacy ROM loaded for this device
905 @retval EFI_INVALID_PARAMETER PciHandle not found
906 @retval EFI_UNSUPPORTED There is no PCI ROM in the ROM BAR or no onboard
912 LegacyBiosInstallPciRom (
913 IN EFI_LEGACY_BIOS_PROTOCOL
* This
,
914 IN EFI_HANDLE PciHandle
,
917 OUT UINT8
*DiskStart
, OPTIONAL
918 OUT UINT8
*DiskEnd
, OPTIONAL
919 OUT VOID
**RomShadowAddress
, OPTIONAL
920 OUT UINT32
*RomShadowedSize OPTIONAL
925 Fill in the standard BDA for Keyboard LEDs
927 @param This Protocol instance pointer.
928 @param Leds Current LED status
930 @retval EFI_SUCCESS It should always work.
935 LegacyBiosUpdateKeyboardLedStatus (
936 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
944 @param This Protocol instance pointer.
945 @param HddCount Number of HDD_INFO structures
946 @param HddInfo Onboard IDE controller information
947 @param BbsCount Number of BBS_TABLE structures
948 @param BbsTable List BBS entries
950 @retval EFI_SUCCESS Tables returned
951 @retval EFI_NOT_FOUND resource not found
952 @retval EFI_DEVICE_ERROR can not get BBS table
957 LegacyBiosGetBbsInfo (
958 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
959 OUT UINT16
*HddCount
,
960 OUT HDD_INFO
**HddInfo
,
961 OUT UINT16
*BbsCount
,
962 OUT BBS_TABLE
**BbsTable
967 Shadow all legacy16 OPROMs that haven't been shadowed.
968 Warning: Use this with caution. This routine disconnects all EFI
969 drivers. If used externally then caller must re-connect EFI
972 @param This Protocol instance pointer.
974 @retval EFI_SUCCESS OPROMs shadowed
979 LegacyBiosShadowAllLegacyOproms (
980 IN EFI_LEGACY_BIOS_PROTOCOL
*This
985 Attempt to legacy boot the BootOption. If the EFI contexted has been
986 compromised this function will not return.
988 @param This Protocol instance pointer.
989 @param BbsDevicePath EFI Device Path from BootXXXX variable.
990 @param LoadOptionsSize Size of LoadOption in size.
991 @param LoadOptions LoadOption from BootXXXX variable
993 @retval EFI_SUCCESS Removable media not present
998 LegacyBiosLegacyBoot (
999 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1000 IN BBS_BBS_DEVICE_PATH
*BbsDevicePath
,
1001 IN UINT32 LoadOptionsSize
,
1002 IN VOID
*LoadOptions
1007 Allocate memory < 1 MB and copy the thunker code into low memory. Se up
1008 all the descriptors.
1010 @param Private Private context for Legacy BIOS
1012 @retval EFI_SUCCESS Should only pass.
1016 LegacyBiosInitializeThunk (
1017 IN LEGACY_BIOS_INSTANCE
*Private
1022 Fill in the standard BDA and EBDA stuff before Legacy16 load
1024 @param Private Legacy BIOS Instance data
1026 @retval EFI_SUCCESS It should always work.
1031 IN LEGACY_BIOS_INSTANCE
*Private
1036 Collect IDE Inquiry data from the IDE disks
1038 @param Private Legacy BIOS Instance data
1039 @param HddInfo Hdd Information
1040 @param Flag Reconnect IdeController or not
1042 @retval EFI_SUCCESS It should always work.
1046 LegacyBiosBuildIdeData (
1047 IN LEGACY_BIOS_INSTANCE
*Private
,
1048 IN HDD_INFO
**HddInfo
,
1054 Enable ide controller. This gets disabled when LegacyBoot.c is about
1055 to run the Option ROMs.
1057 @param Private Legacy BIOS Instance data
1062 EnableIdeController (
1063 IN LEGACY_BIOS_INSTANCE
*Private
1068 If the IDE channel is in compatibility (legacy) mode, remove all
1069 PCI I/O BAR addresses from the controller.
1071 @param IdeController The handle of target IDE controller
1076 InitLegacyIdeController (
1077 IN EFI_HANDLE IdeController
1082 Program the interrupt routing register in all the PCI devices. On a PC AT system
1083 this register contains the 8259 IRQ vector that matches it's PCI interrupt.
1085 @param Private Legacy BIOS Instance data
1087 @retval EFI_SUCCESS Succeed.
1088 @retval EFI_ALREADY_STARTED All PCI devices have been processed.
1092 PciProgramAllInterruptLineRegisters (
1093 IN LEGACY_BIOS_INSTANCE
*Private
1098 Collect EFI Info about legacy devices.
1100 @param Private Legacy BIOS Instance data
1102 @retval EFI_SUCCESS It should always work.
1106 LegacyBiosBuildSioData (
1107 IN LEGACY_BIOS_INSTANCE
*Private
1112 Shadow all the PCI legacy ROMs. Use data from the Legacy BIOS Protocol
1113 to chose the order. Skip any devices that have already have legacy
1116 @param Private Protocol instance pointer.
1118 @retval EFI_SUCCESS Succeed.
1119 @retval EFI_UNSUPPORTED Cannot get VGA device handle.
1124 IN LEGACY_BIOS_INSTANCE
*Private
1129 Fill in the standard BDA and EBDA stuff prior to legacy Boot
1131 @param Private Legacy BIOS Instance data
1133 @retval EFI_SUCCESS It should always work.
1137 LegacyBiosCompleteBdaBeforeBoot (
1138 IN LEGACY_BIOS_INSTANCE
*Private
1143 Fill in the standard CMOS stuff before Legacy16 load
1145 @param Private Legacy BIOS Instance data
1147 @retval EFI_SUCCESS It should always work.
1151 LegacyBiosInitCmos (
1152 IN LEGACY_BIOS_INSTANCE
*Private
1157 Fill in the standard CMOS stuff prior to legacy Boot
1159 @param Private Legacy BIOS Instance data
1161 @retval EFI_SUCCESS It should always work.
1165 LegacyBiosCompleteStandardCmosBeforeBoot (
1166 IN LEGACY_BIOS_INSTANCE
*Private
1171 Contains the code that is copied into low memory (below 640K).
1172 This code reflects interrupts 0x68-0x6f to interrupts 0x08-0x0f.
1173 This template must be copied into low memory, and the IDT entries
1174 0x68-0x6F must be point to the low memory copy of this code. Each
1175 entry is 4 bytes long, so IDT entries 0x68-0x6F can be easily
1180 InterruptRedirectionTemplate (
1186 Build the E820 table.
1188 @param Private Legacy BIOS Instance data
1189 @param Size Size of E820 Table
1191 @retval EFI_SUCCESS It should always work.
1195 LegacyBiosBuildE820 (
1196 IN LEGACY_BIOS_INSTANCE
*Private
,
1201 This function is to put all AP in halt state.
1203 @param Private Legacy BIOS Instance data
1208 IN LEGACY_BIOS_INSTANCE
*Private
1212 Worker function for LegacyBiosGetFlatDescs, retrieving content of
1215 @param IntThunk Pointer to IntThunk of Legacy BIOS context.
1220 LOW_MEMORY_THUNK
*IntThunk
1224 Routine for calling real thunk code.
1226 @param RealCode The address of thunk code.
1227 @param BiosInt The Bios interrupt vector number.
1228 @param CallAddress The address of 16-bit mode call.
1230 @return Status returned by real thunk code
1241 Routine for generating soft interrupt.
1243 @param Vector The interrupt vector number.
1252 Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode
1255 @param AllocateType Allocated Legacy Memory Type
1256 @param StartPageAddress Start address of range
1257 @param Pages Number of pages to allocate
1258 @param Result Result of allocation
1260 @retval EFI_SUCCESS Legacy16 code loaded
1261 @retval Other No protocol installed, unload driver.
1265 AllocateLegacyMemory (
1266 IN EFI_ALLOCATE_TYPE AllocateType
,
1267 IN EFI_PHYSICAL_ADDRESS StartPageAddress
,
1269 OUT EFI_PHYSICAL_ADDRESS
*Result
1273 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1275 @param This Protocol instance pointer.
1276 @param LegacyMemorySize Size of required region
1277 @param Region Region to use. 00 = Either 0xE0000 or 0xF0000
1278 block Bit0 = 1 0xF0000 block Bit1 = 1 0xE0000
1280 @param Alignment Address alignment. Bit mapped. First non-zero
1281 bit from right is alignment.
1282 @param LegacyMemoryAddress Region Assigned
1284 @retval EFI_SUCCESS Region assigned
1285 @retval EFI_ACCESS_DENIED Procedure previously invoked
1286 @retval Other Region not assigned
1291 LegacyBiosGetLegacyRegion (
1292 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1293 IN UINTN LegacyMemorySize
,
1296 OUT VOID
**LegacyMemoryAddress
1300 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1302 @param This Protocol instance pointer.
1303 @param LegacyMemorySize Size of data to copy
1304 @param LegacyMemoryAddress Legacy Region destination address Note: must
1305 be in region assigned by
1306 LegacyBiosGetLegacyRegion
1307 @param LegacyMemorySourceAddress Source of data
1309 @retval EFI_SUCCESS Region assigned
1310 @retval EFI_ACCESS_DENIED Destination outside assigned region
1315 LegacyBiosCopyLegacyRegion (
1316 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1317 IN UINTN LegacyMemorySize
,
1318 IN VOID
*LegacyMemoryAddress
,
1319 IN VOID
*LegacyMemorySourceAddress
1323 Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find
1324 the $EFI table in the shadow area. Thunk into the Legacy16 code after it had
1327 @param Private Legacy BIOS context data
1329 @retval EFI_SUCCESS Legacy16 code loaded
1330 @retval Other No protocol installed, unload driver.
1334 ShadowAndStartLegacy16 (
1335 IN LEGACY_BIOS_INSTANCE
*Private
1339 Checks the state of the floppy and if media is inserted.
1341 This routine checks the state of the floppy and if media is inserted.
1343 No floppy present - Set BBS entry to ignore
1344 Floppy present & no media - Set BBS entry to lowest priority. We cannot
1345 set it to ignore since 16-bit CSM will
1346 indicate no floppy and thus drive A: is
1347 unusable. CSM-16 will not try floppy since
1348 lowest priority and thus not incur boot
1350 Floppy present & media - Set BBS entry to some priority.
1352 @return State of floppy media
1361 Identify drive data must be updated to actual parameters before boot.
1362 This requires updating the checksum, if it exists.
1364 @param IdentifyDriveData ATA Identify Data
1365 @param Checksum checksum of the ATA Identify Data
1367 @retval EFI_SUCCESS checksum calculated
1368 @retval EFI_SECURITY_VIOLATION IdentifyData invalid
1372 CalculateIdentifyDriveChecksum (
1373 IN UINT8
*IdentifyDriveData
,
1378 Identify drive data must be updated to actual parameters before boot.
1380 @param IdentifyDriveData ATA Identify Data
1384 UpdateIdentifyDriveData (
1385 IN UINT8
*IdentifyDriveData
1389 Complete build of BBS TABLE.
1391 @param Private Legacy BIOS Instance data
1392 @param BbsTable BBS Table passed to 16-bit code
1394 @retval EFI_SUCCESS Removable media not present
1398 LegacyBiosBuildBbs (
1399 IN LEGACY_BIOS_INSTANCE
*Private
,
1400 IN BBS_TABLE
*BbsTable
1404 Read CMOS register through index/data port.
1406 @param[in] Index The index of the CMOS register to read.
1408 @return The data value from the CMOS register specified by Index.
1412 LegacyReadStandardCmos (
1417 Write CMOS register through index/data port.
1419 @param[in] Index The index of the CMOS register to write.
1420 @param[in] Value The value of CMOS register to write.
1422 @return The value written to the CMOS register specified by Index.
1426 LegacyWriteStandardCmos (
1432 Calculate the new standard CMOS checksum and write it.
1434 @param Private Legacy BIOS Instance data
1436 @retval EFI_SUCCESS Calculate 16-bit checksum successfully
1440 LegacyCalculateWriteStandardCmosChecksum (
1445 Test to see if a legacy PCI ROM exists for this device. Optionally return
1446 the Legacy ROM instance for this PCI device.
1448 @param[in] This Protocol instance pointer.
1449 @param[in] PciHandle The PCI PC-AT OPROM from this devices ROM BAR will be loaded
1450 @param[out] RomImage Return the legacy PCI ROM for this device
1451 @param[out] RomSize Size of ROM Image
1452 @param[out] RuntimeImageLength Runtime size of ROM Image
1453 @param[out] Flags Indicates if ROM found and if PC-AT.
1454 @param[out] OpromRevision Revision of the PCI Rom
1455 @param[out] ConfigUtilityCodeHeaderPointer of Configuration Utility Code Header
1457 @return EFI_SUCCESS Legacy Option ROM availible for this device
1458 @return EFI_ALREADY_STARTED This device is already managed by its Oprom
1459 @return EFI_UNSUPPORTED Legacy Option ROM not supported.
1463 LegacyBiosCheckPciRomEx (
1464 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1465 IN EFI_HANDLE PciHandle
,
1466 OUT VOID
**RomImage
, OPTIONAL
1467 OUT UINTN
*RomSize
, OPTIONAL
1468 OUT UINTN
*RuntimeImageLength
, OPTIONAL
1469 OUT UINTN
*Flags
, OPTIONAL
1470 OUT UINT8
*OpromRevision
, OPTIONAL
1471 OUT VOID
**ConfigUtilityCodeHeader OPTIONAL
1475 Relocate this image under 4G memory for IPF.
1477 @param ImageHandle Handle of driver image.
1478 @param SystemTable Pointer to system table.
1480 @retval EFI_SUCCESS Image successfully relocated.
1481 @retval EFI_ABORTED Failed to relocate image.
1485 RelocateImageUnder4GIfNeeded (
1486 IN EFI_HANDLE ImageHandle
,
1487 IN EFI_SYSTEM_TABLE
*SystemTable
1491 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
1492 16-bit register context on entry and exit. Arguments can be passed on
1495 @param This Protocol instance pointer.
1496 @param Segment Segemnt of 16-bit mode call
1497 @param Offset Offset of 16-bit mdoe call
1498 @param Regs Register contexted passed into (and returned) from thunk to
1500 @param Stack Caller allocated stack used to pass arguments
1501 @param StackSize Size of Stack in bytes
1503 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
1504 See Regs for status.
1505 @retval TRUE There was a BIOS erro in the target code.
1510 InternalLegacyBiosFarCall (
1511 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1514 IN EFI_IA32_REGISTER_SET
*Regs
,