DuetPkg: Remove DuetPkg

DuetPkg depends on Legacy BIOS to provide a UEFI environment.
It was invented in the era when UEFI environment is hard to find.
Since now UEFI is very popular in PC area, we could stop the
official support of this package and remove it from the master.
https://bugzilla.tianocore.org/show_bug.cgi?id=1322

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
This commit is contained in:
Shenglei Zhang
2018-11-30 10:30:38 +08:00
committed by Ruiyu Ni
parent 8efc6d84ca
commit 9fb5c5c4a3
172 changed files with 0 additions and 57158 deletions

View File

@@ -1,212 +0,0 @@
/*++ @file
Reset Architectural Protocol implementation.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
--*/
#include <PiDxe.h>
#include <Protocol/Reset.h>
#include <Guid/AcpiDescription.h>
#include <Library/BaseLib.h>
#include <Library/IoLib.h>
#include <Library/PciLib.h>
#include <Library/HobLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
///
/// Handle for the Reset Architectural Protocol
///
EFI_HANDLE mResetHandle = NULL;
///
/// Copy of ACPI Description HOB in runtime memory
///
EFI_ACPI_DESCRIPTION mAcpiDescription;
/**
Reset the system.
@param[in] ResetType Warm or cold
@param[in] ResetStatus Possible cause of reset
@param[in] DataSize Size of ResetData in bytes
@param[in] ResetData Optional Unicode string
**/
VOID
EFIAPI
EfiAcpiResetSystem (
IN EFI_RESET_TYPE ResetType,
IN EFI_STATUS ResetStatus,
IN UINTN DataSize,
IN VOID *ResetData OPTIONAL
)
{
UINT8 Dev;
UINT8 Func;
UINT8 Register;
switch (ResetType) {
case EfiResetShutdown:
//
// 1. Write SLP_TYPa
//
if ((mAcpiDescription.PM1a_CNT_BLK.Address != 0) && (mAcpiDescription.SLP_TYPa != 0)) {
switch (mAcpiDescription.PM1a_CNT_BLK.AddressSpaceId) {
case EFI_ACPI_3_0_SYSTEM_IO:
IoAndThenOr16 ((UINTN)mAcpiDescription.PM1a_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPa << 10)));
break;
case EFI_ACPI_3_0_SYSTEM_MEMORY:
MmioAndThenOr16 ((UINTN)mAcpiDescription.PM1a_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPa << 10)));
break;
}
}
//
// 2. Write SLP_TYPb
//
if ((mAcpiDescription.PM1b_CNT_BLK.Address != 0) && (mAcpiDescription.SLP_TYPb != 0)) {
switch (mAcpiDescription.PM1b_CNT_BLK.AddressSpaceId) {
case EFI_ACPI_3_0_SYSTEM_IO:
IoAndThenOr16 ((UINTN)mAcpiDescription.PM1b_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPb << 10)));
break;
case EFI_ACPI_3_0_SYSTEM_MEMORY:
MmioAndThenOr16 ((UINTN)mAcpiDescription.PM1b_CNT_BLK.Address, 0xc3ff, (UINT16)(0x2000 | (mAcpiDescription.SLP_TYPb << 10)));
break;
}
}
//
// If Shutdown fails, then let fall through to reset
//
case EfiResetWarm:
case EfiResetCold:
if ((mAcpiDescription.RESET_REG.Address != 0) &&
((mAcpiDescription.RESET_REG.AddressSpaceId == EFI_ACPI_3_0_SYSTEM_IO) ||
(mAcpiDescription.RESET_REG.AddressSpaceId == EFI_ACPI_3_0_SYSTEM_MEMORY) ||
(mAcpiDescription.RESET_REG.AddressSpaceId == EFI_ACPI_3_0_PCI_CONFIGURATION_SPACE))) {
//
// Use ACPI System Reset
//
switch (mAcpiDescription.RESET_REG.AddressSpaceId) {
case EFI_ACPI_3_0_SYSTEM_IO:
//
// Send reset request through I/O port register
//
IoWrite8 ((UINTN)mAcpiDescription.RESET_REG.Address, mAcpiDescription.RESET_VALUE);
//
// Halt
//
CpuDeadLoop ();
case EFI_ACPI_3_0_SYSTEM_MEMORY:
//
// Send reset request through MMIO register
//
MmioWrite8 ((UINTN)mAcpiDescription.RESET_REG.Address, mAcpiDescription.RESET_VALUE);
//
// Halt
//
CpuDeadLoop ();
case EFI_ACPI_3_0_PCI_CONFIGURATION_SPACE:
//
// Send reset request through PCI register
//
Register = (UINT8)mAcpiDescription.RESET_REG.Address;
Func = (UINT8) (RShiftU64 (mAcpiDescription.RESET_REG.Address, 16) & 0x7);
Dev = (UINT8) (RShiftU64 (mAcpiDescription.RESET_REG.Address, 32) & 0x1F);
PciWrite8 (PCI_LIB_ADDRESS (0, Dev, Func, Register), mAcpiDescription.RESET_VALUE);
//
// Halt
//
CpuDeadLoop ();
}
}
//
// If system comes here, means ACPI reset is not supported, so do Legacy System Reset, assume 8042 available
//
IoWrite8 (0x64, 0xfe);
CpuDeadLoop ();
default:
break;
}
//
// Given we should have reset getting here would be bad
//
ASSERT (FALSE);
CpuDeadLoop();
}
/**
Initialize the state information for the Reset Architectural Protocol.
@param[in] ImageHandle Image handle of the loaded driver
@param[in] SystemTable Pointer to the System Table
@retval EFI_SUCCESS Thread can be successfully created
@retval EFI_UNSUPPORTED Cannot find the info to reset system
**/
EFI_STATUS
EFIAPI
InitializeReset (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_HOB_GUID_TYPE *HobAcpiDescription;
//
// Make sure the Reset Architectural Protocol is not already installed in the system
//
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiResetArchProtocolGuid);
//
// Get ACPI Description HOB
//
HobAcpiDescription = GetFirstGuidHob (&gEfiAcpiDescriptionGuid);
if (HobAcpiDescription == NULL) {
return EFI_UNSUPPORTED;
}
//
// Copy it to Runtime Memory
//
ASSERT (sizeof (EFI_ACPI_DESCRIPTION) == GET_GUID_HOB_DATA_SIZE (HobAcpiDescription));
CopyMem (&mAcpiDescription, GET_GUID_HOB_DATA (HobAcpiDescription), sizeof (EFI_ACPI_DESCRIPTION));
DEBUG ((DEBUG_INFO, "ACPI Reset Base - %lx\n", mAcpiDescription.RESET_REG.Address));
DEBUG ((DEBUG_INFO, "ACPI Reset Value - %02x\n", (UINTN)mAcpiDescription.RESET_VALUE));
DEBUG ((DEBUG_INFO, "IAPC support - %x\n", (UINTN)(mAcpiDescription.IAPC_BOOT_ARCH)));
//
// Hook the runtime service table
//
SystemTable->RuntimeServices->ResetSystem = EfiAcpiResetSystem;
//
// Install the Reset Architectural Protocol onto a new handle
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mResetHandle,
&gEfiResetArchProtocolGuid, NULL,
NULL
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -1,47 +0,0 @@
## @file
# Component description file for AcpiResetDxe module.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = AcpiReset
FILE_GUID = 928EF6D4-72BC-4686-B57B-1EEB6ABD4F93
MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeReset
[Packages]
MdePkg/MdePkg.dec
DuetPkg/DuetPkg.dec
[LibraryClasses]
DebugLib
UefiBootServicesTableLib
UefiDriverEntryPoint
IoLib
PciLib
HobLib
BaseLib
BaseMemoryLib
[Sources]
Reset.c
[Protocols]
gEfiResetArchProtocolGuid
[Guids]
gEfiAcpiDescriptionGuid
[Depex]
TRUE

File diff suppressed because it is too large Load Diff

View File

@@ -1,504 +0,0 @@
/** @file
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _BIOS_GRAPHICS_OUTPUT_H
#define _BIOS_GRAPHICS_OUTPUT_H
#include <Uefi.h>
//
// Driver Consumed Protocol Prototypes
//
#include <Protocol/DevicePath.h>
#include <Protocol/PciIo.h>
#include <Protocol/DriverBinding.h>
#include <Protocol/ComponentName.h>
#include <Protocol/ComponentName2.h>
#include <Protocol/UgaDraw.h>
#include <Protocol/VgaMiniPort.h>
#include <Protocol/Legacy8259.h>
#include <Protocol/EdidActive.h>
#include <Protocol/EdidDiscovered.h>
#include <Protocol/DevicePath.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
#include <IndustryStandard/Pci.h>
#include "VesaBiosExtensions.h"
//
// Packed format support: The number of bits reserved for each of the colors and the actual
// position of RGB in the frame buffer is specified in the VBE Mode information
//
typedef struct {
UINT8 Position; // Position of the color
UINT8 Mask; // The number of bits expressed as a mask
} BIOS_VIDEO_COLOR_PLACEMENT;
//
// BIOS Graphics Output Graphical Mode Data
//
typedef struct {
UINT16 VbeModeNumber;
UINT16 BytesPerScanLine;
VOID *LinearFrameBuffer;
UINTN FrameBufferSize;
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
UINT32 RefreshRate;
UINT32 BitsPerPixel;
BIOS_VIDEO_COLOR_PLACEMENT Red;
BIOS_VIDEO_COLOR_PLACEMENT Green;
BIOS_VIDEO_COLOR_PLACEMENT Blue;
BIOS_VIDEO_COLOR_PLACEMENT Reserved;
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
EFI_PIXEL_BITMASK PixelBitMask;
} BIOS_VIDEO_MODE_DATA;
//
// BIOS video child handle private data Structure
//
#define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
//
// Consumed Protocols inherited from parent controller.
//
EFI_PCI_IO_PROTOCOL *PciIo;
EFI_LEGACY_8259_PROTOCOL *Legacy8259;
THUNK_CONTEXT *ThunkContext;
//
// Produced Protocols
//
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
EFI_EDID_ACTIVE_PROTOCOL EdidActive;
EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort;
//
// General fields
//
BOOLEAN VgaCompatible;
BOOLEAN ProduceGraphicsOutput;
//
// Graphics Output Protocol related fields
//
BOOLEAN HardwareNeedsStarting;
BIOS_VIDEO_MODE_DATA *ModeData;
UINT8 *LineBuffer;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *VbeFrameBuffer;
UINT8 *VgaFrameBuffer;
//
// VESA Bios Extensions related fields
//
UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB
EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks
VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB
VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 bytes. Must be allocated below 1MB
VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *VbeEdidDataBlock; // 0x80 bytes. Must be allocated below 1MB
VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *VbeCrtcInformationBlock; // 59 bytes. Must be allocated below 1MB
UINTN VbeSaveRestorePages; // Number of 4KB pages in VbeSaveRestoreBuffer
EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer; // Must be allocated below 1MB
//
// Status code
//
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
} BIOS_VIDEO_DEV;
#define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
#define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
#define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
#define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
#define EFI_SEGMENT(_Adr) (UINT16) ((UINT16) (((UINTN) (_Adr)) >> 4) & 0xf000)
#define EFI_OFFSET(_Adr) (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xffff)
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2;
//
// Driver Binding Protocol functions
//
/**
Test to see if Bios Video could be supported on the Controller.
@param This Pointer to driver binding protocol
@param Controller Controller handle to connect
@param RemainingDevicePath A pointer to the remaining portion of a device path
@retval EFI_SUCCESS This driver supports this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
BiosVideoDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
;
/**
Install Graphics Output Protocol onto VGA device handles
@param This Pointer to driver binding protocol
@param Controller Controller handle to connect
@param RemainingDevicePath A pointer to the remaining portion of a device path
@return EFI_STATUS
**/
EFI_STATUS
EFIAPI
BiosVideoDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
;
/**
Stop this driver on Controller
@param This Protocol instance pointer.
@param Controller Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed Controller.
@retval other This driver was not removed from this device.
**/
EFI_STATUS
EFIAPI
BiosVideoDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
;
//
// Private worker functions
//
/**
Check for VBE device
@param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
@retval EFI_SUCCESS VBE device found
**/
EFI_STATUS
EFIAPI
BiosVideoCheckForVbe (
IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
)
;
/**
Check for VGA device
@param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
@retval EFI_SUCCESS Standard VGA device found
**/
EFI_STATUS
EFIAPI
BiosVideoCheckForVga (
BIOS_VIDEO_DEV *BiosVideoPrivate
)
;
/**
Collect the resource from destroyed bios video device.
@param BiosVideoPrivate Video child device private data structure
**/
VOID
BiosVideoDeviceReleaseResource (
BIOS_VIDEO_DEV *BiosVideoChildPrivate
)
;
//
// BIOS Graphics Output Protocol functions
//
/**
Graphics Output protocol interface to get video mode
@param This - Protocol instance pointer.
@param ModeNumber - The mode number to return information on.
@param SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
@param Info - Caller allocated buffer that returns information about ModeNumber.
@return EFI_SUCCESS - Mode information returned.
EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
EFI_INVALID_PARAMETER - One of the input args was NULL.
**/
EFI_STATUS
EFIAPI
BiosVideoGraphicsOutputQueryMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo,
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
)
;
/**
Graphics Output protocol interface to set video mode
@param This - Protocol instance pointer.
@param ModeNumber - The mode number to be set.
@return EFI_SUCCESS - Graphics mode was changed.
EFI_DEVICE_ERROR - The device had an error and could not complete the request.
EFI_UNSUPPORTED - ModeNumber is not supported by this device.
**/
EFI_STATUS
EFIAPI
BiosVideoGraphicsOutputSetMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This,
IN UINT32 ModeNumber
)
;
/**
Graphics Output protocol instance to block transfer for VBE device
@param This - Pointer to Graphics Output protocol instance
@param BltBuffer - The data to transfer to screen
@param BltOperation - The operation to perform
@param SourceX - The X coordinate of the source for BltOperation
@param SourceY - The Y coordinate of the source for BltOperation
@param DestinationX - The X coordinate of the destination for BltOperation
@param DestinationY - The Y coordinate of the destination for BltOperation
@param Width - The width of a rectangle in the blt rectangle in pixels
@param Height - The height of a rectangle in the blt rectangle in pixels
@param Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
If a Delta of 0 is used, the entire BltBuffer will be operated on.
If a subrectangle of the BltBuffer is used, then Delta represents
the number of bytes in a row of the BltBuffer.
@return EFI_INVALID_PARAMETER - Invalid parameter passed in
EFI_SUCCESS - Blt operation success
**/
EFI_STATUS
EFIAPI
BiosVideoGraphicsOutputVbeBlt (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX,
IN UINTN SourceY,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height,
IN UINTN Delta
)
;
/**
Grahpics Output protocol instance to block transfer for VGA device
@param This Pointer to Grahpics Output protocol instance
@param BltBuffer The data to transfer to screen
@param BltOperation The operation to perform
@param SourceX The X coordinate of the source for BltOperation
@param SourceY The Y coordinate of the source for BltOperation
@param DestinationX The X coordinate of the destination for BltOperation
@param DestinationY The Y coordinate of the destination for BltOperation
@param Width The width of a rectangle in the blt rectangle in pixels
@param Height The height of a rectangle in the blt rectangle in pixels
@param Delta Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
If a Delta of 0 is used, the entire BltBuffer will be operated on.
If a subrectangle of the BltBuffer is used, then Delta represents
the number of bytes in a row of the BltBuffer.
@retval EFI_INVALID_PARAMETER Invalid parameter passed in
@retval EFI_SUCCESS Blt operation success
**/
EFI_STATUS
EFIAPI
BiosVideoGraphicsOutputVgaBlt (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX,
IN UINTN SourceY,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height,
IN UINTN Delta
)
;
//
// BIOS VGA Mini Port Protocol functions
//
/**
VgaMiniPort protocol interface to set mode
@param This Pointer to VgaMiniPort protocol instance
@param ModeNumber The index of the mode
@retval EFI_UNSUPPORTED The requested mode is not supported
@retval EFI_SUCCESS The requested mode is set successfully
**/
EFI_STATUS
EFIAPI
BiosVideoVgaMiniPortSetMode (
IN EFI_VGA_MINI_PORT_PROTOCOL *This,
IN UINTN ModeNumber
)
;
/**
Judge whether this device is VGA device.
@param PciIo Parent PciIo protocol instance pointer
@retval TRUE Is vga device
@retval FALSE Is no vga device
**/
BOOLEAN
BiosVideoIsVga (
IN EFI_PCI_IO_PROTOCOL *PciIo
)
;
//
// Standard VGA Definitions
//
#define VGA_HORIZONTAL_RESOLUTION 640
#define VGA_VERTICAL_RESOLUTION 480
#define VGA_NUMBER_OF_BIT_PLANES 4
#define VGA_PIXELS_PER_BYTE 8
#define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
#define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
#define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
#define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
#define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
#define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
#define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
#define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
#define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
#define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
#define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
#define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
#define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
#define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
#define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
/**
Initialize legacy environment for BIOS INI caller.
@param ThunkContext the instance pointer of THUNK_CONTEXT
**/
VOID
InitializeBiosIntCaller (
THUNK_CONTEXT *ThunkContext
);
/**
Initialize interrupt redirection code and entries, because
IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.
Or the interrupt will lost when we do thunk.
NOTE: We do not reset 8259 vector base, because it will cause pending
interrupt lost.
@param Legacy8259 Instance pointer for EFI_LEGACY_8259_PROTOCOL.
**/
VOID
InitializeInterruptRedirection (
IN EFI_LEGACY_8259_PROTOCOL *Legacy8259
);
/**
Thunk to 16-bit real mode and execute a software interrupt with a vector
of BiosInt. Regs will contain the 16-bit register context on entry and
exit.
@param This Protocol instance pointer.
@param BiosInt Processor interrupt vector to invoke
@param Reg Register contexted passed into (and returned) from thunk to 16-bit mode
@retval TRUE Thunk completed, and there were no BIOS errors in the target code.
See Regs for status.
@retval FALSE There was a BIOS erro in the target code.
**/
BOOLEAN
EFIAPI
LegacyBiosInt86 (
IN BIOS_VIDEO_DEV *BiosDev,
IN UINT8 BiosInt,
IN IA32_REGISTER_SET *Regs
);
#endif

View File

@@ -1,50 +0,0 @@
## @file
# This module provides EFI_GRAPHIC_OUT_PROTOCOL based on functions of video
# on legacy BIOS.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = BiosVideo
FILE_GUID = 29CF55F8-B675-4f5d-8F2F-B87A3ECFD063
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = BiosVideoDriverEntryPoint
[Packages]
MdePkg/MdePkg.dec
IntelFrameworkPkg/IntelFrameworkPkg.dec
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
DuetPkg/DuetPkg.dec
[LibraryClasses]
UefiLib
DebugLib
UefiBootServicesTableLib
BaseMemoryLib
UefiDriverEntryPoint
DevicePathLib
[Sources]
BiosVideo.h
BiosVideo.c
ComponentName.c
VesaBiosExtensions.h
LegacyBiosThunk.c
[Protocols]
gEfiPciIoProtocolGuid
gEfiVgaMiniPortProtocolGuid
gEfiLegacy8259ProtocolGuid
gEfiEdidDiscoveredProtocolGuid
gEfiEdidActiveProtocolGuid

View File

@@ -1,166 +0,0 @@
/*++
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ComponentName.c
Abstract:
--*/
#include "BiosVideo.h"
EFI_STATUS
EFIAPI
BiosVideoComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
BiosVideoComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName = {
BiosVideoComponentNameGetDriverName,
BiosVideoComponentNameGetControllerName,
"eng"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) BiosVideoComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) BiosVideoComponentNameGetControllerName,
"en"
};
static EFI_UNICODE_STRING_TABLE mBiosVideoDriverNameTable[] = {
{
"eng;en",
L"BIOS[INT10] Video Driver"
},
{
NULL,
NULL
}
};
EFI_STATUS
EFIAPI
BiosVideoComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
/*++
Routine Description:
Retrieves a Unicode string that is the user readable name of the EFI Driver.
Arguments:
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
Language - A pointer to a three character ISO 639-2 language identifier.
This is the language of the driver name that that the caller
is requesting, and it must match one of the languages specified
in SupportedLanguages. The number of languages supported by a
driver is up to the driver writer.
DriverName - A pointer to the Unicode string to return. This Unicode string
is the name of the driver specified by This in the language
specified by Language.
Returns:
EFI_SUCCESS - The Unicode string for the Driver specified by This
and the language specified by Language was returned
in DriverName.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - DriverName is NULL.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
--*/
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mBiosVideoDriverNameTable,
DriverName,
(BOOLEAN)(This == &gBiosVideoComponentName)
);
}
EFI_STATUS
EFIAPI
BiosVideoComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
/*++
Routine Description:
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by an EFI Driver.
Arguments:
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
ControllerHandle - The handle of a controller that the driver specified by
This is managing. This handle specifies the controller
whose name is to be returned.
ChildHandle - The handle of the child controller to retrieve the name
of. This is an optional parameter that may be NULL. It
will be NULL for device drivers. It will also be NULL
for a bus drivers that wish to retrieve the name of the
bus controller. It will not be NULL for a bus driver
that wishes to retrieve the name of a child controller.
Language - A pointer to a three character ISO 639-2 language
identifier. This is the language of the controller name
that that the caller is requesting, and it must match one
of the languages specified in SupportedLanguages. The
number of languages supported by a driver is up to the
driver writer.
ControllerName - A pointer to the Unicode string to return. This Unicode
string is the name of the controller specified by
ControllerHandle and ChildHandle in the language specified
by Language from the point of view of the driver specified
by This.
Returns:
EFI_SUCCESS - The Unicode string for the user readable name in the
language specified by Language for the driver
specified by This was returned in DriverName.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - ControllerName is NULL.
EFI_UNSUPPORTED - The driver specified by This is not currently managing
the controller specified by ControllerHandle and
ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
--*/
{
return EFI_UNSUPPORTED;
}

View File

@@ -1,220 +0,0 @@
/** @file
Provide legacy thunk interface for accessing Bios Video Rom.
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "BiosVideo.h"
#define EFI_CPU_EFLAGS_IF 0x200
/**
Initialize legacy environment for BIOS INI caller.
@param ThunkContext the instance pointer of THUNK_CONTEXT
**/
VOID
InitializeBiosIntCaller (
THUNK_CONTEXT *ThunkContext
)
{
EFI_STATUS Status;
UINT32 RealModeBufferSize;
UINT32 ExtraStackSize;
EFI_PHYSICAL_ADDRESS LegacyRegionBase;
UINT32 LegacyRegionSize;
//
// Get LegacyRegion
//
AsmGetThunk16Properties (&RealModeBufferSize, &ExtraStackSize);
LegacyRegionSize = (((RealModeBufferSize + ExtraStackSize) / EFI_PAGE_SIZE) + 1) * EFI_PAGE_SIZE;
LegacyRegionBase = 0x100000;
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiACPIMemoryNVS,
EFI_SIZE_TO_PAGES(LegacyRegionSize),
&LegacyRegionBase
);
ASSERT_EFI_ERROR (Status);
ThunkContext->RealModeBuffer = (VOID*)(UINTN)LegacyRegionBase;
ThunkContext->RealModeBufferSize = LegacyRegionSize;
ThunkContext->ThunkAttributes = THUNK_ATTRIBUTE_BIG_REAL_MODE|THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15;
AsmPrepareThunk16(ThunkContext);
}
/**
Initialize interrupt redirection code and entries, because
IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.
Or the interrupt will lost when we do thunk.
NOTE: We do not reset 8259 vector base, because it will cause pending
interrupt lost.
@param Legacy8259 Instance pointer for EFI_LEGACY_8259_PROTOCOL.
**/
VOID
InitializeInterruptRedirection (
IN EFI_LEGACY_8259_PROTOCOL *Legacy8259
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS LegacyRegionBase;
UINTN LegacyRegionLength;
UINT32 *IdtArray;
UINTN Index;
UINT8 ProtectedModeBaseVector;
UINT32 InterruptRedirectionCode[] = {
0x90CF08CD, // INT8; IRET; NOP
0x90CF09CD, // INT9; IRET; NOP
0x90CF0ACD, // INTA; IRET; NOP
0x90CF0BCD, // INTB; IRET; NOP
0x90CF0CCD, // INTC; IRET; NOP
0x90CF0DCD, // INTD; IRET; NOP
0x90CF0ECD, // INTE; IRET; NOP
0x90CF0FCD // INTF; IRET; NOP
};
//
// Get LegacyRegion
//
LegacyRegionLength = sizeof(InterruptRedirectionCode);
LegacyRegionBase = 0x100000;
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiACPIMemoryNVS,
EFI_SIZE_TO_PAGES(LegacyRegionLength),
&LegacyRegionBase
);
ASSERT_EFI_ERROR (Status);
//
// Copy code to legacy region
//
CopyMem ((VOID *)(UINTN)LegacyRegionBase, InterruptRedirectionCode, sizeof (InterruptRedirectionCode));
//
// Get VectorBase, it should be 0x68
//
Status = Legacy8259->GetVector (Legacy8259, Efi8259Irq0, &ProtectedModeBaseVector);
ASSERT_EFI_ERROR (Status);
//
// Patch IVT 0x68 ~ 0x6f
//
IdtArray = (UINT32 *) 0;
for (Index = 0; Index < 8; Index++) {
IdtArray[ProtectedModeBaseVector + Index] = ((EFI_SEGMENT (LegacyRegionBase + Index * 4)) << 16) | (EFI_OFFSET (LegacyRegionBase + Index * 4));
}
return ;
}
/**
Thunk to 16-bit real mode and execute a software interrupt with a vector
of BiosInt. Regs will contain the 16-bit register context on entry and
exit.
@param This Protocol instance pointer.
@param BiosInt Processor interrupt vector to invoke
@param Reg Register contexted passed into (and returned) from thunk to 16-bit mode
@retval TRUE Thunk completed, and there were no BIOS errors in the target code.
See Regs for status.
@retval FALSE There was a BIOS erro in the target code.
**/
BOOLEAN
EFIAPI
LegacyBiosInt86 (
IN BIOS_VIDEO_DEV *BiosDev,
IN UINT8 BiosInt,
IN IA32_REGISTER_SET *Regs
)
{
UINTN Status;
IA32_REGISTER_SET ThunkRegSet;
BOOLEAN Ret;
UINT16 *Stack16;
BOOLEAN Enabled;
ZeroMem (&ThunkRegSet, sizeof (ThunkRegSet));
ThunkRegSet.E.EFLAGS.Bits.Reserved_0 = 1;
ThunkRegSet.E.EFLAGS.Bits.Reserved_1 = 0;
ThunkRegSet.E.EFLAGS.Bits.Reserved_2 = 0;
ThunkRegSet.E.EFLAGS.Bits.Reserved_3 = 0;
ThunkRegSet.E.EFLAGS.Bits.IOPL = 3;
ThunkRegSet.E.EFLAGS.Bits.NT = 0;
ThunkRegSet.E.EFLAGS.Bits.IF = 1;
ThunkRegSet.E.EFLAGS.Bits.TF = 0;
ThunkRegSet.E.EFLAGS.Bits.CF = 0;
ThunkRegSet.E.EDI = Regs->E.EDI;
ThunkRegSet.E.ESI = Regs->E.ESI;
ThunkRegSet.E.EBP = Regs->E.EBP;
ThunkRegSet.E.EBX = Regs->E.EBX;
ThunkRegSet.E.EDX = Regs->E.EDX;
ThunkRegSet.E.ECX = Regs->E.ECX;
ThunkRegSet.E.EAX = Regs->E.EAX;
ThunkRegSet.E.DS = Regs->E.DS;
ThunkRegSet.E.ES = Regs->E.ES;
//
// The call to Legacy16 is a critical section to EFI
//
Enabled = SaveAndDisableInterrupts();
//
// Set Legacy16 state. 0x08, 0x70 is legacy 8259 vector bases.
//
Status = BiosDev->Legacy8259->SetMode (BiosDev->Legacy8259, Efi8259LegacyMode, NULL, NULL);
ASSERT_EFI_ERROR (Status);
Stack16 = (UINT16 *)((UINT8 *) BiosDev->ThunkContext->RealModeBuffer + BiosDev->ThunkContext->RealModeBufferSize - sizeof (UINT16));
ThunkRegSet.E.SS = (UINT16) (((UINTN) Stack16 >> 16) << 12);
ThunkRegSet.E.ESP = (UINT16) (UINTN) Stack16;
ThunkRegSet.E.Eip = (UINT16)((UINT32 *)NULL)[BiosInt];
ThunkRegSet.E.CS = (UINT16)(((UINT32 *)NULL)[BiosInt] >> 16);
BiosDev->ThunkContext->RealModeState = &ThunkRegSet;
AsmThunk16 (BiosDev->ThunkContext);
//
// Restore protected mode interrupt state
//
Status = BiosDev->Legacy8259->SetMode (BiosDev->Legacy8259, Efi8259ProtectedMode, NULL, NULL);
ASSERT_EFI_ERROR (Status);
//
// End critical section
//
SetInterruptState (Enabled);
Regs->E.EDI = ThunkRegSet.E.EDI;
Regs->E.ESI = ThunkRegSet.E.ESI;
Regs->E.EBP = ThunkRegSet.E.EBP;
Regs->E.EBX = ThunkRegSet.E.EBX;
Regs->E.EDX = ThunkRegSet.E.EDX;
Regs->E.ECX = ThunkRegSet.E.ECX;
Regs->E.EAX = ThunkRegSet.E.EAX;
Regs->E.SS = ThunkRegSet.E.SS;
Regs->E.CS = ThunkRegSet.E.CS;
Regs->E.DS = ThunkRegSet.E.DS;
Regs->E.ES = ThunkRegSet.E.ES;
CopyMem (&(Regs->E.EFLAGS), &(ThunkRegSet.E.EFLAGS), sizeof (UINT32));
Ret = (BOOLEAN) (Regs->E.EFLAGS.Bits.CF == 1);
return Ret;
}

View File

@@ -1,457 +0,0 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
VesaBiosExtensions.h
Abstract:
Revision History
--*/
#ifndef _VESA_BIOS_EXTENSIONS_H
#define _VESA_BIOS_EXTENSIONS_H
//
// Turn on byte packing of data structures
//
#pragma pack(1)
//
// VESA BIOS Extensions status codes
//
#define VESA_BIOS_EXTENSIONS_STATUS_SUCCESS 0x004f
//
// VESA BIOS Extensions Services
//
#define VESA_BIOS_EXTENSIONS_RETURN_CONTROLLER_INFORMATION 0x4f00
/*++
Routine Description:
Function 00 : Return Controller Information
Arguments:
Inputs:
AX = 0x4f00
ES:DI = Pointer to buffer to place VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK structure
Outputs:
AX = Return Status
--*/
#define VESA_BIOS_EXTENSIONS_RETURN_MODE_INFORMATION 0x4f01
/*++
Routine Description:
Function 01 : Return Mode Information
Arguments:
Inputs:
AX = 0x4f01
CX = Mode Number
ES:DI = Pointer to buffer to place VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK structure
Outputs:
AX = Return Status
--*/
#define VESA_BIOS_EXTENSIONS_SET_MODE 0x4f02
/*++
Routine Description:
Function 02 : Set Mode
Arguments:
Inputs:
AX = 0x4f02
BX = Desired mode to set
D0-D8 = Mode Number
D9-D10 = Reserved (must be 0)
D11 = 0 - Use current default refresh rate
= 1 - Use user specfieid CRTC values for refresh rate
D12-D13 = Reserved (must be 0)
D14 = 0 - Use windowed frame buffer model
= 1 - Use linear/flat frame buffer model
D15 = 0 - Clear display memory
= 1 - Don't clear display memory
ES:DI = Pointer to buffer to the VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK structure
Outputs:
AX = Return Status
--*/
#define VESA_BIOS_EXTENSIONS_RETURN_CURRENT_MODE 0x4f03
/*++
Routine Description:
Function 03 : Return Current Mode
Arguments:
Inputs:
AX = 0x4f03
Outputs:
AX = Return Status
BX = Current mode
D0-D13 = Mode Number
D14 = 0 - Windowed frame buffer model
= 1 - Linear/flat frame buffer model
D15 = 0 - Memory cleared at last mode set
= 1 - Memory not cleared at last mode set
--*/
#define VESA_BIOS_EXTENSIONS_SAVE_RESTORE_STATE 0x4f04
/*++
Routine Description:
Function 04 : Save/Restore State
Arguments:
Inputs:
AX = 0x4f03
DL = 0x00 - Return Save/Restore State buffer size
= 0x01 - Save State
= 0x02 - Restore State
CX = Requested Status
D0 = Save/Restore controller hardware state
D1 = Save/Restore BIOS data state
D2 = Save/Restore DAC state
D3 = Save/Restore Regsiter state
ES:BX = Pointer to buffer if DL=1 or DL=2
Outputs:
AX = Return Status
BX = Number of 64 byte blocks to hold the state buffer if DL=0
--*/
#define VESA_BIOS_EXTENSIONS_EDID 0x4f15
/*++
Routine Description:
Function 15 : implement VBE/DDC service
Arguments:
Inputs:
AX = 0x4f15
BL = 0x00 - Report VBE/DDC Capabilities
CX = 0x00 - Controller unit number (00 = primary controller)
ES:DI = Null pointer, must be 0:0 in version 1.0
Outputs:
AX = Return Status
BH = Approx. time in seconds, rounded up, to transfer one EDID block(128 bytes)
BL = DDC level supported
D0 = 0 DDC1 not supported
= 1 DDC1 supported
D1 = 0 DDC2 not supported
= 1 DDC2 supported
D2 = 0 Screen not blanked during data transfer
= 1 Screen blanked during data transfer
Inputs:
AX = 0x4f15
BL = 0x01 - Read EDID
CX = 0x00 - Controller unit number (00 = primary controller)
DX = 0x00 - EDID block number
ES:DI = Pointer to buffer in which the EDID block is returned
Outputs:
AX = Return Status
--*/
//
// Timing data from EDID data block
//
#define VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE 128
#define VESA_BIOS_EXTENSIONS_EDID_ESTABLISHED_TIMING_MAX_NUMBER 17
typedef struct {
UINT16 HorizontalResolution;
UINT16 VerticalResolution;
UINT16 RefreshRate;
} VESA_BIOS_EXTENSIONS_EDID_TIMING;
typedef struct {
UINT32 ValidNumber;
UINT32 Key[VESA_BIOS_EXTENSIONS_EDID_ESTABLISHED_TIMING_MAX_NUMBER];
} VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING;
typedef struct {
UINT8 Header[8]; //EDID header "00 FF FF FF FF FF FF 00"
UINT16 ManufactureName; //EISA 3-character ID
UINT16 ProductCode; //Vendor assigned code
UINT32 SerialNumber; //32-bit serial number
UINT8 WeekOfManufacture; //Week number
UINT8 YearOfManufacture; //Year
UINT8 EdidVersion; //EDID Structure Version
UINT8 EdidRevision; //EDID Structure Revision
UINT8 VideoInputDefinition;
UINT8 MaxHorizontalImageSize; //cm
UINT8 MaxVerticalImageSize; //cm
UINT8 DisplayTransferCharacteristic;
UINT8 FeatureSupport;
UINT8 RedGreenLowBits; //Rx1 Rx0 Ry1 Ry0 Gx1 Gx0 Gy1Gy0
UINT8 BlueWhiteLowBits; //Bx1 Bx0 By1 By0 Wx1 Wx0 Wy1 Wy0
UINT8 RedX; //Red-x Bits 9 - 2
UINT8 RedY; //Red-y Bits 9 - 2
UINT8 GreenX; //Green-x Bits 9 - 2
UINT8 GreenY; //Green-y Bits 9 - 2
UINT8 BlueX; //Blue-x Bits 9 - 2
UINT8 BlueY; //Blue-y Bits 9 - 2
UINT8 WhiteX; //White-x Bits 9 - 2
UINT8 WhiteY; //White-x Bits 9 - 2
UINT8 EstablishedTimings[3];
UINT8 StandardTimingIdentification[16];
UINT8 DetailedTimingDescriptions[72];
UINT8 ExtensionFlag; //Number of (optional) 128-byte EDID extension blocks to follow
UINT8 Checksum;
} VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK;
//
// Super VGA Information Block
//
typedef struct {
UINT32 VESASignature; // 'VESA' 4 byte signature
UINT16 VESAVersion; // VBE version number
UINT32 OEMStringPtr; // Pointer to OEM string
UINT32 Capabilities; // Capabilities of video card
UINT32 VideoModePtr; // Pointer to an array of 16-bit supported modes values terminated by 0xFFFF
UINT16 TotalMemory; // Number of 64kb memory blocks
UINT16 OemSoftwareRev; // VBE implementation Software revision
UINT32 OemVendorNamePtr; // VbeFarPtr to Vendor Name String
UINT32 OemProductNamePtr; // VbeFarPtr to Product Name String
UINT32 OemProductRevPtr; // VbeFarPtr to Product Revision String
UINT8 Reserved[222]; // Reserved for VBE implementation scratch area
UINT8 OemData[256]; // Data area for OEM strings. Pad to 512 byte block size
} VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK;
//
// Super VGA Information Block VESASignature values
//
#define VESA_BIOS_EXTENSIONS_VESA_SIGNATURE SIGNATURE_32 ('V', 'E', 'S', 'A')
#define VESA_BIOS_EXTENSIONS_VBE2_SIGNATURE SIGNATURE_32 ('V', 'B', 'E', '2')
//
// Super VGA Information Block VESAVersion values
//
#define VESA_BIOS_EXTENSIONS_VERSION_1_2 0x0102
#define VESA_BIOS_EXTENSIONS_VERSION_2_0 0x0200
#define VESA_BIOS_EXTENSIONS_VERSION_3_0 0x0300
//
// Super VGA Information Block Capabilities field bit defintions
//
#define VESA_BIOS_EXTENSIONS_CAPABILITY_8_BIT_DAC 0x01 // 0: DAC width is fixed at 6 bits/color
// 1: DAC width switchable to 8 bits/color
//
#define VESA_BIOS_EXTENSIONS_CAPABILITY_NOT_VGA 0x02 // 0: Controller is VGA compatible
// 1: Controller is not VGA compatible
//
#define VESA_BIOS_EXTENSIONS_CAPABILITY_NOT_NORMAL_RAMDAC 0x04 // 0: Normal RAMDAC operation
// 1: Use blank bit in function 9 to program RAMDAC
//
#define VESA_BIOS_EXTENSIONS_CAPABILITY_STEREOSCOPIC 0x08 // 0: No hardware stereoscopic signal support
// 1: Hardware stereoscopic signal support
//
#define VESA_BIOS_EXTENSIONS_CAPABILITY_VESA_EVC 0x10 // 0: Stero signaling supported via external VESA stereo connector
// 1: Stero signaling supported via VESA EVC connector
//
// Super VGA mode number bite field definitions
//
#define VESA_BIOS_EXTENSIONS_MODE_NUMBER_VESA 0x0100 // 0: Not a VESA defined VBE mode
// 1: A VESA defined VBE mode
//
#define VESA_BIOS_EXTENSIONS_MODE_NUMBER_REFRESH_CONTROL_USER 0x0800 // 0: Use current BIOS default referesh rate
// 1: Use the user specified CRTC values for refresh rate
//
#define VESA_BIOS_EXTENSIONS_MODE_NUMBER_LINEAR_FRAME_BUFFER 0x4000 // 0: Use a banked/windowed frame buffer
// 1: Use a linear/flat frame buffer
//
#define VESA_BIOS_EXTENSIONS_MODE_NUMBER_PRESERVE_MEMORY 0x8000 // 0: Clear display memory
// 1: Preseve display memory
//
// Super VGA Information Block mode list terminator value
//
#define VESA_BIOS_EXTENSIONS_END_OF_MODE_LIST 0xffff
//
// Window Function
//
typedef
VOID
(*VESA_BIOS_EXTENSIONS_WINDOW_FUNCTION) (
VOID
);
//
// Super VGA Mode Information Block
//
typedef struct {
//
// Manadory fields for all VESA Bios Extensions revisions
//
UINT16 ModeAttributes; // Mode attributes
UINT8 WinAAttributes; // Window A attributes
UINT8 WinBAttributes; // Window B attributes
UINT16 WinGranularity; // Window granularity in k
UINT16 WinSize; // Window size in k
UINT16 WinASegment; // Window A segment
UINT16 WinBSegment; // Window B segment
UINT32 WindowFunction; // Pointer to window function
UINT16 BytesPerScanLine; // Bytes per scanline
//
// Manadory fields for VESA Bios Extensions 1.2 and above
//
UINT16 XResolution; // Horizontal resolution
UINT16 YResolution; // Vertical resolution
UINT8 XCharSize; // Character cell width
UINT8 YCharSize; // Character cell height
UINT8 NumberOfPlanes; // Number of memory planes
UINT8 BitsPerPixel; // Bits per pixel
UINT8 NumberOfBanks; // Number of CGA style banks
UINT8 MemoryModel; // Memory model type
UINT8 BankSize; // Size of CGA style banks
UINT8 NumberOfImagePages; // Number of images pages
UINT8 Reserved1; // Reserved
UINT8 RedMaskSize; // Size of direct color red mask
UINT8 RedFieldPosition; // Bit posn of lsb of red mask
UINT8 GreenMaskSize; // Size of direct color green mask
UINT8 GreenFieldPosition; // Bit posn of lsb of green mask
UINT8 BlueMaskSize; // Size of direct color blue mask
UINT8 BlueFieldPosition; // Bit posn of lsb of blue mask
UINT8 RsvdMaskSize; // Size of direct color res mask
UINT8 RsvdFieldPosition; // Bit posn of lsb of res mask
UINT8 DirectColorModeInfo; // Direct color mode attributes
//
// Manadory fields for VESA Bios Extensions 2.0 and above
//
UINT32 PhysBasePtr; // Physical Address for flat memory frame buffer
UINT32 Reserved2; // Reserved
UINT16 Reserved3; // Reserved
//
// Manadory fields for VESA Bios Extensions 3.0 and above
//
UINT16 LinBytesPerScanLine; // Bytes/scan line for linear modes
UINT8 BnkNumberOfImagePages; // Number of images for banked modes
UINT8 LinNumberOfImagePages; // Number of images for linear modes
UINT8 LinRedMaskSize; // Size of direct color red mask (linear mode)
UINT8 LinRedFieldPosition; // Bit posiiton of lsb of red mask (linear modes)
UINT8 LinGreenMaskSize; // Size of direct color green mask (linear mode)
UINT8 LinGreenFieldPosition; // Bit posiiton of lsb of green mask (linear modes)
UINT8 LinBlueMaskSize; // Size of direct color blue mask (linear mode)
UINT8 LinBlueFieldPosition; // Bit posiiton of lsb of blue mask (linear modes)
UINT8 LinRsvdMaskSize; // Size of direct color reserved mask (linear mode)
UINT8 LinRsvdFieldPosition; // Bit posiiton of lsb of reserved mask (linear modes)
UINT32 MaxPixelClock; // Maximum pixel clock (in Hz) for graphics mode
UINT8 Pad[190]; // Pad to 256 byte block size
} VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK;
//
// Super VGA Mode Information Block ModeAttributes field bit defintions
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_HARDWARE 0x0001 // 0: Mode not supported in handware
// 1: Mode supported in handware
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_TTY 0x0004 // 0: TTY Output functions not supported by BIOS
// 1: TTY Output functions supported by BIOS
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_COLOR 0x0008 // 0: Monochrome mode
// 1: Color mode
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_GRAPHICS 0x0010 // 0: Text mode
// 1: Graphics mode
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NOT_VGA 0x0020 // 0: VGA compatible mode
// 1: Not a VGA compatible mode
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NOT_WINDOWED 0x0040 // 0: VGA compatible windowed memory mode
// 1: Not a VGA compatible windowed memory mode
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER 0x0080 // 0: No linear fram buffer mode available
// 1: Linear frame buffer mode available
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_DOUBLE_SCAN 0x0100 // 0: No double scan mode available
// 1: Double scan mode available
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_INTERLACED 0x0200 // 0: No interlaced mode is available
// 1: Interlaced mode is available
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NO_TRIPPLE_BUFFER 0x0400 // 0: No hardware triple buffer mode support available
// 1: Hardware triple buffer mode support available
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_STEREOSCOPIC 0x0800 // 0: No hardware steroscopic display support
// 1: Hardware steroscopic display support
//
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_DUAL_DISPLAY 0x1000 // 0: No dual display start address support
// 1: Dual display start address support
//
// Super VGA Mode Information Block WinAAttribite/WinBAttributes field bit defintions
//
#define VESA_BIOS_EXTENSIONS_WINX_ATTRIBUTE_RELOCATABLE 0x01 // 0: Single non-relocatable window only
// 1: Relocatable window(s) are supported
//
#define VESA_BIOS_EXTENSIONS_WINX_ATTRIBUTE_READABLE 0x02 // 0: Window is not readable
// 1: Window is readable
//
#define VESA_BIOS_EXTENSIONS_WINX_ATTRIBUTE_WRITABLE 0x04 // 0: Window is not writable
// 1: Window is writable
//
// Super VGA Mode Information Block DirectColorMode field bit defintions
//
#define VESA_BIOS_EXTENSIONS_DIRECT_COLOR_MODE_PROG_COLOR_RAMP 0x01 // 0: Color ram is fixed
// 1: Color ramp is programmable
//
#define VESA_BIOS_EXTENSIONS_DIRECT_COLOR_MODE_RSVD_USABLE 0x02 // 0: Bits in Rsvd field are reserved
// 1: Bits in Rsdv field are usable
//
// Super VGA Memory Models
//
typedef enum {
memPL = 3, // Planar memory model
memPK = 4, // Packed pixel memory model
memRGB= 6, // Direct color RGB memory model
memYUV= 7 // Direct color YUV memory model
} VESA_BIOS_EXTENSIONS_MEMORY_MODELS;
//
// Super VGA CRTC Information Block
//
typedef struct {
UINT16 HorizontalTotal; // Horizontal total in pixels
UINT16 HorizontalSyncStart; // Horizontal sync start in pixels
UINT16 HorizontalSyncEnd; // Horizontal sync end in pixels
UINT16 VericalTotal; // Vertical total in pixels
UINT16 VericalSyncStart; // Vertical sync start in pixels
UINT16 VericalSyncEnd; // Vertical sync end in pixels
UINT8 Flags; // Flags (Interlaced/DoubleScan/etc).
UINT32 PixelClock; // Pixel clock in units of Hz
UINT16 RefreshRate; // Refresh rate in units of 0.01 Hz
UINT8 Reserved[40]; // Pad
} VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK;
#define VESA_BIOS_EXTENSIONS_CRTC_FLAGS_DOUBLE_SCAN 0x01 // 0: Graphics mode is not souble scanned
// 1: Graphics mode is double scanned
//
#define VESA_BIOS_EXTENSIONS_CRTC_FLAGSINTERLACED 0x02 // 0: Graphics mode is not interlaced
// 1: Graphics mode is interlaced
//
#define VESA_BIOS_EXTENSIONS_CRTC_HORIZONTAL_SYNC_NEGATIVE 0x04 // 0: Horizontal sync polarity is positive(+)
// 0: Horizontal sync polarity is negative(-)
//
#define VESA_BIOS_EXTENSIONS_CRTC_VERITICAL_SYNC_NEGATIVE 0x08 // 0: Verical sync polarity is positive(+)
// 0: Verical sync polarity is negative(-)
//
// Turn off byte packing of data structures
//
#pragma pack()
#endif

View File

@@ -1,79 +0,0 @@
## @file
#
# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = BootSector
FILE_GUID = C89D72CE-E21A-4c71-BA79-770EF373D6DA
MODULE_TYPE = USER_DEFINED
VERSION_STRING = 1.0
CUSTOM_MAKEFILE = MSFT|Makefile
CUSTOM_MAKEFILE = GCC|GNUmakefile
[Packages]
MdePkg/MdePkg.dec
DuetPkg/DuetPkg.dec
[Sources]
bootsect.asm | INTEL
bootsect.asm | MSFT
bootsect.S | GCC
bs16.asm | INTEL
bs16.asm | MSFT
bs16.S | GCC
bs32.asm | INTEL
bs32.asm | MSFT
bs32.S | GCC
Gpt.asm | INTEL
Gpt.asm | MSFT
Gpt.S | GCC
Mbr.asm | INTEL
Mbr.asm | MSFT
Mbr.S | GCC
start.asm | INTEL
start.asm | MSFT
start.S | GCC
start16.asm | INTEL
start16.asm | MSFT
start16.S | GCC
start32.asm | INTEL
start32.asm | MSFT
start32.S | GCC
efi32.asm | INTEL
efi32.asm | MSFT
efi32.S | GCC
start64.asm | INTEL
start64.asm | MSFT
start64.S | GCC
st16_64.asm | INTEL
st16_64.asm | MSFT
st16_64.S | GCC
st32_64.asm | INTEL
st32_64.asm | MSFT
st32_64.S | GCC
efi64.asm | INTEL
efi64.asm | MSFT
efi64.S | GCC

View File

@@ -1,39 +0,0 @@
## @file
#
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
IA32
====
FAT12 FAT16 FAT32
bootsect.asm bs16.asm bs32.asm
start.asm start16.asm start32.asm
\ | /
\ | /
efi32.asm
X64
===
FAT12 FAT16 FAT32
bootsect.asm bs16.asm bs32.asm
start64.asm st16_64.asm st32_64.asm
\ | /
\ | /
efi64.asm
MBR
===
Mbr.asm
GPT
===
Gpt.asm

View File

@@ -1,140 +0,0 @@
## @file
# Just use host GCC to compile boot sector image.
#
# Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
ASM=gcc
DLINK=ld
ASSEMBLY_CODE_FILE_LIST = $(MODULE_DIR)/bootsect.S \
$(MODULE_DIR)/bs16.S \
$(MODULE_DIR)/bs32.S \
$(MODULE_DIR)/efi32.S \
$(MODULE_DIR)/efi64.S \
$(MODULE_DIR)/Gpt.S \
$(MODULE_DIR)/Mbr.S \
$(MODULE_DIR)/start.S \
$(MODULE_DIR)/start16.S \
$(MODULE_DIR)/start32.S \
$(MODULE_DIR)/start64.S \
$(MODULE_DIR)/st16_64.S \
$(MODULE_DIR)/st32_64.S
TARGET_FILES = $(OUTPUT_DIR)/bootsect.com \
$(OUTPUT_DIR)/bs16.com \
$(OUTPUT_DIR)/bs32.com \
$(OUTPUT_DIR)/Gpt.com \
$(OUTPUT_DIR)/Mbr.com \
$(OUTPUT_DIR)/start.com \
$(OUTPUT_DIR)/start16.com \
$(OUTPUT_DIR)/start32.com \
$(OUTPUT_DIR)/efi32.com2 \
$(OUTPUT_DIR)/start64.com \
$(OUTPUT_DIR)/st16_64.com \
$(OUTPUT_DIR)/st32_64.com \
$(OUTPUT_DIR)/efi64.com2
.PHONY : all
all: $(TARGET_FILES)
# bootsect.S
$(OUTPUT_DIR)/bootsect.o: $(MODULE_DIR)/bootsect.S
$(ASM) -c -o $(OUTPUT_DIR)/bootsect.o $(MODULE_DIR)/bootsect.S
$(OUTPUT_DIR)/bootsect.com: $(OUTPUT_DIR)/bootsect.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/bootsect.com $(OUTPUT_DIR)/bootsect.o -Ttext 0 -Map $(OUTPUT_DIR)/bootsect.map
# bs16.S
$(OUTPUT_DIR)/bs16.o: $(MODULE_DIR)/bs16.S
$(ASM) -c -o $(OUTPUT_DIR)/bs16.o $(MODULE_DIR)/bs16.S
$(OUTPUT_DIR)/bs16.com: $(OUTPUT_DIR)/bs16.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/bs16.com $(OUTPUT_DIR)/bs16.o -Ttext 0 -Map $(OUTPUT_DIR)/bs16.map
# bs32.S
$(OUTPUT_DIR)/bs32.o: $(MODULE_DIR)/bs32.S
$(ASM) -c -o $(OUTPUT_DIR)/bs32.o $(MODULE_DIR)/bs32.S
$(OUTPUT_DIR)/bs32.com: $(OUTPUT_DIR)/bs32.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/bs32.com $(OUTPUT_DIR)/bs32.o -Ttext 0 -Map $(OUTPUT_DIR)/bs32.map
# Gpt.S
$(OUTPUT_DIR)/Gpt.o: $(MODULE_DIR)/Gpt.S
$(ASM) -c -o $(OUTPUT_DIR)/Gpt.o $(MODULE_DIR)/Gpt.S
$(OUTPUT_DIR)/Gpt.com: $(OUTPUT_DIR)/Gpt.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/Gpt.com $(OUTPUT_DIR)/Gpt.o -Ttext 0 -Map $(OUTPUT_DIR)/Gpt.map
# Mbr.S
$(OUTPUT_DIR)/Mbr.o: $(MODULE_DIR)/Mbr.S
$(ASM) -c -o $(OUTPUT_DIR)/Mbr.o $(MODULE_DIR)/Mbr.S
$(OUTPUT_DIR)/Mbr.com: $(OUTPUT_DIR)/Mbr.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/Mbr.com $(OUTPUT_DIR)/Mbr.o -Ttext 0 -Map $(OUTPUT_DIR)/Mbr.map
# start.S
$(OUTPUT_DIR)/start.o: $(MODULE_DIR)/start.S
$(ASM) -c -o $(OUTPUT_DIR)/start.o $(MODULE_DIR)/start.S
$(OUTPUT_DIR)/start.com: $(OUTPUT_DIR)/start.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/start.com $(OUTPUT_DIR)/start.o -Ttext 0 -Map $(OUTPUT_DIR)/start.map
# start16.S
$(OUTPUT_DIR)/start16.o: $(MODULE_DIR)/start16.S
$(ASM) -c -o $(OUTPUT_DIR)/start16.o $(MODULE_DIR)/start16.S
$(OUTPUT_DIR)/start16.com: $(OUTPUT_DIR)/start16.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/start16.com $(OUTPUT_DIR)/start16.o -Ttext 0 -Map $(OUTPUT_DIR)/start16.map
# start32.S
$(OUTPUT_DIR)/start32.o: $(MODULE_DIR)/start32.S
$(ASM) -c -o $(OUTPUT_DIR)/start32.o $(MODULE_DIR)/start32.S
$(OUTPUT_DIR)/start32.com: $(OUTPUT_DIR)/start32.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/start32.com $(OUTPUT_DIR)/start32.o -Ttext 0 -Map $(OUTPUT_DIR)/start32.map
# start64.S
$(OUTPUT_DIR)/start64.o: $(MODULE_DIR)/start64.S
$(ASM) -c -o $(OUTPUT_DIR)/start64.o $(MODULE_DIR)/start64.S
$(OUTPUT_DIR)/start64.com: $(OUTPUT_DIR)/start64.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/start64.com $(OUTPUT_DIR)/start64.o -Ttext 0 -Map $(OUTPUT_DIR)/start64.map
# start16_64.S
$(OUTPUT_DIR)/st16_64.o: $(MODULE_DIR)/st16_64.S
$(ASM) -c -o $(OUTPUT_DIR)/st16_64.o $(MODULE_DIR)/st16_64.S
$(OUTPUT_DIR)/st16_64.com: $(OUTPUT_DIR)/st16_64.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/st16_64.com $(OUTPUT_DIR)/st16_64.o -Ttext 0 -Map $(OUTPUT_DIR)/st16_64.map
# start32_64.S
$(OUTPUT_DIR)/st32_64.o: $(MODULE_DIR)/st32_64.S
$(ASM) -c -o $(OUTPUT_DIR)/st32_64.o $(MODULE_DIR)/st32_64.S
$(OUTPUT_DIR)/st32_64.com: $(OUTPUT_DIR)/st32_64.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/st32_64.com $(OUTPUT_DIR)/st32_64.o -Ttext 0 -Map $(OUTPUT_DIR)/st32_64.map
# efi32.S
$(OUTPUT_DIR)/efi32.o: $(MODULE_DIR)/efi32.S
$(ASM) -c -o $(OUTPUT_DIR)/efi32.o $(MODULE_DIR)/efi32.S
$(OUTPUT_DIR)/efi32.com: $(OUTPUT_DIR)/efi32.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/efi32.com $(OUTPUT_DIR)/efi32.o -Ttext 0 -Map $(OUTPUT_DIR)/efi32.map
$(OUTPUT_DIR)/efi32.com2: $(OUTPUT_DIR)/efi32.com
Split -f $(OUTPUT_DIR)/efi32.com -p $(OUTPUT_DIR) -o efi32.com1 -p $(OUTPUT_DIR) -t efi32.com2 -s 135168
# efi64.S
$(OUTPUT_DIR)/efi64.o: $(MODULE_DIR)/efi64.S
$(ASM) -c -o $(OUTPUT_DIR)/efi64.o $(MODULE_DIR)/efi64.S
$(OUTPUT_DIR)/efi64.com: $(OUTPUT_DIR)/efi64.o
$(DLINK) --oformat binary -o $(OUTPUT_DIR)/efi64.com $(OUTPUT_DIR)/efi64.o -Ttext 0 -Map $(OUTPUT_DIR)/efi64.map
$(OUTPUT_DIR)/efi64.com2: $(OUTPUT_DIR)/efi64.com
Split -f $(OUTPUT_DIR)/efi64.com -p $(OUTPUT_DIR) -o efi64.com1 -p $(OUTPUT_DIR) -t efi64.com2 -s 135168
clean:
ifneq ($(OUTPUT_DIR), )
rm -r $(OUTPUT_DIR)
endif
ifneq ($(DEBUG_DIR), )
rm -r $(DEBUG_DIR)
endif

View File

@@ -1,297 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* gpt.asm
#*
#* Abstract:
#*
#------------------------------------------------------------------------------
#.MODEL small
# .dosseg
.stack:
.486p:
.code16
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
# ****************************************************************************
# Code loaded by BIOS at 0x0000:0x7C00
# ****************************************************************************
.org 0x00
Start:
# ****************************************************************************
# Start Print
# ****************************************************************************
movw $0xb800, %ax
movw %ax, %es
movw $0x7c0, %ax
movw %ax, %ds
leaw %cs:StartString, %si
movw $10, %cx
movw $160, %di
rep
movsw
# ****************************************************************************
# Print over
# ****************************************************************************
# ****************************************************************************
# Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
# ****************************************************************************
xorw %ax, %ax # AX = 0x0000
movw $0x7c00, %bx # BX = 0x7C00
movw $0x600, %bp # BP = 0x0600
movw RelocatedStart, %si # SI = Offset(RelocatedStart)
movw $0x200, %cx # CX = 0x0200
subw %si, %cx # CS = 0x0200 - Offset(RelocatedStart)
leaw (%bp,%si,), %di # DI = 0x0600 + Offset(RelocatedStart)
leaw (%bx,%si,), %si # BX = 0x7C00 + Offset(RelocatedStart)
movw %ax, %ss # SS = 0x0000
movw %bx, %sp # SP = 0x7C00
movw %ax, %es # ES = 0x0000
movw %ax, %ds # DS = 0x0000
pushw %ax # PUSH 0x0000
pushw %di # PUSH 0x0600 + Offset(RelocatedStart)
cld # Clear the direction flag
rep
movsb # Copy 0x0200 bytes from 0x7C00 to 0x0600
retl # JMP 0x0000:0x0600 + Offset(RelocatedStart)
# ****************************************************************************
# Code relocated to 0x0000:0x0600
# ****************************************************************************
RelocatedStart:
# ****************************************************************************
# Get Driver Parameters to 0x0000:0x7BFC
# ****************************************************************************
xorw %ax, %ax # ax = 0
movw %ax, %ss # ss = 0
addw $0x1000, %ax
movw %ax, %ds
movw $0x7c00, %sp # sp = 0x7c00
movw %sp, %bp # bp = 0x7c00
movb $8, %ah # ah = 8 - Get Drive Parameters Function
movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
int $0x13 # Get Drive Parameters
xorw %ax, %ax # ax = 0
movb %dh, %al # al = dh
incb %al # MaxHead = al + 1
pushw %ax # 0000:7bfe = MaxHead
movb %cl, %al # al = cl
andb $0x3f, %al # MaxSector = al & 0x3f
pushw %ax # 0000:7bfc = MaxSector
# ****************************************************************************
# Read GPT Header from hard disk to 0x0000:0x0800
# ****************************************************************************
xorw %ax, %ax
movw %ax, %es # Read to 0x0000:0x0800
movw $0x800, %di # Read to 0x0000:0x0800
movl $1, %eax # Read LBA #1
movl $0, %edx # Read LBA #1
movw $1, %bx # Read 1 Block
pushw %es
call ReadBlocks
popw %es
# ****************************************************************************
# Read Target GPT Entry from hard disk to 0x0000:0x0A00
# ****************************************************************************
cmpl $0x20494645, %es:(%di) # Check for "EFI "
jne BadGpt
cmpl $0x54524150, %es:4(%di) # Check for "PART"
jne BadGpt
cmpl $0x00010000, %es:8(%di) # Check Revision - 0x10000
jne BadGpt
movl %es:84(%di), %eax # EAX = SizeOfPartitionEntry
mulb GptPartitionIndicator(%bp) # EAX = SizeOfPartitionEntry * GptPartitionIndicator
movl %eax, %edx # EDX = SizeOfPartitionEntry * GptPartitionIndicator
shrl $BLOCK_SHIFT, %eax # EAX = (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE
andl $BLOCK_MASK, %edx # EDX = Targer PartitionEntryLBA Offset
# = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
pushl %edx
movl %es:72(%di), %ecx # ECX = PartitionEntryLBA (Low)
movl %es:76(%di), %ebx # EBX = PartitionEntryLBA (High)
addl %ecx, %eax # EAX = Target PartitionEntryLBA (Low)
# = (PartitionEntryLBA +
# (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE)
adcl %ebx, %edx # EDX = Target PartitionEntryLBA (High)
movw $0xA00, %di # Read to 0x0000:0x0A00
movw $1, %bx # Read 1 Block
pushw %es
call ReadBlocks
popw %es
# ****************************************************************************
# Read Target DBR from hard disk to 0x0000:0x7C00
# ****************************************************************************
popl %edx # EDX = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
addw %dx, %di # DI = Targer PartitionEntryLBA Offset
cmpl $0xC12A7328, %es:(%di) # Check for EFI System Partition "C12A7328-F81F-11d2-BA4B-00A0C93EC93B"
jne BadGpt
cmpl $0x11d2F81F, %es:4(%di) #
jne BadGpt
cmpl $0xA0004BBA, %es:8(%di) #
jne BadGpt
cmpl $0x3BC93EC9, %es:0xc(%di) #
jne BadGpt
movl %es:32(%di), %eax # EAX = StartingLBA (Low)
movl %es:36(%di), %edx # EDX = StartingLBA (High)
movw $0x7C00, %di # Read to 0x0000:0x7C00
movw $1, %bx # Read 1 Block
call ReadBlocks
# ****************************************************************************
# Transfer control to BootSector - Jump to 0x0000:0x7C00
# ****************************************************************************
xorw %ax, %ax
pushw %ax # PUSH 0x0000
movw $0x7c00, %di
pushw %di # PUSH 0x7C00
retl # JMP 0x0000:0x7C00
# ****************************************************************************
# ReadBlocks - Reads a set of blocks from a block device
#
# EDX:EAX = Start LBA
# BX = Number of Blocks to Read (must < 127)
# ES:DI = Buffer to store sectors read from disk
# ****************************************************************************
# si = DiskAddressPacket
ReadBlocks:
pushal
pushw %ds
xorw %cx, %cx
movw %cx, %ds
movw $0x600, %bp # bp = 0x600
leaw AddressPacket(%bp), %si
movb %bl, %ds:2(%si) # 02 = Number Of Block transfered
movw %di, %ds:4(%si) # 04 = Transfer Buffer Offset
movw %es, %ds:6(%si) # 06 = Transfer Buffer Segment
movl %eax, %ds:8(%si) # 08 = Starting LBA (Low)
movl %edx, %ds:0xc(%si) # 0C = Starting LBA (High)
movb $0x42, %ah # ah = Function 42
movb PhysicalDrive(%bp), %dl # dl = Drive Number
int $0x13
jc BadGpt
popw %ds
popal
ret
# ****************************************************************************
# Address Packet used by ReadBlocks
# ****************************************************************************
AddressPacket:
.byte 0x10 # Size of address packet
.byte 0x0 # Reserved. Must be 0
.byte 0x1 # Read blocks at a time (To be fixed each times)
.byte 0x0 # Reserved. Must be 0
.word 0x000 # Destination Address offset (To be fixed each times)
.word 0x000 # Destination Address segment (To be fixed each times)
AddressPacketLba:
.long 0x0,0x0 # Start LBA (To be fixed each times)
AddressPacketEnd:
# ****************************************************************************
# ERROR Condition:
# ****************************************************************************
BadGpt:
movw $0xb800, %ax
movw %ax, %es
movw $0x60, %ax
movw %ax, %ds
leaw %cs:ErrorString, %si
movw $10, %cx
movw $320, %di
rep
movsw
Halt:
jmp Halt
StartString:
.byte 'G', 0x0c, 'P', 0x0c, 'T', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
ErrorString:
.byte 'G', 0x0c, 'P', 0x0c, 'T', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
# ****************************************************************************
# PhysicalDrive - Used to indicate which disk to be boot
# Can be patched by tool
# ****************************************************************************
# .org 0x01B6 # Just for passing build.
PhysicalDrive: .byte 0x80
# ****************************************************************************
# GptPartitionIndicator - Used to indicate which GPT partition to be boot
# Can be patched by tool
# ****************************************************************************
# .org 0x01B7 # Just for passing build.
GptPartitionIndicator: .byte 0
# ****************************************************************************
# Unique MBR signature
# ****************************************************************************
# .org 0x01B8 # Just for passing build.
.ascii "DUET"
# ****************************************************************************
# Unknown
# ****************************************************************************
# .org 0x01BC # Just for passing build.
.word 0
# ****************************************************************************
# PMBR Entry - Can be patched by tool
# ****************************************************************************
# .org 0x01BE # Just for passing build.
.byte 0 # Boot Indicator
.byte 0xff # Start Header
.byte 0xff # Start Sector
.byte 0xff # Start Track
.byte 0xee # OS Type
.byte 0xff # End Header
.byte 0xff # End Sector
.byte 0xff # End Track
.long 1 # Starting LBA
.long 0xFFFFFFFF # End LBA
# .org 0x01CE # Just for passing build.
.long 0,0,0,0
# .org 0x01DE # Just for passing build.
.long 0,0,0,0
# .org 0x01EE # Just for passing build.
.long 0,0,0,0
# ****************************************************************************
# Sector Signature
# ****************************************************************************
# .org 0x01FE # Just for passing build.
SectorSignature:
.word 0xaa55 # Boot Sector Signature

View File

@@ -1,294 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* gpt.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
; .dosseg
.stack
.486p
.code
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
; ****************************************************************************
; Code loaded by BIOS at 0x0000:0x7C00
; ****************************************************************************
org 0h
Start:
; ****************************************************************************
; Start Print
; ****************************************************************************
mov ax,0b800h
mov es,ax
mov ax, 07c0h
mov ds, ax
lea si, cs:[StartString]
mov cx, 10
mov di, 160
rep movsw
; ****************************************************************************
; Print over
; ****************************************************************************
; ****************************************************************************
; Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
; ****************************************************************************
xor ax, ax ; AX = 0x0000
mov bx, 07c00h ; BX = 0x7C00
mov bp, 0600h ; BP = 0x0600
mov si, OFFSET RelocatedStart ; SI = Offset(RelocatedStart)
mov cx, 0200h ; CX = 0x0200
sub cx, si ; CS = 0x0200 - Offset(RelocatedStart)
lea di, [bp+si] ; DI = 0x0600 + Offset(RelocatedStart)
lea si, [bx+si] ; BX = 0x7C00 + Offset(RelocatedStart)
mov ss, ax ; SS = 0x0000
mov sp, bx ; SP = 0x7C00
mov es,ax ; ES = 0x0000
mov ds,ax ; DS = 0x0000
push ax ; PUSH 0x0000
push di ; PUSH 0x0600 + Offset(RelocatedStart)
cld ; Clear the direction flag
rep movsb ; Copy 0x0200 bytes from 0x7C00 to 0x0600
retf ; JMP 0x0000:0x0600 + Offset(RelocatedStart)
; ****************************************************************************
; Code relocated to 0x0000:0x0600
; ****************************************************************************
RelocatedStart:
; ****************************************************************************
; Get Driver Parameters to 0x0000:0x7BFC
; ****************************************************************************
xor ax,ax ; ax = 0
mov ss,ax ; ss = 0
add ax,1000h
mov ds,ax
mov sp,07c00h ; sp = 0x7c00
mov bp,sp ; bp = 0x7c00
mov ah,8 ; ah = 8 - Get Drive Parameters Function
mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
int 13h ; Get Drive Parameters
xor ax,ax ; ax = 0
mov al,dh ; al = dh
inc al ; MaxHead = al + 1
push ax ; 0000:7bfe = MaxHead
mov al,cl ; al = cl
and al,03fh ; MaxSector = al & 0x3f
push ax ; 0000:7bfc = MaxSector
; ****************************************************************************
; Read GPT Header from hard disk to 0x0000:0x0800
; ****************************************************************************
xor ax, ax
mov es, ax ; Read to 0x0000:0x0800
mov di, 0800h ; Read to 0x0000:0x0800
mov eax, 1 ; Read LBA #1
mov edx, 0 ; Read LBA #1
mov bx, 1 ; Read 1 Block
push es
call ReadBlocks
pop es
; ****************************************************************************
; Read Target GPT Entry from hard disk to 0x0000:0x0A00
; ****************************************************************************
cmp dword ptr es:[di], 020494645h ; Check for "EFI "
jne BadGpt
cmp dword ptr es:[di + 4], 054524150h ; Check for "PART"
jne BadGpt
cmp dword ptr es:[di + 8], 000010000h ; Check Revision - 0x10000
jne BadGpt
mov eax, dword ptr es:[di + 84] ; EAX = SizeOfPartitionEntry
mul byte ptr [bp+GptPartitionIndicator] ; EAX = SizeOfPartitionEntry * GptPartitionIndicator
mov edx, eax ; EDX = SizeOfPartitionEntry * GptPartitionIndicator
shr eax, BLOCK_SHIFT ; EAX = (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE
and edx, BLOCK_MASK ; EDX = Targer PartitionEntryLBA Offset
; = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
push edx
mov ecx, dword ptr es:[di + 72] ; ECX = PartitionEntryLBA (Low)
mov ebx, dword ptr es:[di + 76] ; EBX = PartitionEntryLBA (High)
add eax, ecx ; EAX = Target PartitionEntryLBA (Low)
; = (PartitionEntryLBA +
; (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE)
adc edx, ebx ; EDX = Target PartitionEntryLBA (High)
mov di, 0A00h ; Read to 0x0000:0x0A00
mov bx, 1 ; Read 1 Block
push es
call ReadBlocks
pop es
; ****************************************************************************
; Read Target DBR from hard disk to 0x0000:0x7C00
; ****************************************************************************
pop edx ; EDX = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
add di, dx ; DI = Targer PartitionEntryLBA Offset
cmp dword ptr es:[di], 0C12A7328h ; Check for EFI System Partition "C12A7328-F81F-11d2-BA4B-00A0C93EC93B"
jne BadGpt
cmp dword ptr es:[di + 4], 011d2F81Fh ;
jne BadGpt
cmp dword ptr es:[di + 8], 0A0004BBAh ;
jne BadGpt
cmp dword ptr es:[di + 0ch], 03BC93EC9h ;
jne BadGpt
mov eax, dword ptr es:[di + 32] ; EAX = StartingLBA (Low)
mov edx, dword ptr es:[di + 36] ; EDX = StartingLBA (High)
mov di, 07C00h ; Read to 0x0000:0x7C00
mov bx, 1 ; Read 1 Block
call ReadBlocks
; ****************************************************************************
; Transfer control to BootSector - Jump to 0x0000:0x7C00
; ****************************************************************************
xor ax, ax
push ax ; PUSH 0x0000
mov di, 07c00h
push di ; PUSH 0x7C00
retf ; JMP 0x0000:0x7C00
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; EDX:EAX = Start LBA
; BX = Number of Blocks to Read (must < 127)
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; si = DiskAddressPacket
ReadBlocks:
pushad
push ds
xor cx, cx
mov ds, cx
mov bp, 0600h ; bp = 0x600
lea si, [bp + OFFSET AddressPacket] ; DS:SI = Disk Address Packet
mov BYTE PTR ds:[si+2],bl ; 02 = Number Of Block transfered
mov WORD PTR ds:[si+4],di ; 04 = Transfer Buffer Offset
mov WORD PTR ds:[si+6],es ; 06 = Transfer Buffer Segment
mov DWORD PTR ds:[si+8],eax ; 08 = Starting LBA (Low)
mov DWORD PTR ds:[si+0ch],edx ; 0C = Starting LBA (High)
mov ah, 42h ; ah = Function 42
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
int 13h
jc BadGpt
pop ds
popad
ret
; ****************************************************************************
; Address Packet used by ReadBlocks
; ****************************************************************************
AddressPacket:
db 10h ; Size of address packet
db 00h ; Reserved. Must be 0
db 01h ; Read blocks at a time (To be fixed each times)
db 00h ; Reserved. Must be 0
dw 0000h ; Destination Address offset (To be fixed each times)
dw 0000h ; Destination Address segment (To be fixed each times)
AddressPacketLba:
dd 0h, 0h ; Start LBA (To be fixed each times)
AddressPacketEnd:
; ****************************************************************************
; ERROR Condition:
; ****************************************************************************
BadGpt:
mov ax,0b800h
mov es,ax
mov ax, 060h
mov ds, ax
lea si, cs:[ErrorString]
mov cx, 10
mov di, 320
rep movsw
Halt:
jmp Halt
StartString:
db 'G', 0ch, 'P', 0ch, 'T', 0ch, ' ', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
ErrorString:
db 'G', 0ch, 'P', 0ch, 'T', 0ch, ' ', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
; ****************************************************************************
; PhysicalDrive - Used to indicate which disk to be boot
; Can be patched by tool
; ****************************************************************************
org 01B6h
PhysicalDrive db 80h
; ****************************************************************************
; GptPartitionIndicator - Used to indicate which GPT partition to be boot
; Can be patched by tool
; ****************************************************************************
org 01B7h
GptPartitionIndicator db 0
; ****************************************************************************
; Unique MBR signature
; ****************************************************************************
org 01B8h
db 'DUET'
; ****************************************************************************
; Unknown
; ****************************************************************************
org 01BCh
dw 0
; ****************************************************************************
; PMBR Entry - Can be patched by tool
; ****************************************************************************
org 01BEh
db 0 ; Boot Indicator
db 0ffh ; Start Header
db 0ffh ; Start Sector
db 0ffh ; Start Track
db 0eeh ; OS Type
db 0ffh ; End Header
db 0ffh ; End Sector
db 0ffh ; End Track
dd 1 ; Starting LBA
dd 0FFFFFFFFh ; End LBA
org 01CEh
dd 0, 0, 0, 0
org 01DEh
dd 0, 0, 0, 0
org 01EEh
dd 0, 0, 0, 0
; ****************************************************************************
; Sector Signature
; ****************************************************************************
org 01FEh
SectorSignature:
dw 0aa55h ; Boot Sector Signature
end

View File

@@ -1,173 +0,0 @@
## @file
#
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
BASETOOLS_DIR = $(EDK_TOOLS_PATH)\Bin\Win32
#
# Build Macro
#
ASSEMBLY_CODE_FILE_LIST = $(MODULE_DIR)\bootsect.asm \
$(MODULE_DIR)\bs16.asm \
$(MODULE_DIR)\bs32.asm \
$(MODULE_DIR)\efi32.asm \
$(MODULE_DIR)\Gpt.asm \
$(MODULE_DIR)\Mbr.asm \
$(MODULE_DIR)\start.asm \
$(MODULE_DIR)\start16.asm \
$(MODULE_DIR)\start32.asm
TARGET_FILES = $(OUTPUT_DIR)\bootsect.com \
$(OUTPUT_DIR)\bs16.com \
$(OUTPUT_DIR)\bs32.com \
$(OUTPUT_DIR)\Gpt.com \
$(OUTPUT_DIR)\Mbr.com \
$(OUTPUT_DIR)\Start.com \
$(OUTPUT_DIR)\Start16.com \
$(OUTPUT_DIR)\Start32.com \
$(OUTPUT_DIR)\Start64.com \
$(OUTPUT_DIR)\St16_64.com \
$(OUTPUT_DIR)\St32_64.com \
$(OUTPUT_DIR)\efi32.com2 \
$(OUTPUT_DIR)\efi64.com2
INC =
#OBJECTS =
LIBS =
COMMON_DEPS =
all: $(TARGET_FILES)
#=============
$(OUTPUT_DIR)\bootsect.obj:$(MODULE_DIR)\bootsect.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\bootsect.obj" /FR"$(OUTPUT_DIR)\bootsect.txt" "$(MODULE_DIR)\bootsect.asm"
$(OUTPUT_DIR)\bootsect.com:$(OUTPUT_DIR)\bootsect.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\bootsect.obj,$(OUTPUT_DIR)\bootsect.com,$(OUTPUT_DIR)\bootsect.map,,,
#=============
$(OUTPUT_DIR)\bs16.obj:$(MODULE_DIR)\bs16.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\bs16.obj" "$(MODULE_DIR)\bs16.asm"
$(OUTPUT_DIR)\bs16.com:$(OUTPUT_DIR)\bs16.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\bs16.obj,$(OUTPUT_DIR)\bs16.com,$(OUTPUT_DIR)\bs16.map,,,
#=============
$(OUTPUT_DIR)\bs32.obj:$(MODULE_DIR)\bs32.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\bs32.obj" "$(MODULE_DIR)\bs32.asm"
$(OUTPUT_DIR)\bs32.com:$(OUTPUT_DIR)\bs32.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\bs32.obj,$(OUTPUT_DIR)\bs32.com,$(OUTPUT_DIR)\bs32.map,,,
#=============
$(OUTPUT_DIR)\Gpt.obj:$(MODULE_DIR)\Gpt.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Gpt.obj" "$(MODULE_DIR)\Gpt.asm"
$(OUTPUT_DIR)\Gpt.com:$(OUTPUT_DIR)\Gpt.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\Gpt.obj,$(OUTPUT_DIR)\Gpt.com,$(OUTPUT_DIR)\Gpt.map,,,
#=============
$(OUTPUT_DIR)\Mbr.obj:$(MODULE_DIR)\Mbr.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Mbr.obj" "$(MODULE_DIR)\Mbr.asm"
$(OUTPUT_DIR)\Mbr.com:$(OUTPUT_DIR)\Mbr.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\Mbr.obj,$(OUTPUT_DIR)\Mbr.com,$(OUTPUT_DIR)\Mbr.map,,,
#============
$(OUTPUT_DIR)\Start.obj:$(MODULE_DIR)\Start.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start.obj" "$(MODULE_DIR)\Start.asm"
$(OUTPUT_DIR)\Start.com:$(OUTPUT_DIR)\Start.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start.obj,$(OUTPUT_DIR)\Start.com,$(OUTPUT_DIR)\Start.map,,,
#=============
$(OUTPUT_DIR)\Start16.obj:$(MODULE_DIR)\Start16.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start16.obj" "$(MODULE_DIR)\Start16.asm"
$(OUTPUT_DIR)\Start16.com:$(OUTPUT_DIR)\Start16.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start16.obj,$(OUTPUT_DIR)\Start16.com,$(OUTPUT_DIR)\Start16.map,,,
#=============
$(OUTPUT_DIR)\Start32.obj:$(MODULE_DIR)\Start32.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start32.obj" "$(MODULE_DIR)\Start32.asm"
$(OUTPUT_DIR)\Start32.com:$(OUTPUT_DIR)\Start32.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start32.obj,$(OUTPUT_DIR)\Start32.com,$(OUTPUT_DIR)\Start32.map,,,
#=============
$(OUTPUT_DIR)\Start64.obj:$(MODULE_DIR)\Start64.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\Start64.obj" "$(MODULE_DIR)\Start64.asm"
$(OUTPUT_DIR)\Start64.com:$(OUTPUT_DIR)\Start64.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\Start64.obj,$(OUTPUT_DIR)\Start64.com,$(OUTPUT_DIR)\Start64.map,,,
#=============
$(OUTPUT_DIR)\St16_64.obj:$(MODULE_DIR)\St16_64.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\St16_64.obj" "$(MODULE_DIR)\St16_64.asm"
$(OUTPUT_DIR)\St16_64.com:$(OUTPUT_DIR)\St16_64.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\St16_64.obj,$(OUTPUT_DIR)\St16_64.com,$(OUTPUT_DIR)\St16_64.map,,,
#=============
$(OUTPUT_DIR)\St32_64.obj:$(MODULE_DIR)\St32_64.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\St32_64.obj" "$(MODULE_DIR)\St32_64.asm"
$(OUTPUT_DIR)\St32_64.com:$(OUTPUT_DIR)\St32_64.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\St32_64.obj,$(OUTPUT_DIR)\St32_64.com,$(OUTPUT_DIR)\St32_64.map,,,
#=============
$(OUTPUT_DIR)\efi32.obj:$(MODULE_DIR)\efi32.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\efi32.obj" "$(MODULE_DIR)\efi32.asm"
$(OUTPUT_DIR)\efi32.com:$(OUTPUT_DIR)\efi32.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\efi32.obj,$(OUTPUT_DIR)\efi32.com,$(OUTPUT_DIR)\efi32.map,,,
#=============
$(OUTPUT_DIR)\efi32.com2:$(OUTPUT_DIR)\efi32.com
$(BASETOOLS_DIR)\Split.exe -f $(OUTPUT_DIR)\efi32.com -t $(OUTPUT_DIR)\efi32.com2 -s 135168
#=============
$(OUTPUT_DIR)\efi64.obj:$(MODULE_DIR)\efi64.asm
"$(ASM)" /c /omf /Fo"$(OUTPUT_DIR)\efi64.obj" "$(MODULE_DIR)\efi64.asm"
$(OUTPUT_DIR)\efi64.com:$(OUTPUT_DIR)\efi64.obj
"$(ASMLINK)" /tiny $(OUTPUT_DIR)\efi64.obj,$(OUTPUT_DIR)\efi64.com,$(OUTPUT_DIR)\efi64.map,,,
#=============
$(OUTPUT_DIR)\efi64.com2:$(OUTPUT_DIR)\efi64.com
$(BASETOOLS_DIR)\Split.exe -f $(OUTPUT_DIR)\efi64.com -t $(OUTPUT_DIR)\efi64.com2 -s 135168
clean:
if exist $(DEBUG_DIR) rmdir /s /q $(DEBUG_DIR)
if exist $(OUTPUT_DIR) rmdir /s /q $(OUTPUT_DIR)

View File

@@ -1,262 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* Mbr.asm
#*
#* Abstract:
#*
#------------------------------------------------------------------------------
.code16
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
# ****************************************************************************
# Code loaded by BIOS at 0x0000:0x7C00
# ****************************************************************************
.org 0x0
.global _start
_start:
# ****************************************************************************
# Start Print
# ****************************************************************************
movw $0xb800, %ax
movw %ax, %es
movw $0x7c0, %ax
movw %ax, %ds
leaw %cs:StartString, %si
movw $10, %cx
movw $160, %di
rep
movsw
# ****************************************************************************
# Print over
# ****************************************************************************
# ****************************************************************************
# Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
# ****************************************************************************
xorw %ax, %ax # AX = 0x0000
movw $0x7c00, %bx # BX = 0x7C00
movw $0x600, %bp # BP = 0x0600
movw $RelocatedStart, %si # SI = Offset(RelocatedStart)
movw $0x200, %cx # CX = 0x0200
subw %si, %cx # CS = 0x0200 - Offset(RelocatedStart)
leaw (%bp,%si,), %di # DI = 0x0600 + Offset(RelocatedStart)
leaw (%bx,%si,), %si # BX = 0x7C00 + Offset(RelocatedStart)
movw %ax, %ss # SS = 0x0000
movw %bx, %sp # SP = 0x7C00
movw %ax, %es # ES = 0x0000
movw %ax, %ds # DS = 0x0000
pushw %ax # PUSH 0x0000
pushw %di # PUSH 0x0600 + Offset(RelocatedStart)
cld # Clear the direction flag
rep
movsb # Copy 0x0200 bytes from 0x7C00 to 0x0600
retl # JMP 0x0000:0x0600 + Offset(RelocatedStart)
# ****************************************************************************
# Code relocated to 0x0000:0x0600
# ****************************************************************************
RelocatedStart:
# ****************************************************************************
# Get Driver Parameters to 0x0000:0x7BFC
# ****************************************************************************
xorw %ax, %ax # AX = 0
movw %ax, %ss # SS = 0
addw $0x1000, %ax
movw %ax, %ds
movw $0x7c00, %sp # SP = 0x7c00
movw %sp, %bp # BP = 0x7c00
movb $8, %ah # AH = 8 - Get Drive Parameters Function
movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
int $0x13 # Get Drive Parameters
xorw %ax, %ax # AX = 0
movb %dh, %al # AL = DH
incb %al # MaxHead = AL + 1
pushw %ax # 0000:7bfe = MaxHead
movb %cl, %al # AL = CL
andb $0x3f, %al # MaxSector = AL & 0x3f
pushw %ax # 0000:7bfc = MaxSector
# ****************************************************************************
# Read Target DBR from hard disk to 0x0000:0x7C00
# ****************************************************************************
xorw %ax, %ax
movb MbrPartitionIndicator(%bp), %al # AX = MbrPartitionIndex
cmpb $0xff, %al # 0xFF means do legacy MBR boot
jnz EfiDbr
LegacyMbr:
movl $0x0000600, %eax # Assume LegacyMBR is backuped in Sector 6
jmp StartReadTo7C00 # EAX = Header/Sector/Tracker/Zero
EfiDbr:
cmpb $4, %al # MbrPartitionIndex should < 4
jae BadDbr
shlw $4, %ax # AX = MBREntrySize * Index
addw $0x1be, %ax # AX = MBREntryOffset
movw %ax, %di # DI = MBREntryOffset
# Here we don't use the C/H/S information provided by Partition table
# but calculate C/H/S from LBA ourselves
# Ci: Cylinder number
# Hi: Header number
# Si: Sector number
movl %es:8(%bp,%di,), %eax # Start LBA
movl %eax, %edx
shrl $16, %edx # DX:AX = Start LBA
# = Ci * (H * S) + Hi * S + (Si - 1)
# Calculate C/H/S according to LBA
movw $0x7bfa, %bp
divw 2(%bp) # AX = Hi + H*Ci
# DX = Si - 1
incw %dx # DX = Si
pushw %dx # 0000:7bfa = Si <----
xorw %dx, %dx # DX:AX = Hi + H*Ci
divw 4(%bp) # AX = Ci <----
# DX = Hi <----
StartReadTo7C00:
movb (%bp), %cl # Si
movb %al, %ch # Ci[0-7]
orb %ah, %cl # Ci[8,9]
movw $0x7c00, %bx # ES:BX = 0000:7C00h
movb $0x2, %ah # Function 02h
movb $1, %al # 1 Sector
movb %dl, %dh # Hi
movw $0x600, %bp
movb PhysicalDrive(%bp), %dl # Drive number
int $0x13
jc BadDbr
# ****************************************************************************
# Transfer control to BootSector - Jump to 0x0000:0x7C00
# ****************************************************************************
xorw %ax, %ax
pushw %ax # PUSH 0x0000 - Segment
movw $0x7c00, %di
pushw %di # PUSH 0x7C00 - Offset
retl # JMP 0x0000:0x7C00
# ****************************************************************************
# ERROR Condition:
# ****************************************************************************
BadDbr:
pushw %ax
movw $0xb800, %ax
movw %ax, %es
movw $0x60, %ax
movw %ax, %ds
leaw %cs:ErrorString, %si
movw $320, %di
popw %ax
call A2C
movb %ah, 16(%si)
movb %al, 18(%si)
movw $10, %cx
rep
movsw
Halt:
jmp Halt
StartString:
.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
ErrorString:
.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, ':', 0x0c, '?', 0x0c, '?', 0x0c
# ****************************************************************************
# A2C - convert Ascii code stored in AH to character stored in AX
# ****************************************************************************
A2C:
movb %ah, %al
shrb $4, %ah
andb $0xF, %al
addb '0', %ah
addb '0', %al
cmpb '9', %ah
jle A2C_L1
addb $7, %ah
A2C_L1:
cmpb '9', %al
jle A2C_L2
addb $7, %al
A2C_L2:
ret
# ****************************************************************************
# PhysicalDrive - Used to indicate which disk to be boot
# Can be patched by tool
# ****************************************************************************
.org 0x01B6
PhysicalDrive: .byte 0x80
# ****************************************************************************
# MbrPartitionIndicator - Used to indicate which MBR partition to be boot
# Can be patched by tool
# OxFF means boot to legacy MBR. (LBA OFFSET 6)
# ****************************************************************************
.org 0x01B7
MbrPartitionIndicator: .byte 0
# ****************************************************************************
# Unique MBR signature
# ****************************************************************************
.org 0x01B8
.ascii "DUET"
# ****************************************************************************
# Unknown
# ****************************************************************************
.org 0x01BC
.word 0
# ****************************************************************************
# MBR Entry - To be patched
# ****************************************************************************
.org 0x01BE
.long 0,0,0,0
.org 0x01CE
.long 0,0,0,0
.org 0x01DE
.long 0,0,0,0
.org 0x01EE
.long 0,0,0,0
# ****************************************************************************
# Sector Signature
# ****************************************************************************
.org 0x01FE
SectorSignature:
.word 0xaa55 # Boot Sector Signature

View File

@@ -1,261 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* Mbr.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
; .dosseg
.stack
.486p
.code
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
; ****************************************************************************
; Code loaded by BIOS at 0x0000:0x7C00
; ****************************************************************************
org 0h
Start:
; ****************************************************************************
; Start Print
; ****************************************************************************
mov ax,0b800h
mov es,ax
mov ax, 07c0h
mov ds, ax
lea si, cs:[StartString]
mov cx, 10
mov di, 160
rep movsw
; ****************************************************************************
; Print over
; ****************************************************************************
; ****************************************************************************
; Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
; ****************************************************************************
xor ax, ax ; AX = 0x0000
mov bx, 07c00h ; BX = 0x7C00
mov bp, 0600h ; BP = 0x0600
mov si, OFFSET RelocatedStart ; SI = Offset(RelocatedStart)
mov cx, 0200h ; CX = 0x0200
sub cx, si ; CS = 0x0200 - Offset(RelocatedStart)
lea di, [bp+si] ; DI = 0x0600 + Offset(RelocatedStart)
lea si, [bx+si] ; BX = 0x7C00 + Offset(RelocatedStart)
mov ss, ax ; SS = 0x0000
mov sp, bx ; SP = 0x7C00
mov es,ax ; ES = 0x0000
mov ds,ax ; DS = 0x0000
push ax ; PUSH 0x0000
push di ; PUSH 0x0600 + Offset(RelocatedStart)
cld ; Clear the direction flag
rep movsb ; Copy 0x0200 bytes from 0x7C00 to 0x0600
retf ; JMP 0x0000:0x0600 + Offset(RelocatedStart)
; ****************************************************************************
; Code relocated to 0x0000:0x0600
; ****************************************************************************
RelocatedStart:
; ****************************************************************************
; Get Driver Parameters to 0x0000:0x7BFC
; ****************************************************************************
xor ax,ax ; AX = 0
mov ss,ax ; SS = 0
add ax,1000h
mov ds,ax
mov sp,07c00h ; SP = 0x7c00
mov bp,sp ; BP = 0x7c00
mov ah,8 ; AH = 8 - Get Drive Parameters Function
mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
int 13h ; Get Drive Parameters
xor ax,ax ; AX = 0
mov al,dh ; AL = DH
inc al ; MaxHead = AL + 1
push ax ; 0000:7bfe = MaxHead
mov al,cl ; AL = CL
and al,03fh ; MaxSector = AL & 0x3f
push ax ; 0000:7bfc = MaxSector
; ****************************************************************************
; Read Target DBR from hard disk to 0x0000:0x7C00
; ****************************************************************************
xor ax, ax
mov al, byte ptr [bp+MbrPartitionIndicator] ; AX = MbrPartitionIndex
cmp al, 0ffh ; 0xFF means do legacy MBR boot
jnz EfiDbr
LegacyMbr:
mov eax, 00000600h ; Assume LegacyMBR is backuped in Sector 6
jmp StartReadTo7C00 ; EAX = Header/Sector/Tracker/Zero
EfiDbr:
cmp al, 4 ; MbrPartitionIndex should < 4
jae BadDbr
shl ax, 4 ; AX = MBREntrySize * Index
add ax, 1beh ; AX = MBREntryOffset
mov di, ax ; DI = MBREntryOffset
; Here we don't use the C/H/S information provided by Partition table
; but calculate C/H/S from LBA ourselves
; Ci: Cylinder number
; Hi: Header number
; Si: Sector number
mov eax, dword ptr es:[bp + di + 8] ; Start LBA
mov edx, eax
shr edx, 16 ; DX:AX = Start LBA
; = Ci * (H * S) + Hi * S + (Si - 1)
; Calculate C/H/S according to LBA
mov bp, 7bfah
div word ptr [bp+2] ; AX = Hi + H*Ci
; DX = Si - 1
inc dx ; DX = Si
push dx ; 0000:7bfa = Si <----
xor dx, dx ; DX:AX = Hi + H*Ci
div word ptr [bp+4] ; AX = Ci <----
; DX = Hi <----
StartReadTo7C00:
mov cl, byte ptr [bp] ; Si
mov ch, al ; Ci[0-7]
or cl, ah ; Ci[8,9]
mov bx, 7c00h ; ES:BX = 0000:7C00h
mov ah, 2h ; Function 02h
mov al, 1 ; 1 Sector
mov dh, dl ; Hi
mov bp, 0600h
mov dl, byte ptr [bp + PhysicalDrive] ; Drive number
int 13h
jc BadDbr
; ****************************************************************************
; Transfer control to BootSector - Jump to 0x0000:0x7C00
; ****************************************************************************
xor ax, ax
push ax ; PUSH 0x0000 - Segment
mov di, 07c00h
push di ; PUSH 0x7C00 - Offset
retf ; JMP 0x0000:0x7C00
; ****************************************************************************
; ERROR Condition:
; ****************************************************************************
BadDbr:
push ax
mov ax, 0b800h
mov es, ax
mov ax, 060h
mov ds, ax
lea si, cs:[ErrorString]
mov di, 320
pop ax
call A2C
mov [si+16], ah
mov [si+18], al
mov cx, 10
rep movsw
Halt:
jmp Halt
StartString:
db 'M', 0ch, 'B', 0ch, 'R', 0ch, ' ', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
ErrorString:
db 'M', 0ch, 'B', 0ch, 'R', 0ch, ' ', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, ':', 0ch, '?', 0ch, '?', 0ch
; ****************************************************************************
; A2C - convert Ascii code stored in AH to character stored in AX
; ****************************************************************************
A2C:
mov al, ah
shr ah, 4
and al, 0Fh
add ah, '0'
add al, '0'
cmp ah, '9'
jle @f
add ah, 7
@@:
cmp al, '9'
jle @f
add al, 7
@@:
ret
; ****************************************************************************
; PhysicalDrive - Used to indicate which disk to be boot
; Can be patched by tool
; ****************************************************************************
org 01B6h
PhysicalDrive db 80h
; ****************************************************************************
; MbrPartitionIndicator - Used to indicate which MBR partition to be boot
; Can be patched by tool
; OxFF means boot to legacy MBR. (LBA OFFSET 6)
; ****************************************************************************
org 01B7h
MbrPartitionIndicator db 0
; ****************************************************************************
; Unique MBR signature
; ****************************************************************************
org 01B8h
db 'DUET'
; ****************************************************************************
; Unknown
; ****************************************************************************
org 01BCh
dw 0
; ****************************************************************************
; MBR Entry - To be patched
; ****************************************************************************
org 01BEh
dd 0, 0, 0, 0
org 01CEh
dd 0, 0, 0, 0
org 01DEh
dd 0, 0, 0, 0
org 01EEh
dd 0, 0, 0, 0
; ****************************************************************************
; Sector Signature
; ****************************************************************************
org 01FEh
SectorSignature:
dw 0aa55h ; Boot Sector Signature
end

Binary file not shown.

Binary file not shown.

View File

@@ -1,8 +0,0 @@
These binaries are used to make the bootable floppy or usb disk.
The binaries of boot sector are built from DuetPkg\Bootsector\BootSector.inf at r8617 with following steps:
1) enter edk2 workspace directory from command line windows.
2) run "edksetup.bat"
3) run "build -p DuetPkg/DuetPkg.dsc -a IA32 -m DuetPkg/BootSector/BootSector.inf"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,303 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* bootsect.S
#*
#* bootsect.S is built as 16-bit binary file in 512 bytes and patched to disk/partition's
#* first section - boot sector.
#*
#* The startup sequence for DUET disk boot sector is:
#*
#* 1, LegacyBios check 0xAA55 signature at boot sectore offset 0x1FE to judget
#* whether disk/partition is bootable.
#* 2, LegacyBios will load boot sector to 0x7c00 in real mode, pass BPB data and
#* hand off control to 0x7c00 code.
#* 3, boot sector code simply parse FAT format in boot disk and find EfiLdr binary file
#* and EfiVar.bin if exists. For first boot, EfiVar.bin does not exist.
#* 4, boot sector load the first sector of EfiLdr binary which is start.com to
#* 0x2000:0x0000 address.
#* 5, boot sector handoff control to 0x2000:0x0000 for start.com binary.
#*
#------------------------------------------------------------------------------
.stack:
.486p:
.code16
.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
# "EFILDR_____"
.equ LOADER_FILENAME_PART1, 0x04c494645 # "EFIL"
.equ LOADER_FILENAME_PART2, 0x020205244 # "DR__"
.equ LOADER_FILENAME_PART3, 0x020202020 # "____"
.org 0x0
.global _start
_start:
Ia32Jump:
jmp BootSectorEntryPoint # JMP inst - 3 bytes
nop
OemId: .ascii "INTEL " # OemId - 8 bytes
# BPB data below will be fixed by tool
SectorSize: .word 0 # Sector Size - 16 bits
SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
ReservedSectors: .word 0 # Reserved Sectors - 16 bits
NoFats: .byte 0 # Number of FATs - 8 bits
RootEntries: .word 0 # Root Entries - 16 bits
Sectors: .word 0 # Number of Sectors - 16 bits
Media: .byte 0 # Media - 8 bits - ignored
SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
Heads: .word 0 # Heads - 16 bits - ignored
HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
LargeSectors: .long 0 # Large Sectors - 32 bits
PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
CurrentHead: .byte 0 # Current Head - 8 bits
Signature: .byte 0 # Signature - 8 bits - ignored
VolId: .ascii " " # Volume Serial Number- 4 bytes
FatLabel: .ascii " " # Label - 11 bytes
SystemId: .ascii "FAT12 " # SystemId - 8 bytes
BootSectorEntryPoint:
#ASSUME ds:@code
#ASSUME ss:@code
# ****************************************************************************
# Start Print
# ****************************************************************************
movw $StartString, %si
call PrintString
# ****************************************************************************
# Print over
# ****************************************************************************
movw %cs, %ax # ax = 0
movw %ax, %ss # ss = 0
addw $0x1000, %ax
movw %ax, %ds
movw $0x7c00, %sp # sp = 0x7c00
movw %sp, %bp # bp = 0x7c00
movb $8, %ah # ah = 8 - Get Drive Parameters Function
movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
int $0x13 # Get Drive Parameters
xorw %ax, %ax # ax = 0
movb %dh, %al # al = dh
incb %al # MaxHead = al + 1
pushw %ax # 0000:7bfe = MaxHead
movb %cl, %al # al = cl
andb $0x3f, %al # MaxSector = al & 0x3f
pushw %ax # 0000:7bfc = MaxSector
cmpw $0xaa55, SectorSignature(%bp) # Verify Boot Sector Signature
jne BadBootSector
movw RootEntries(%bp), %cx # cx = RootEntries
shlw $FAT_DIRECTORY_ENTRY_SHIFT, %cx # cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
movw %cx, %bx # bx = size of the Root Directory in bytes
andw $BLOCK_MASK, %bx # See if it is an even number of sectors long
jne BadBootSector # If is isn't, then the boot sector is bad.
movw %cx, %bx # bx = size of the Root Directory in bytes
shrw $BLOCK_SHIFT, %bx # bx = size of Root Directory in sectors
movb NoFats(%bp), %al # al = NoFats
xorb %ah, %ah # ah = 0 ==> ax = NoFats
mulw SectorsPerFat(%bp) # ax = NoFats * SectorsPerFat
addw ReservedSectors(%bp), %ax # ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
pushw %ds
popw %es
xorw %di, %di # Store directory in es:di = 1000:0000
call ReadBlocks # Read entire Root Directory
addw %bx, %ax # ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
movw %ax, (%bp) # Save FirstClusterLBA (FirstDataSector) for later use
# dx - variable storage (initial value is 0)
# bx - loader (initial value is 0)
xorw %dx, %dx
xorw %bx, %bx
FindEFILDR:
cmpl $LOADER_FILENAME_PART1, (%di) # Compare to "EFIL"
jne FindVARSTORE
cmpl $LOADER_FILENAME_PART2, 4(%di)
jne FindVARSTORE
cmpl $LOADER_FILENAME_PART3, 7(%di)
jne FindVARSTORE
movw 26(%di), %bx # bx = Start Cluster for EFILDR <----------------------------------
testw %dx, %dx
je FindNext # Efivar.bin is not loaded
jmp FoundAll
FindVARSTORE:
## if the file is not loader file, see if it's "EFIVAR BIN"
cmpl $0x56494645, (%di) # Compare to "EFIV"
jne FindNext
cmpl $0x20205241, 4(%di) # Compare to "AR "
jne FindNext
cmpl $0x4e494220, 7(%di) # Compare to " BIN"
jne FindNext
movw %di, %dx # dx = Offset of Start Cluster for Efivar.bin <---------------------
addw $26, %dx
testw %bx, %bx
je FindNext # Efildr is not loaded
jmp FoundAll
FindNext:
# go to next find
addw $FAT_DIRECTORY_ENTRY_SIZE, %di # Increment di
subw $FAT_DIRECTORY_ENTRY_SIZE, %cx # Decrement cx
# TODO: jump to FindVarStore if ...
jne FindEFILDR
jmp NotFoundAll
FoundAll:
FoundEFILDR:
movw %bx, %cx # cx = Start Cluster for EFILDR <----------------------------------
movw %cs, %ax # Destination = 2000:0000
addw $0x2000, %ax
movw %ax, %es
xorw %di, %di
ReadFirstClusterOfEFILDR:
movw %cx, %ax # ax = StartCluster
subw $2, %ax # ax = StartCluster - 2
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
pushw %dx
mulw %bx
popw %dx # ax = (StartCluster - 2) * SectorsPerCluster
addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = Number of Sectors in a cluster
pushw %es
call ReadBlocks
popw %ax
JumpIntoFirstSectorOfEFILDR:
movw %ax, JumpSegment(%bp)
JumpFarInstruction:
.byte 0xea
JumpOffset:
.word 0x000
JumpSegment:
.word 0x2000
PrintString:
movw $0xb800, %ax
movw %ax, %es
movw $0x7c0, %ax
movw %ax, %ds
movw $7, %cx
movw $160, %di
rep
movsw
ret
# ****************************************************************************
# ReadBlocks - Reads a set of blocks from a block device
#
# AX = Start LBA
# BX = Number of Blocks to Read
# ES:DI = Buffer to store sectors read from disk
# ****************************************************************************
# cx = Blocks
# bx = NumberOfBlocks
# si = StartLBA
ReadBlocks:
pusha
addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
movl %eax, %esi # esi = Start LBA
movw %bx, %cx # cx = Number of blocks to read
ReadCylinderLoop:
movw $0x7bfc, %bp # bp = 0x7bfc
movl %esi, %eax # eax = Start LBA
xorl %edx, %edx # edx = 0
movzwl (%bp), %ebx # bx = MaxSector
divl %ebx # ax = StartLBA / MaxSector
incw %dx # dx = (StartLBA % MaxSector) + 1
subw %dx, %bx # bx = MaxSector - Sector
incw %bx # bx = MaxSector - Sector + 1
cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
movw %cx, %bx # bx = Blocks
LimitTransfer:
pushw %cx
movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
xorw %dx, %dx # dx = 0
divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
# dx = ax % (MaxHead + 1) = Head
pushw %bx # Save number of blocks to transfer
movb %dl, %dh # dh = Head
movw $0x7c00, %bp # bp = 0x7c00
movb PhysicalDrive(%bp), %dl # dl = Drive Number
movb %al, %ch # ch = Cylinder
movb %bl, %al # al = Blocks
movb $2, %ah # ah = Function 2
movw %di, %bx # es:bx = Buffer address
int $0x13
jc DiskError
popw %bx
popw %cx
movzwl %bx, %ebx
addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
movw %es, %ax
shlw $(BLOCK_SHIFT-4), %bx
addw %bx, %ax
movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmpw $0, %cx
jne ReadCylinderLoop
popa
ret
# ****************************************************************************
# ERROR Condition:
# ****************************************************************************
NotFoundAll:
## if we found EFILDR, continue
testw %bx, %bx
jne FoundEFILDR
BadBootSector:
DiskError:
movw $ErrorString, %si
call PrintString
Halt:
jmp Halt
StartString:
.byte 'B', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
ErrorString:
.byte 'B', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
# ****************************************************************************
# LBA Offset for BootSector, need patched by tool for HD boot.
# ****************************************************************************
.org 0x01fa # Comment it for pass build. Should optimise code size.
LBAOffsetForBootSector:
.long 0x0
# ****************************************************************************
# Sector Signature
# ****************************************************************************
.org 0x01fe # Comment it for pass build.
SectorSignature:
.word 0xaa55 # Boot Sector Signature

View File

@@ -1,301 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* bootsect.asm
;*
;* bootsect.asm is built as 16-bit binary file in 512 bytes and patched to disk/partition's
;* first section - boot sector.
;*
;* The startup sequence for DUET disk boot sector is:
;*
;* 1, LegacyBios check 0xAA55 signature at boot sectore offset 0x1FE to judget
;* whether disk/partition is bootable.
;* 2, LegacyBios will load boot sector to 0x7c00 in real mode, pass BPB data and
;* hand off control to 0x7c00 code.
;* 3, boot sector code simply parse FAT format in boot disk and find EfiLdr binary file
;* and EfiVar.bin if exists. For first boot, EfiVar.bin does not exist.
;* 4, boot sector load the first sector of EfiLdr binary which is start.com to
;* 0x2000:0x0000 address.
;* 5, boot sector handoff control to 0x2000:0x0000 for start.com binary.
;*
;------------------------------------------------------------------------------
.model small
.stack
.486p
.code
FAT_DIRECTORY_ENTRY_SIZE EQU 020h
FAT_DIRECTORY_ENTRY_SHIFT EQU 5
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
; "EFILDR_____"
LOADER_FILENAME_PART1 EQU 04c494645h ; "EFIL"
LOADER_FILENAME_PART2 EQU 020205244h ; "DR__"
LOADER_FILENAME_PART3 EQU 020202020h ; "____"
org 0h
Ia32Jump:
jmp BootSectorEntryPoint ; JMP inst - 3 bytes
nop
OemId db "INTEL " ; OemId - 8 bytes
; BPB data below will be fixed by tool
SectorSize dw 0 ; Sector Size - 16 bits
SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
ReservedSectors dw 0 ; Reserved Sectors - 16 bits
NoFats db 0 ; Number of FATs - 8 bits
RootEntries dw 0 ; Root Entries - 16 bits
Sectors dw 0 ; Number of Sectors - 16 bits
Media db 0 ; Media - 8 bits - ignored
SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
Heads dw 0 ; Heads - 16 bits - ignored
HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
LargeSectors dd 0 ; Large Sectors - 32 bits
PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
CurrentHead db 0 ; Current Head - 8 bits
Signature db 0 ; Signature - 8 bits - ignored
Id db " " ; Id - 4 bytes
FatLabel db " " ; Label - 11 bytes
SystemId db "FAT12 " ; SystemId - 8 bytes
BootSectorEntryPoint:
ASSUME ds:@code
ASSUME ss:@code
; ****************************************************************************
; Start Print
; ****************************************************************************
lea si, cs:[StartString]
call PrintString
; ****************************************************************************
; Print over
; ****************************************************************************
mov ax,cs ; ax = 0
mov ss,ax ; ss = 0
add ax,1000h
mov ds,ax
mov sp,07c00h ; sp = 0x7c00
mov bp,sp ; bp = 0x7c00
mov ah,8 ; ah = 8 - Get Drive Parameters Function
mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
int 13h ; Get Drive Parameters
xor ax,ax ; ax = 0
mov al,dh ; al = dh (number of sides (0 based))
inc al ; MaxHead = al + 1
push ax ; 0000:7bfe = MaxHead
mov al,cl ; al = cl (CL = sectors per track)
and al,03fh ; MaxSector = al & 0x3f
push ax ; 0000:7bfc = MaxSector
cmp word ptr [bp+SectorSignature],0aa55h ; Verify Boot Sector Signature
jne BadBootSector
mov cx,word ptr [bp+RootEntries] ; cx = RootEntries
shl cx,FAT_DIRECTORY_ENTRY_SHIFT ; cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
mov bx,cx ; bx = size of the Root Directory in bytes
and bx,BLOCK_MASK ; See if it is an even number of sectors long
jne BadBootSector ; If is isn't, then the boot sector is bad.
mov bx,cx ; bx = size of the Root Directory in bytes
shr bx,BLOCK_SHIFT ; bx = size of Root Directory in sectors
mov al,byte ptr [bp+NoFats] ; al = NoFats
xor ah,ah ; ah = 0 ==> ax = NoFats
mul word ptr [bp+SectorsPerFat] ; ax = NoFats * SectorsPerFat
add ax,word ptr [bp+ReservedSectors] ; ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
push ds
pop es
xor di,di ; Store directory in es:di = 1000:0000
call ReadBlocks ; Read entire Root Directory
add ax,bx ; ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
mov word ptr [bp],ax ; Save FirstClusterLBA (FirstDataSector) for later use
; dx - variable storage (initial value is 0)
; bx - loader (initial value is 0)
xor dx, dx
xor bx, bx
FindEFILDR:
cmp dword ptr [di],LOADER_FILENAME_PART1 ; Compare to "EFIL"
jne FindVARSTORE
cmp dword ptr [di+4],LOADER_FILENAME_PART2
jne FindVARSTORE
cmp dword ptr [di+7],LOADER_FILENAME_PART3
jne FindVARSTORE
mov bx, word ptr [di+26] ; bx = Start Cluster for EFILDR <----------------------------------
test dx, dx
je FindNext ; Efivar.bin is not loaded
jmp FoundAll
FindVARSTORE:
; if the file is not loader file, see if it's "EFIVAR BIN"
cmp dword ptr [di], 056494645h ; Compare to "EFIV"
jne FindNext
cmp dword ptr [di+4], 020205241h ; Compare to "AR "
jne FindNext
cmp dword ptr [di+7], 04e494220h ; Compare to " BIN"
jne FindNext
mov dx, di ; dx = Offset of Start Cluster for Efivar.bin <---------------------
add dx, 26
test bx, bx
je FindNext ; Efildr is not loaded
jmp FoundAll
FindNext:
; go to next find
add di,FAT_DIRECTORY_ENTRY_SIZE ; Increment di
sub cx,FAT_DIRECTORY_ENTRY_SIZE ; Decrement cx
; TODO: jump to FindVarStore if ...
jne FindEFILDR
jmp NotFoundAll
FoundAll:
FoundEFILDR: ; 0x7cfe
mov cx,bx ; cx = Start Cluster for EFILDR <----------------------------------
mov ax,cs ; Destination = 2000:0000
add ax,2000h
mov es,ax
xor di,di
ReadFirstClusterOfEFILDR:
mov ax,cx ; ax = StartCluster
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
push dx
mul bx
pop dx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = Number of Sectors in a cluster
push es
call ReadBlocks
pop ax
JumpIntoFirstSectorOfEFILDR:
mov word ptr [bp+JumpSegment],ax ; 0x7d26
JumpFarInstruction: ; 0x7d2a
db 0eah
JumpOffset:
dw 0000h
JumpSegment:
dw 2000h
PrintString:
mov ax,0b800h
mov es,ax
mov ax, 07c0h
mov ds, ax
mov cx, 7
mov di, 160
rep movsw
ret
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; AX = Start LBA
; BX = Number of Blocks to Read
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; cx = Blocks
; bx = NumberOfBlocks
; si = StartLBA
ReadBlocks:
pusha
add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
mov esi,eax ; esi = Start LBA
mov cx,bx ; cx = Number of blocks to read
ReadCylinderLoop:
mov bp,07bfch ; bp = 0x7bfc
mov eax,esi ; eax = Start LBA
xor edx,edx ; edx = 0
movzx ebx,word ptr [bp] ; bx = MaxSector
div ebx ; ax = StartLBA / MaxSector
inc dx ; dx = (StartLBA % MaxSector) + 1
sub bx,dx ; bx = MaxSector - Sector
inc bx ; bx = MaxSector - Sector + 1
cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
mov bx,cx ; bx = Blocks
LimitTransfer:
push cx
mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
xor dx,dx ; dx = 0
div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
; dx = ax % (MaxHead + 1) = Head
push bx ; Save number of blocks to transfer
mov dh,dl ; dh = Head
mov bp,07c00h ; bp = 0x7c00
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
mov ch,al ; ch = Cylinder
mov al,bl ; al = Blocks
mov ah,2 ; ah = Function 2
mov bx,di ; es:bx = Buffer address
int 013h
jc DiskError
pop bx
pop cx
movzx ebx,bx
add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
sub cx,bx ; Blocks = Blocks - NumberOfBlocks
mov ax,es
shl bx,(BLOCK_SHIFT-4)
add ax,bx
mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmp cx,0
jne ReadCylinderLoop
popa
ret
; ****************************************************************************
; ERROR Condition:
; ****************************************************************************
NotFoundAll: ; 0x7da6
; if we found EFILDR, continue
test bx,bx
jne FoundEFILDR
BadBootSector:
DiskError:
lea si, cs:[ErrorString]
call PrintString
Halt:
jmp Halt
StartString:
db 'B', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
ErrorString:
db 'B', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
; ****************************************************************************
; LBA Offset for BootSector, need patched by tool for HD boot.
; ****************************************************************************
org 01fah
LBAOffsetForBootSector:
dd 0h
; ****************************************************************************
; Sector Signature
; ****************************************************************************
org 01feh
SectorSignature:
dw 0aa55h ; Boot Sector Signature
end

View File

@@ -1,291 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* bs16.asm
#*
#* Abstract:
#*
#------------------------------------------------------------------------------
#.MODEL small
.stack:
.486p:
.code16
.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
# "EFILDR_____"
.equ LOADER_FILENAME_PART1, 0x04c494645 # "EFIL"
.equ LOADER_FILENAME_PART2, 0x036315244 # "DR16"
.equ LOADER_FILENAME_PART3, 0x020202036 # "6___"
.org 0x0
.global _start
_start:
Ia32Jump:
jmp BootSectorEntryPoint # JMP inst - 3 bytes
nop
OemId: .ascii "INTEL " # OemId - 8 bytes
# BPB data below will be fixed by tool
SectorSize: .word 0 # Sector Size - 16 bits
SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
ReservedSectors: .word 0 # Reserved Sectors - 16 bits
NoFats: .byte 0 # Number of FATs - 8 bits
RootEntries: .word 0 # Root Entries - 16 bits
Sectors: .word 0 # Number of Sectors - 16 bits
Media: .byte 0 # Media - 8 bits - ignored
SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
Heads: .word 0 # Heads - 16 bits - ignored
HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
LargeSectors: .long 0 # Large Sectors - 32 bits
PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
CurrentHead: .byte 0 # Current Head - 8 bits
Signature: .byte 0 # Signature - 8 bits - ignored
VolId: .ascii " " # Volume Serial Number- 4 bytes
FatLabel: .ascii " " # Label - 11 bytes
SystemId: .ascii "FAT12 " # SystemId - 8 bytes
BootSectorEntryPoint:
#ASSUME ds:@code
#ASSUME ss:@code
# ****************************************************************************
# Start Print
# ****************************************************************************
movw $StartString, %si
call PrintString
# ****************************************************************************
# Print over
# ****************************************************************************
movw %cs, %ax # ax = 0
movw %ax, %ss # ss = 0
addw $0x1000, %ax
movw %ax, %ds
movw $0x7c00, %sp # sp = 0x7c00
movw %sp, %bp # bp = 0x7c00
movb $8, %ah # ah = 8 - Get Drive Parameters Function
movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
int $0x13 # Get Drive Parameters
xorw %ax, %ax # ax = 0
movb %dh, %al # al = dh
incb %al # MaxHead = al + 1
pushw %ax # 0000:7bfe = MaxHead
movb %cl, %al # al = cl
andb $0x3f, %al # MaxSector = al & 0x3f
pushw %ax # 0000:7bfc = MaxSector
cmpw $0xaa55, SectorSignature(%bp) # Verify Boot Sector Signature
jne BadBootSector
movw RootEntries(%bp), %cx # cx = RootEntries
shlw $FAT_DIRECTORY_ENTRY_SHIFT, %cx # cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
movw %cx, %bx # bx = size of the Root Directory in bytes
andw $BLOCK_MASK, %bx # See if it is an even number of sectors long
jne BadBootSector # If is isn't, then the boot sector is bad.
movw %cx, %bx # bx = size of the Root Directory in bytes
shrw $BLOCK_SHIFT, %bx # bx = size of Root Directory in sectors
movb NoFats(%bp), %al # al = NoFats
xorb %ah, %ah # ah = 0 ==> ax = NoFats
mulw SectorsPerFat(%bp) # ax = NoFats * SectorsPerFat
addw ReservedSectors(%bp), %ax # ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
pushw %ds
popw %es
xorw %di, %di # Store directory in es:di = 1000:0000
call ReadBlocks # Read entire Root Directory
addw %bx, %ax # ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
movw %ax, (%bp) # Save FirstClusterLBA (FirstDataSector) for later use
# dx - variable storage (initial value is 0)
# bx - loader (initial value is 0)
xorw %dx, %dx
xorw %bx, %bx
FindEFILDR:
cmpl $LOADER_FILENAME_PART1, (%di) # Compare to "EFIL"
jne FindVARSTORE
cmpl $LOADER_FILENAME_PART2, 4(%di)
jne FindVARSTORE
cmpl $LOADER_FILENAME_PART3, 7(%di)
jne FindVARSTORE
movw 26(%di), %bx # bx = Start Cluster for EFILDR <----------------------------------
testw %dx, %dx
je FindNext # Efivar.bin is not loaded
jmp FoundAll
FindVARSTORE:
##if the file is not loader file, see if it's "EFIVAR BIN"
cmpl $0x56494645, (%di) # Compare to "EFIV"
jne FindNext
cmpl $0x20205241, 4(%di) # Compare to "AR "
jne FindNext
cmpl $0x4e494220, 7(%di) # Compare to " BIN"
jne FindNext
movw %di, %dx # dx = Offset of Start Cluster for Efivar.bin <---------------------
addw $26, %dx
testw %bx, %bx
je FindNext # Efildr is not loaded
jmp FoundAll
FindNext:
# go to next find
addw $FAT_DIRECTORY_ENTRY_SIZE, %di # Increment di
subw $FAT_DIRECTORY_ENTRY_SIZE, %cx # Decrement cx
# TODO: jump to FindVarStore if ...
jne FindEFILDR
jmp NotFoundAll
FoundAll:
FoundEFILDR:
movw %bx, %cx # cx = Start Cluster for EFILDR <----------------------------------
movw %cs, %ax # Destination = 2000:0000
addw $0x2000, %ax
movw %ax, %es
xorw %di, %di
ReadFirstClusterOfEFILDR:
movw %cx, %ax # ax = StartCluster
subw $2, %ax # ax = StartCluster - 2
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
pushw %dx
mulw %bx
popw %dx # ax = (StartCluster - 2) * SectorsPerCluster
addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = Number of Sectors in a cluster
pushw %es
call ReadBlocks
popw %ax
JumpIntoFirstSectorOfEFILDR:
movw %ax, JumpSegment(%bp)
JumpFarInstruction:
.byte 0xea
JumpOffset:
.word 0x000
JumpSegment:
.word 0x2000
PrintString:
movw $0xb800, %ax
movw %ax, %es
movw $0x7c0, %ax
movw %ax, %ds
movw $7, %cx
movw $160, %di
rep
movsw
ret
# ****************************************************************************
# ReadBlocks - Reads a set of blocks from a block device
#
# AX = Start LBA
# BX = Number of Blocks to Read
# ES:DI = Buffer to store sectors read from disk
# ****************************************************************************
# cx = Blocks
# bx = NumberOfBlocks
# si = StartLBA
ReadBlocks:
pusha
addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
movl %eax, %esi # esi = Start LBA
movw %bx, %cx # cx = Number of blocks to read
ReadCylinderLoop:
movw $0x7bfc, %bp # bp = 0x7bfc
movl %esi, %eax # eax = Start LBA
xorl %edx, %edx # edx = 0
movzwl (%bp), %ebx # bx = MaxSector
divl %ebx # ax = StartLBA / MaxSector
incw %dx # dx = (StartLBA % MaxSector) + 1
subw %dx, %bx # bx = MaxSector - Sector
incw %bx # bx = MaxSector - Sector + 1
cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
movw %cx, %bx # bx = Blocks
LimitTransfer:
pushw %cx
movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
xorw %dx, %dx # dx = 0
divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
# dx = ax % (MaxHead + 1) = Head
pushw %bx # Save number of blocks to transfer
movb %dl, %dh # dh = Head
movw $0x7c00, %bp # bp = 0x7c00
movb PhysicalDrive(%bp), %dl # dl = Drive Number
movb %al, %ch # ch = Cylinder
movb %bl, %al # al = Blocks
movb $2, %ah # ah = Function 2
movw %di, %bx # es:bx = Buffer address
int $0x13
jc DiskError
popw %bx
popw %cx
movzwl %bx, %ebx
addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
movw %es, %ax
shlw $(BLOCK_SHIFT-4),%bx
addw %bx, %ax
movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmpw $0, %cx
jne ReadCylinderLoop
popa
ret
# ****************************************************************************
# ERROR Condition:
# ****************************************************************************
NotFoundAll:
## if we found EFILDR, continue
testw %bx, %bx
jne FoundEFILDR
BadBootSector:
DiskError:
movw $ErrorString, %si
call PrintString
Halt:
jmp Halt
StartString:
.byte 'B', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
ErrorString:
.byte 'B', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
# ****************************************************************************
# LBA Offset for BootSector, need patched by tool for HD boot.
# ****************************************************************************
.org 0x01fa
LBAOffsetForBootSector:
.long 0x0
# ****************************************************************************
# Sector Signature
# ****************************************************************************
.org 0x01fe
SectorSignature:
.word 0xaa55 # Boot Sector Signature

View File

@@ -1,288 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* bs16.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
.stack
.486p
.code
FAT_DIRECTORY_ENTRY_SIZE EQU 020h
FAT_DIRECTORY_ENTRY_SHIFT EQU 5
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
; "EFILDR_____"
LOADER_FILENAME_PART1 EQU 04c494645h ; "EFIL"
LOADER_FILENAME_PART2 EQU 036315244h ; "DR16"
LOADER_FILENAME_PART3 EQU 020202036h ; "6___"
org 0h
Ia32Jump:
jmp BootSectorEntryPoint ; JMP inst - 3 bytes
nop
OemId db "INTEL " ; OemId - 8 bytes
; BPB data below will be fixed by tool
SectorSize dw 0 ; Sector Size - 16 bits
SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
ReservedSectors dw 0 ; Reserved Sectors - 16 bits
NoFats db 0 ; Number of FATs - 8 bits
RootEntries dw 0 ; Root Entries - 16 bits
Sectors dw 0 ; Number of Sectors - 16 bits
Media db 0 ; Media - 8 bits - ignored
SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
Heads dw 0 ; Heads - 16 bits - ignored
HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
LargeSectors dd 0 ; Large Sectors - 32 bits
PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
CurrentHead db 0 ; Current Head - 8 bits
Signature db 0 ; Signature - 8 bits - ignored
Id db " " ; Id - 4 bytes
FatLabel db " " ; Label - 11 bytes
SystemId db "FAT16 " ; SystemId - 8 bytes
BootSectorEntryPoint:
ASSUME ds:@code
ASSUME ss:@code
; ****************************************************************************
; Start Print
; ****************************************************************************
lea si, cs:[StartString]
call PrintString
; ****************************************************************************
; Print over
; ****************************************************************************
mov ax,cs ; ax = 0
mov ss,ax ; ss = 0
add ax,1000h
mov ds,ax
mov sp,07c00h ; sp = 0x7c00
mov bp,sp ; bp = 0x7c00
mov ah,8 ; ah = 8 - Get Drive Parameters Function
mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
int 13h ; Get Drive Parameters
xor ax,ax ; ax = 0
mov al,dh ; al = dh
inc al ; MaxHead = al + 1
push ax ; 0000:7bfe = MaxHead
mov al,cl ; al = cl
and al,03fh ; MaxSector = al & 0x3f
push ax ; 0000:7bfc = MaxSector
cmp word ptr [bp+SectorSignature],0aa55h ; Verify Boot Sector Signature
jne BadBootSector
mov cx,word ptr [bp+RootEntries] ; cx = RootEntries
shl cx,FAT_DIRECTORY_ENTRY_SHIFT ; cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
mov bx,cx ; bx = size of the Root Directory in bytes
and bx,BLOCK_MASK ; See if it is an even number of sectors long
jne BadBootSector ; If is isn't, then the boot sector is bad.
mov bx,cx ; bx = size of the Root Directory in bytes
shr bx,BLOCK_SHIFT ; bx = size of Root Directory in sectors
mov al,byte ptr [bp+NoFats] ; al = NoFats
xor ah,ah ; ah = 0 ==> ax = NoFats
mul word ptr [bp+SectorsPerFat] ; ax = NoFats * SectorsPerFat
add ax,word ptr [bp+ReservedSectors] ; ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
push ds
pop es
xor di,di ; Store directory in es:di = 1000:0000
call ReadBlocks ; Read entire Root Directory
add ax,bx ; ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA (FirstDataSector)
mov word ptr [bp],ax ; Save FirstClusterLBA (FirstDataSector) for later use
; dx - variable storage (initial value is 0)
; bx - loader (initial value is 0)
xor dx, dx
xor bx, bx
FindEFILDR:
cmp dword ptr [di],LOADER_FILENAME_PART1 ; Compare to "EFIL"
jne FindVARSTORE
cmp dword ptr [di+4],LOADER_FILENAME_PART2
jne FindVARSTORE
cmp dword ptr [di+7],LOADER_FILENAME_PART3
jne FindVARSTORE
mov bx, word ptr [di+26] ; bx = Start Cluster for EFILDR <----------------------------------
test dx, dx
je FindNext ; Efivar.bin is not loaded
jmp FoundAll
FindVARSTORE:
; if the file is not loader file, see if it's "EFIVAR BIN"
cmp dword ptr [di], 056494645h ; Compare to "EFIV"
jne FindNext
cmp dword ptr [di+4], 020205241h ; Compare to "AR "
jne FindNext
cmp dword ptr [di+7], 04e494220h ; Compare to " BIN"
jne FindNext
mov dx, di ; dx = Offset of Start Cluster for Efivar.bin <---------------------
add dx, 26
test bx, bx
je FindNext ; Efildr is not loaded
jmp FoundAll
FindNext:
; go to next find
add di,FAT_DIRECTORY_ENTRY_SIZE ; Increment di
sub cx,FAT_DIRECTORY_ENTRY_SIZE ; Decrement cx
; TODO: jump to FindVarStore if ...
jne FindEFILDR
jmp NotFoundAll
FoundAll:
FoundEFILDR:
mov cx,bx ; cx = Start Cluster for EFILDR <----------------------------------
mov ax,cs ; Destination = 2000:0000
add ax,2000h
mov es,ax
xor di,di
ReadFirstClusterOfEFILDR:
mov ax,cx ; ax = StartCluster
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
push dx
mul bx
pop dx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = Number of Sectors in a cluster
push es
call ReadBlocks
pop ax
JumpIntoFirstSectorOfEFILDR:
mov word ptr [bp+JumpSegment],ax
JumpFarInstruction:
db 0eah
JumpOffset:
dw 0000h
JumpSegment:
dw 2000h
PrintString:
mov ax,0b800h
mov es,ax
mov ax, 07c0h
mov ds, ax
mov cx, 7
mov di, 160
rep movsw
ret
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; AX = Start LBA
; BX = Number of Blocks to Read
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; cx = Blocks
; bx = NumberOfBlocks
; si = StartLBA
ReadBlocks:
pusha
add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
mov esi,eax ; esi = Start LBA
mov cx,bx ; cx = Number of blocks to read
ReadCylinderLoop:
mov bp,07bfch ; bp = 0x7bfc
mov eax,esi ; eax = Start LBA
xor edx,edx ; edx = 0
movzx ebx,word ptr [bp] ; bx = MaxSector
div ebx ; ax = StartLBA / MaxSector
inc dx ; dx = (StartLBA % MaxSector) + 1
sub bx,dx ; bx = MaxSector - Sector
inc bx ; bx = MaxSector - Sector + 1
cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
mov bx,cx ; bx = Blocks
LimitTransfer:
push cx
mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
xor dx,dx ; dx = 0
div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
; dx = ax % (MaxHead + 1) = Head
push bx ; Save number of blocks to transfer
mov dh,dl ; dh = Head
mov bp,07c00h ; bp = 0x7c00
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
mov ch,al ; ch = Cylinder
mov al,bl ; al = Blocks
mov ah,2 ; ah = Function 2
mov bx,di ; es:bx = Buffer address
int 013h
jc DiskError
pop bx
pop cx
movzx ebx,bx
add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
sub cx,bx ; Blocks = Blocks - NumberOfBlocks
mov ax,es
shl bx,(BLOCK_SHIFT-4)
add ax,bx
mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmp cx,0
jne ReadCylinderLoop
popa
ret
; ****************************************************************************
; ERROR Condition:
; ****************************************************************************
NotFoundAll:
; if we found EFILDR, continue
test bx,bx
jne FoundEFILDR
BadBootSector:
DiskError:
lea si, cs:[ErrorString]
call PrintString
Halt:
jmp Halt
StartString:
db 'B', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
ErrorString:
db 'B', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
; ****************************************************************************
; LBA Offset for BootSector, need patched by tool for HD boot.
; ****************************************************************************
org 01fah
LBAOffsetForBootSector:
dd 0h
; ****************************************************************************
; Sector Signature
; ****************************************************************************
org 01feh
SectorSignature:
dw 0aa55h ; Boot Sector Signature
end

View File

@@ -1,312 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* bs32.asm
#*
#* Abstract:
#*
#------------------------------------------------------------------------------
#.MODEL small
.stack:
.486p:
.code16
.equ FAT_DIRECTORY_ENTRY_SIZE, 0x0020
.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
# "EFILDR_____"
.equ LOADER_FILENAME_PART1, 0x4c494645 # "EFIL"
.equ LOADER_FILENAME_PART2, 0x30325244 # "DR20"
.equ LOADER_FILENAME_PART3, 0x20202030 # "0___"
.org 0x0
.global _start
_start:
Ia32Jump:
jmp BootSectorEntryPoint # JMP inst - 3 bytes
nop
OemId: .ascii "INTEL " # OemId - 8 bytes
# BPB data below will be fixed by tool
SectorSize: .word 0 # Sector Size - 16 bits
SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
ReservedSectors: .word 0 # Reserved Sectors - 16 bits
NoFats: .byte 0 # Number of FATs - 8 bits
RootEntries: .word 0 # Root Entries - 16 bits
Sectors: .word 0 # Number of Sectors - 16 bits
Media: .byte 0 # Media - 8 bits - ignored
SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
Heads: .word 0 # Heads - 16 bits - ignored
HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
LargeSectors: .long 0 # Large Sectors - 32 bits
#******************************************************************************
#
#The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
#the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
#
#******************************************************************************
SectorsPerFat32: .long 0 # Sectors Per FAT for FAT32 - 4 bytes
ExtFlags: .word 0 # Mirror Flag - 2 bytes
FSVersion: .word 0 # File System Version - 2 bytes
RootCluster: .long 0 # 1st Cluster Number of Root Dir - 4 bytes
FSInfo: .word 0 # Sector Number of FSINFO - 2 bytes
BkBootSector: .word 0 # Sector Number of Bk BootSector - 2 bytes
Reserved: .fill 12, 1, 0 # Reserved Field - 12 bytes
PhysicalDrive: .byte 0 # Physical Drive Number - 1 byte
Reserved1: .byte 0 # Reserved Field - 1 byte
Signature: .byte 0 # Extended Boot Signature - 1 byte
VolId: .ascii " " # Volume Serial Number - 4 bytes
FatLabel: .ascii " " # Volume Label - 11 bytes
FileSystemType: .ascii "FAT32 " # File System Type - 8 bytes
BootSectorEntryPoint:
#ASSUME ds:@code
#ASSUME ss:@code
# ****************************************************************************
# Start Print
# ****************************************************************************
movw $StartString, %si
call PrintString
# ****************************************************************************
# Print over
# ****************************************************************************
movw %cs, %ax # ax = 0
movw %ax, %ss # ss = 0
addw $0x1000, %ax
movw %ax, %ds
movw $0x7c00, %sp # sp = 0x7c00
movw %sp, %bp # bp = 0x7c00
movb $8, %ah # ah = 8 - Get Drive Parameters Function
movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
int $0x13 # Get Drive Parameters
xorw %ax, %ax # ax = 0
movb %dh, %al # al = dh
incb %al # MaxHead = al + 1
pushw %ax # 0000:7bfe = MaxHead
movb %cl, %al # al = cl
andb $0x3f, %al # MaxSector = al & 0x3f
pushw %ax # 0000:7bfc = MaxSector
cmpw $0xaa55, SectorSignature(%bp) # Verify Boot Sector Signature
jne BadBootSector
movw RootEntries(%bp), %cx # cx = RootEntries
shlw $FAT_DIRECTORY_ENTRY_SHIFT, %cx # cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
movw %cx, %bx # bx = size of the Root Directory in bytes
andw $BLOCK_MASK, %bx # See if it is an even number of sectors long
jne BadBootSector # If is isn't, then the boot sector is bad.
movw %cx, %bx # bx = size of the Root Directory in bytes
shrw $BLOCK_SHIFT, %bx # bx = size of Root Directory in sectors
movb NoFats(%bp), %al # al = NoFats
xorb %ah, %ah # ah = 0 ==> ax = NoFats
mulw SectorsPerFat32(%bp) # ax = NoFats * SectorsPerFat
addw ReservedSectors(%bp), %ax # ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
addw %bx, %ax # ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA
movw %ax, (%bp) # Save FirstClusterLBA for later use
movw RootCluster(%bp), %ax # ax = StartCluster of Root Directory
subw $2, %ax # ax = StartCluster - 2
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
pushw %ds
popw %es
xorw %di, %di # Store directory in es:di = 1000:0000
call ReadBlocks # Read StartCluster of Root Directory
# dx - variable storage (initial value is 0)
# bx - loader (initial value is 0)
xorw %dx, %dx
xorw %bx, %bx
FindEFILDR:
cmpl $LOADER_FILENAME_PART1, (%di)
jne FindVARSTORE
cmpl $LOADER_FILENAME_PART2, 4(%di)
jne FindVARSTORE
cmpl $LOADER_FILENAME_PART3, 7(%di)
jne FindVARSTORE
movw 26(%di), %bx # bx = Start Cluster for EFILDR <----------------------------------
testw %dx, %dx
je FindNext # Efivar.bin is not loaded
jmp FoundAll
FindVARSTORE:
## if the file is not loader file, see if it's "EFIVAR BIN"
cmpl $0x56494645, (%di) # Compare to "EFIV"
jne FindNext
cmpl $0x20205241, 4(%di) # Compare to "AR "
jne FindNext
cmpl $0x4e494220, 7(%di) # Compare to " BIN"
jne FindNext
movw %di, %dx # dx = Offset of Start Cluster for Efivar.bin <---------------------
addw $26, %dx
testw %bx, %bx
je FindNext # Efildr is not loaded
jmp FoundAll
FindNext:
# go to next find
addw $FAT_DIRECTORY_ENTRY_SIZE, %di # Increment di
subw $FAT_DIRECTORY_ENTRY_SIZE, %cx # Decrement cx
# TODO: jump to FindVarStore if ...
jne FindEFILDR
jmp NotFoundAll
FoundAll:
FoundEFILDR:
movw %bx, %cx # cx = Start Cluster for EFILDR <----------------------------------
movw %cs, %ax # Destination = 2000:0000
addw $0x2000, %ax
movw %ax, %es
xorw %di, %di
ReadFirstClusterOfEFILDR:
movw %cx, %ax # ax = StartCluster
subw $2, %ax # ax = StartCluster - 2
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
pushw %dx
mulw %bx
popw %dx # ax = (StartCluster - 2) * SectorsPerCluster
addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = Number of Sectors in a cluster
pushw %es
call ReadBlocks
popw %ax
JumpIntoFirstSectorOfEFILDR:
movw %ax, JumpSegment(%bp)
JumpFarInstruction:
.byte 0xea
JumpOffset:
.word 0x000
JumpSegment:
.word 0x2000
PrintString:
movw $0xb800, %ax
movw %ax, %es
movw $0x7c0, %ax
movw %ax, %ds
movw $6, %cx
movw $160, %di
rep
movsw
ret
# ****************************************************************************
# ReadBlocks - Reads a set of blocks from a block device
#
# AX = Start LBA
# BX = Number of Blocks to Read
# ES:DI = Buffer to store sectors read from disk
# ****************************************************************************
# cx = Blocks
# bx = NumberOfBlocks
# si = StartLBA
ReadBlocks:
pusha
addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
movl %eax, %esi # esi = Start LBA
movw %bx, %cx # cx = Number of blocks to read
ReadCylinderLoop:
movw $0x7bfc, %bp # bp = 0x7bfc
movl %esi, %eax # eax = Start LBA
xorl %edx, %edx # edx = 0
movzwl (%bp), %ebx # bx = MaxSector
divl %ebx # ax = StartLBA / MaxSector
incw %dx # dx = (StartLBA % MaxSector) + 1
subw %dx, %bx # bx = MaxSector - Sector
incw %bx # bx = MaxSector - Sector + 1
cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
movw %cx, %bx # bx = Blocks
LimitTransfer:
pushw %cx
movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
xorw %dx, %dx # dx = 0
divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
# dx = ax % (MaxHead + 1) = Head
pushw %bx # Save number of blocks to transfer
movb %dl, %dh # dh = Head
movw $0x7c00, %bp # bp = 0x7c00
movb PhysicalDrive(%bp), %dl # dl = Drive Number
movb %al, %ch # ch = Cylinder
movb %bl, %al # al = Blocks
movb $2, %ah # ah = Function 2
movw %di, %bx # es:bx = Buffer address
int $0x13
jc DiskError
popw %bx
popw %cx
movzwl %bx, %ebx
addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
movw %es, %ax
shlw $(BLOCK_SHIFT-4), %bx
addw %bx, %ax
movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmpw $0, %cx
jne ReadCylinderLoop
popa
ret
# ****************************************************************************
# ERROR Condition:
# ****************************************************************************
NotFoundAll:
## if we found EFILDR, continue
testw %bx, %bx
jne FoundEFILDR
BadBootSector:
DiskError:
movw $ErrorString, %si
call PrintString
Halt:
jmp Halt
StartString:
.byte 'B', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c
ErrorString:
.byte 'B', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c
# ****************************************************************************
# LBA Offset for BootSector, need patched by tool for HD boot.
# ****************************************************************************
.org 0x01fa
LBAOffsetForBootSector:
.long 0x0
# ****************************************************************************
# Sector Signature
# ****************************************************************************
.org 0x01fe
SectorSignature:
.word 0xaa55 # Boot Sector Signature

View File

@@ -1,310 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* bs32.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
.stack
.486p
.code
FAT_DIRECTORY_ENTRY_SIZE EQU 020h
FAT_DIRECTORY_ENTRY_SHIFT EQU 5
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
; "EFILDR_____"
LOADER_FILENAME_PART1 EQU 04c494645h ; "EFIL"
LOADER_FILENAME_PART2 EQU 030325244h ; "DR20"
LOADER_FILENAME_PART3 EQU 020202030h ; "0___"
org 0h
Ia32Jump:
jmp BootSectorEntryPoint ; JMP inst - 3 bytes
nop
OemId db "INTEL " ; OemId - 8 bytes
; BPB data below will be fixed by tool
SectorSize dw 0 ; Sector Size - 16 bits
SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
ReservedSectors dw 0 ; Reserved Sectors - 16 bits
NoFats db 0 ; Number of FATs - 8 bits
RootEntries dw 0 ; Root Entries - 16 bits
Sectors dw 0 ; Number of Sectors - 16 bits
Media db 0 ; Media - 8 bits - ignored
SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
Heads dw 0 ; Heads - 16 bits - ignored
HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
LargeSectors dd 0 ; Large Sectors - 32 bits
;******************************************************************************
;
;The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
;the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
;
;******************************************************************************
SectorsPerFat32 dd 0 ; Sectors Per FAT for FAT32 - 4 bytes
ExtFlags dw 0 ; Mirror Flag - 2 bytes
FSVersion dw 0 ; File System Version - 2 bytes
RootCluster dd 0 ; 1st Cluster Number of Root Dir - 4 bytes
FSInfo dw 0 ; Sector Number of FSINFO - 2 bytes
BkBootSector dw 0 ; Sector Number of Bk BootSector - 2 bytes
Reserved db 12 dup(0) ; Reserved Field - 12 bytes
PhysicalDrive db 0 ; Physical Drive Number - 1 byte
Reserved1 db 0 ; Reserved Field - 1 byte
Signature db 0 ; Extended Boot Signature - 1 byte
VolId db " " ; Volume Serial Number - 4 bytes
FatLabel db " " ; Volume Label - 11 bytes
FileSystemType db "FAT32 " ; File System Type - 8 bytes
BootSectorEntryPoint:
ASSUME ds:@code
ASSUME ss:@code
; ****************************************************************************
; Start Print
; ****************************************************************************
mov si, offset StartString
call PrintString
; ****************************************************************************
; Print over
; ****************************************************************************
mov ax,cs ; ax = 0
mov ss,ax ; ss = 0
add ax,1000h
mov ds,ax
mov sp,07c00h ; sp = 0x7c00
mov bp,sp ; bp = 0x7c00
mov ah,8 ; ah = 8 - Get Drive Parameters Function
mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
int 13h ; Get Drive Parameters
xor ax,ax ; ax = 0
mov al,dh ; al = dh
inc al ; MaxHead = al + 1
push ax ; 0000:7bfe = MaxHead
mov al,cl ; al = cl
and al,03fh ; MaxSector = al & 0x3f
push ax ; 0000:7bfc = MaxSector
cmp word ptr [bp+SectorSignature],0aa55h ; Verify Boot Sector Signature
jne BadBootSector
mov cx,word ptr [bp+RootEntries] ; cx = RootEntries
shl cx,FAT_DIRECTORY_ENTRY_SHIFT ; cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
mov bx,cx ; bx = size of the Root Directory in bytes
and bx,BLOCK_MASK ; See if it is an even number of sectors long
jne BadBootSector ; If is isn't, then the boot sector is bad.
mov bx,cx ; bx = size of the Root Directory in bytes
shr bx,BLOCK_SHIFT ; bx = size of Root Directory in sectors
mov al,byte ptr [bp+NoFats] ; al = NoFats
xor ah,ah ; ah = 0 ==> ax = NoFats
mul word ptr [bp+SectorsPerFat32] ; ax = NoFats * SectorsPerFat
add ax,word ptr [bp+ReservedSectors] ; ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
add ax,bx ; ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA
mov word ptr [bp],ax ; Save FirstClusterLBA for later use
mov ax,word ptr [bp+RootCluster] ; ax = StartCluster of Root Directory
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster]; bx = SectorsPerCluster
mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
push ds
pop es
xor di,di ; Store directory in es:di = 1000:0000
call ReadBlocks ; Read StartCluster of Root Directory
; dx - variable storage (initial value is 0)
; bx - loader (initial value is 0)
xor dx, dx
xor bx, bx
FindEFILDR:
cmp dword ptr [di],LOADER_FILENAME_PART1 ; Compare to "EFIL"
jne FindVARSTORE
cmp dword ptr [di+4],LOADER_FILENAME_PART2
jne FindVARSTORE
cmp dword ptr [di+7],LOADER_FILENAME_PART3
jne FindVARSTORE
mov bx, word ptr [di+26] ; bx = Start Cluster for EFILDR <----------------------------------
test dx, dx
je FindNext ; Efivar.bin is not loaded
jmp FoundAll
FindVARSTORE:
; if the file is not loader file, see if it's "EFIVAR BIN"
cmp dword ptr [di], 056494645h ; Compare to "EFIV"
jne FindNext
cmp dword ptr [di+4], 020205241h ; Compare to "AR "
jne FindNext
cmp dword ptr [di+7], 04e494220h ; Compare to " BIN"
jne FindNext
mov dx, di ; dx = Offset of Start Cluster for Efivar.bin <---------------------
add dx, 26
test bx, bx
je FindNext ; Efildr is not loaded
jmp FoundAll
FindNext:
; go to next find
add di,FAT_DIRECTORY_ENTRY_SIZE ; Increment di
sub cx,FAT_DIRECTORY_ENTRY_SIZE ; Decrement cx
; TODO: jump to FindVarStore if ...
jne FindEFILDR
jmp NotFoundAll
FoundAll:
FoundEFILDR:
mov cx,bx ; cx = Start Cluster for EFILDR <----------------------------------
mov ax,cs ; Destination = 2000:0000
add ax,2000h
mov es,ax
xor di,di
ReadFirstClusterOfEFILDR:
mov ax,cx ; ax = StartCluster
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
push dx
mul bx
pop dx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = Number of Sectors in a cluster
push es
call ReadBlocks
pop ax
JumpIntoFirstSectorOfEFILDR:
mov word ptr [bp+JumpSegment],ax
JumpFarInstruction:
db 0eah
JumpOffset:
dw 0000h
JumpSegment:
dw 2000h
PrintString:
mov ax,0b800h
mov es,ax
mov ax, 07c0h
mov ds, ax
mov cx, 6
mov di, 160
rep movsw
ret
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; AX = Start LBA
; BX = Number of Blocks to Read
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; cx = Blocks
; bx = NumberOfBlocks
; si = StartLBA
ReadBlocks:
pusha
add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
mov esi,eax ; esi = Start LBA
mov cx,bx ; cx = Number of blocks to read
ReadCylinderLoop:
mov bp,07bfch ; bp = 0x7bfc
mov eax,esi ; eax = Start LBA
xor edx,edx ; edx = 0
movzx ebx,word ptr [bp] ; bx = MaxSector
div ebx ; ax = StartLBA / MaxSector
inc dx ; dx = (StartLBA % MaxSector) + 1
sub bx,dx ; bx = MaxSector - Sector
inc bx ; bx = MaxSector - Sector + 1
cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
mov bx,cx ; bx = Blocks
LimitTransfer:
push cx
mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
xor dx,dx ; dx = 0
div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
; dx = ax % (MaxHead + 1) = Head
push bx ; Save number of blocks to transfer
mov dh,dl ; dh = Head
mov bp,07c00h ; bp = 0x7c00
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
mov ch,al ; ch = Cylinder
mov al,bl ; al = Blocks
mov ah,2 ; ah = Function 2
mov bx,di ; es:bx = Buffer address
int 013h
jc DiskError
pop bx
pop cx
movzx ebx,bx
add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
sub cx,bx ; Blocks = Blocks - NumberOfBlocks
mov ax,es
shl bx,(BLOCK_SHIFT-4)
add ax,bx
mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmp cx,0
jne ReadCylinderLoop
popa
ret
; ****************************************************************************
; ERROR Condition:
; ****************************************************************************
NotFoundAll:
; if we found EFILDR, continue
test bx,bx
jne FoundEFILDR
BadBootSector:
DiskError:
mov si, offset ErrorString
call PrintString
Halt:
jmp Halt
StartString:
db 'B', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch
ErrorString:
db 'B', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch
; ****************************************************************************
; LBA Offset for BootSector, need patched by tool for HD boot.
; ****************************************************************************
org 01fah
LBAOffsetForBootSector:
dd 0h
; ****************************************************************************
; Sector Signature
; ****************************************************************************
org 01feh
SectorSignature:
dw 0aa55h ; Boot Sector Signature
end

File diff suppressed because it is too large Load Diff

View File

@@ -1,582 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* efi32.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Now in 32-bit protected mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.486
.model flat
.stack
.code
org 21000h
DEFAULT_HANDLER_SIZE EQU INT1 - INT0
JmpCommonIdtEntry macro
; jmp commonIdtEntry - this must be hand coded to keep the assembler from
; using a 8 bit reletive jump when the entries are
; within 255 bytes of the common entry. This must
; be done to maintain the consistency of the size
; of entry points...
db 0e9h ; jmp 16 bit relative
dd commonIdtEntry - $ - 4 ; offset to jump to
endm
Start:
mov ax,bx ; flat data descriptor in BX
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov esp,0001ffff0h
call ClearScreen
; Populate IDT with meaningful offsets for exception handlers...
sidt fword ptr [Idtr] ; get fword address of IDT
mov eax, offset Halt
mov ebx, eax ; use bx to copy 15..0 to descriptors
shr eax, 16 ; use ax to copy 31..16 to descriptors
mov ecx, 78h ; 78h IDT entries to initialize with unique entry points (exceptions)
mov esi, [offset Idtr + 2]
mov edi, [esi]
@@: ; loop through all IDT entries exception handlers and initialize to default handler
mov word ptr [edi], bx ; write bits 15..0 of offset
mov word ptr [edi+2], 20h ; SYS_CODE_SEL from GDT
mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
mov word ptr [edi+6], ax ; write bits 31..16 of offset
add edi, 8 ; move up to next descriptor
add bx, DEFAULT_HANDLER_SIZE ; move to next entry point
loop @b ; loop back through again until all descriptors are initialized
;; at this point edi contains the offset of the descriptor for INT 20
;; and bx contains the low 16 bits of the offset of the default handler
;; so initialize all the rest of the descriptors with these two values...
; mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
;@@: ; loop through all IDT entries exception handlers and initialize to default handler
; mov word ptr [edi], bx ; write bits 15..0 of offset
; mov word ptr [edi+2], 20h ; SYS_CODE_SEL from GDT
; mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
; mov word ptr [edi+6], ax ; write bits 31..16 of offset
; add edi, 8 ; move up to next descriptor
; loop @b ; loop back through again until all descriptors are initialized
;; DUMP location of IDT and several of the descriptors
; mov ecx, 8
; mov eax, [offset Idtr + 2]
; mov eax, [eax]
; mov edi, 0b8000h
; call PrintDword
; mov esi, eax
; mov edi, 0b80a0h
; jmp OuterLoop
;;
;; just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
; mov eax, 011111111h
; mov ebx, 022222222h
; mov ecx, 033333333h
; mov edx, 044444444h
; mov ebp, 055555555h
; mov esi, 066666666h
; mov edi, 077777777h
; push 011111111h
; push 022222222h
; push 033333333h
; int 119
mov esi,022000h ; esi = 22000
mov eax,[esi+014h] ; eax = [22014]
add esi,eax ; esi = 22000 + [22014] = Base of EFILDR.C
mov ebp,[esi+03ch] ; ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
add ebp,esi
mov edi,[ebp+034h] ; edi = [[22000 + [22014] + 3c] + 30] = ImageBase
mov eax,[ebp+028h] ; eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
add eax,edi ; eax = ImageBase + EntryPoint
mov dword ptr [EfiLdrOffset],eax ; Modify far jump instruction for correct entry point
mov bx,word ptr[ebp+6] ; bx = Number of sections
xor eax,eax
mov ax,word ptr[ebp+014h] ; ax = Optional Header Size
add ebp,eax
add ebp,018h ; ebp = Start of 1st Section
SectionLoop:
push esi ; Save Base of EFILDR.C
push edi ; Save ImageBase
add esi,[ebp+014h] ; esi = Base of EFILDR.C + PointerToRawData
add edi,[ebp+00ch] ; edi = ImageBase + VirtualAddress
mov ecx,[ebp+010h] ; ecs = SizeOfRawData
cld
shr ecx,2
rep movsd
pop edi ; Restore ImageBase
pop esi ; Restore Base of EFILDR.C
add bp,028h ; ebp = ebp + 028h = Pointer to next section record
dec bx
cmp bx,0
jne SectionLoop
movzx eax, word ptr [Idtr] ; get size of IDT
inc eax
add eax, dword ptr [Idtr + 2] ; add to base of IDT to get location of memory map...
push eax ; push memory map location on stack for call to EFILDR...
push eax ; push return address (useless, just for stack balance)
db 0b8h
EfiLdrOffset:
dd 000401000h ; Offset of EFILDR
; mov eax, 401000h
push eax
ret
; db "**** DEFAULT IDT ENTRY ***",0
align 02h
Halt:
INT0:
push 0h ; push error code place holder on the stack
push 0h
JmpCommonIdtEntry
; db 0e9h ; jmp 16 bit reletive
; dd commonIdtEntry - $ - 4 ; offset to jump to
INT1:
push 0h ; push error code place holder on the stack
push 1h
JmpCommonIdtEntry
INT2:
push 0h ; push error code place holder on the stack
push 2h
JmpCommonIdtEntry
INT3:
push 0h ; push error code place holder on the stack
push 3h
JmpCommonIdtEntry
INT4:
push 0h ; push error code place holder on the stack
push 4h
JmpCommonIdtEntry
INT5:
push 0h ; push error code place holder on the stack
push 5h
JmpCommonIdtEntry
INT6:
push 0h ; push error code place holder on the stack
push 6h
JmpCommonIdtEntry
INT7:
push 0h ; push error code place holder on the stack
push 7h
JmpCommonIdtEntry
INT8:
; Double fault causes an error code to be pushed so no phony push necessary
nop
nop
push 8h
JmpCommonIdtEntry
INT9:
push 0h ; push error code place holder on the stack
push 9h
JmpCommonIdtEntry
INT10:
; Invalid TSS causes an error code to be pushed so no phony push necessary
nop
nop
push 10
JmpCommonIdtEntry
INT11:
; Segment Not Present causes an error code to be pushed so no phony push necessary
nop
nop
push 11
JmpCommonIdtEntry
INT12:
; Stack fault causes an error code to be pushed so no phony push necessary
nop
nop
push 12
JmpCommonIdtEntry
INT13:
; GP fault causes an error code to be pushed so no phony push necessary
nop
nop
push 13
JmpCommonIdtEntry
INT14:
; Page fault causes an error code to be pushed so no phony push necessary
nop
nop
push 14
JmpCommonIdtEntry
INT15:
push 0h ; push error code place holder on the stack
push 15
JmpCommonIdtEntry
INT16:
push 0h ; push error code place holder on the stack
push 16
JmpCommonIdtEntry
INT17:
; Alignment check causes an error code to be pushed so no phony push necessary
nop
nop
push 17
JmpCommonIdtEntry
INT18:
push 0h ; push error code place holder on the stack
push 18
JmpCommonIdtEntry
INT19:
push 0h ; push error code place holder on the stack
push 19
JmpCommonIdtEntry
INTUnknown:
REPEAT (78h - 20)
push 0h ; push error code place holder on the stack
; push xxh ; push vector number
db 06ah
db ( $ - INTUnknown - 3 ) / 9 + 20 ; vector number
JmpCommonIdtEntry
ENDM
commonIdtEntry:
pushad
mov ebp, esp
;;
;; At this point the stack looks like this:
;;
;; eflags
;; Calling CS
;; Calling EIP
;; Error code or 0
;; Int num or 0ffh for unknown int num
;; eax
;; ecx
;; edx
;; ebx
;; esp
;; ebp
;; esi
;; edi <------- ESP, EBP
;;
call ClearScreen
mov esi, offset String1
call PrintString
mov eax, [ebp + 32] ;; move Int number into EAX
cmp eax, 19
ja PrintDefaultString
PrintExceptionString:
shl eax, 2 ;; multiply by 4 to get offset from StringTable to actual string address
add eax, offset StringTable
mov esi, [eax]
jmp PrintTheString
PrintDefaultString:
mov esi, offset IntUnknownString
; patch Int number
mov edx, eax
call A2C
mov [esi + 1], al
mov eax, edx
shr eax, 4
call A2C
mov [esi], al
PrintTheString:
call PrintString
mov esi, offset String2
call PrintString
mov eax, [ebp+44] ; CS
call PrintDword
mov al, ':'
mov byte ptr [edi], al
add edi, 2
mov eax, [ebp+40] ; EIP
call PrintDword
mov esi, offset String3
call PrintString
mov edi, 0b8140h
mov esi, offset StringEax ; eax
call PrintString
mov eax, [ebp+28]
call PrintDword
mov esi, offset StringEbx ; ebx
call PrintString
mov eax, [ebp+16]
call PrintDword
mov esi, offset StringEcx ; ecx
call PrintString
mov eax, [ebp+24]
call PrintDword
mov esi, offset StringEdx ; edx
call PrintString
mov eax, [ebp+20]
call PrintDword
mov esi, offset StringEcode ; error code
call PrintString
mov eax, [ebp+36]
call PrintDword
mov edi, 0b81e0h
mov esi, offset StringEsp ; esp
call PrintString
mov eax, [ebp+12]
call PrintDword
mov esi, offset StringEbp ; ebp
call PrintString
mov eax, [ebp+8]
call PrintDword
mov esi, offset StringEsi ; esi
call PrintString
mov eax, [ebp+4]
call PrintDword
mov esi, offset StringEdi ; edi
call PrintString
mov eax, [ebp]
call PrintDword
mov esi, offset StringEflags ; eflags
call PrintString
mov eax, [ebp+48]
call PrintDword
mov edi, 0b8320h
mov esi, ebp
add esi, 52
mov ecx, 8
OuterLoop:
push ecx
mov ecx, 8
mov edx, edi
InnerLoop:
mov eax, [esi]
call PrintDword
add esi, 4
mov al, ' '
mov [edi], al
add edi, 2
loop InnerLoop
pop ecx
add edx, 0a0h
mov edi, edx
loop OuterLoop
mov edi, 0b8960h
mov eax, [ebp+40] ; EIP
sub eax, 32 * 4
mov esi, eax ; esi = eip - 32 DWORD linear (total 64 DWORD)
mov ecx, 8
OuterLoop1:
push ecx
mov ecx, 8
mov edx, edi
InnerLoop1:
mov eax, [esi]
call PrintDword
add esi, 4
mov al, ' '
mov [edi], al
add edi, 2
loop InnerLoop1
pop ecx
add edx, 0a0h
mov edi, edx
loop OuterLoop1
; wbinvd ; Ken: this intruction does not support in early than 486 arch
@@:
jmp @b
;
; return
;
mov esp, ebp
popad
add esp, 8 ; error code and INT number
iretd
PrintString:
push eax
@@:
mov al, byte ptr [esi]
cmp al, 0
je @f
mov byte ptr [edi], al
inc esi
add edi, 2
jmp @b
@@:
pop eax
ret
;; EAX contains dword to print
;; EDI contains memory location (screen location) to print it to
PrintDword:
push ecx
push ebx
push eax
mov ecx, 8
looptop:
rol eax, 4
mov bl, al
and bl, 0fh
add bl, '0'
cmp bl, '9'
jle @f
add bl, 7
@@:
mov byte ptr [edi], bl
add edi, 2
loop looptop
;wbinvd
pop eax
pop ebx
pop ecx
ret
ClearScreen:
push eax
push ecx
mov al, ' '
mov ah, 0ch
mov edi, 0b8000h
mov ecx, 80 * 24
@@:
mov word ptr [edi], ax
add edi, 2
loop @b
mov edi, 0b8000h
pop ecx
pop eax
ret
A2C:
and al, 0fh
add al, '0'
cmp al, '9'
jle @f
add al, 7
@@:
ret
String1 db "*** INT ",0
Int0String db "00h Divide by 0 -",0
Int1String db "01h Debug exception -",0
Int2String db "02h NMI -",0
Int3String db "03h Breakpoint -",0
Int4String db "04h Overflow -",0
Int5String db "05h Bound -",0
Int6String db "06h Invalid opcode -",0
Int7String db "07h Device not available -",0
Int8String db "08h Double fault -",0
Int9String db "09h Coprocessor seg overrun (reserved) -",0
Int10String db "0Ah Invalid TSS -",0
Int11String db "0Bh Segment not present -",0
Int12String db "0Ch Stack fault -",0
Int13String db "0Dh General protection fault -",0
Int14String db "0Eh Page fault -",0
Int15String db "0Fh (Intel reserved) -",0
Int16String db "10h Floating point error -",0
Int17String db "11h Alignment check -",0
Int18String db "12h Machine check -",0
Int19String db "13h SIMD Floating-Point Exception -",0
IntUnknownString db "??h Unknown interrupt -",0
StringTable dd offset Int0String, offset Int1String, offset Int2String, offset Int3String,
offset Int4String, offset Int5String, offset Int6String, offset Int7String,
offset Int8String, offset Int9String, offset Int10String, offset Int11String,
offset Int12String, offset Int13String, offset Int14String, offset Int15String,
offset Int16String, offset Int17String, offset Int18String, offset Int19String
String2 db " HALT!! *** (",0
String3 db ")",0
StringEax db "EAX=",0
StringEbx db " EBX=",0
StringEcx db " ECX=",0
StringEdx db " EDX=",0
StringEcode db " ECODE=",0
StringEsp db "ESP=",0
StringEbp db " EBP=",0
StringEsi db " ESI=",0
StringEdi db " EDI=",0
StringEflags db " EFLAGS=",0
Idtr df 0
org 21ffeh
BlockSignature:
dw 0aa55h
end

File diff suppressed because it is too large Load Diff

View File

@@ -1,787 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* efi64.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Now in 64-bit long mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.486
.model flat
.stack
.code
org 21000h
DEFAULT_HANDLER_SIZE EQU INT1 - INT0
JmpCommonIdtEntry macro
; jmp commonIdtEntry - this must be hand coded to keep the assembler from
; using a 8 bit reletive jump when the entries are
; within 255 bytes of the common entry. This must
; be done to maintain the consistency of the size
; of entry points...
db 0e9h ; jmp 16 bit reletive
dd commonIdtEntry - $ - 4 ; offset to jump to
endm
Start:
mov esp,0001fffe8h ; make final stack aligned
; set OSFXSR and OSXMMEXCPT because some code will use XMM register
db 0fh
db 20h
db 0e0h
; mov rax, cr4
bts eax, 9
bts eax, 0ah
db 0fh
db 22h
db 0e0h
; mov cr4, rax
call ClearScreen
; Populate IDT with meaningful offsets for exception handlers...
mov eax, offset Idtr
sidt fword ptr [eax] ; get fword address of IDT
mov eax, offset Halt
mov ebx, eax ; use bx to copy 15..0 to descriptors
shr eax, 16 ; use ax to copy 31..16 to descriptors
; 63..32 of descriptors is 0
mov ecx, 78h ; 78h IDT entries to initialize with unique entry points (exceptions)
mov esi, [offset Idtr + 2]
mov edi, [esi]
@@: ; loop through all IDT entries exception handlers and initialize to default handler
mov word ptr [edi], bx ; write bits 15..0 of offset
mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT
mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
mov word ptr [edi+6], ax ; write bits 31..16 of offset
mov dword ptr [edi+8], 0 ; write bits 63..32 of offset
add edi, 16 ; move up to next descriptor
add bx, DEFAULT_HANDLER_SIZE ; move to next entry point
loop @b ; loop back through again until all descriptors are initialized
;; at this point edi contains the offset of the descriptor for INT 20
;; and bx contains the low 16 bits of the offset of the default handler
;; so initialize all the rest of the descriptors with these two values...
; mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
;@@: ; loop through all IDT entries exception handlers and initialize to default handler
; mov word ptr [edi], bx ; write bits 15..0 of offset
; mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT
; mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
; mov word ptr [edi+6], ax ; write bits 31..16 of offset
; mov dword ptr [edi+8], 0 ; write bits 63..32 of offset
; add edi, 16 ; move up to next descriptor
; loop @b ; loop back through again until all descriptors are initialized
;; DUMP location of IDT and several of the descriptors
; mov ecx, 8
; mov eax, [offset Idtr + 2]
; mov eax, [eax]
; mov edi, 0b8000h
; call PrintQword
; mov esi, eax
; mov edi, 0b80a0h
; jmp OuterLoop
;;
;; just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
; mov eax, 011111111h
; mov ebx, 022222222h
; mov ecx, 033333333h
; mov edx, 044444444h
; mov ebp, 055555555h
; mov esi, 066666666h
; mov edi, 077777777h
; push 011111111h
; push 022222222h
; push 033333333h
; int 119
mov esi,022000h ; esi = 22000
mov eax,[esi+014h] ; eax = [22014]
add esi,eax ; esi = 22000 + [22014] = Base of EFILDR.C
mov ebp,[esi+03ch] ; ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
add ebp,esi
mov edi,[ebp+030h] ; edi = [[22000 + [22014] + 3c] + 2c] = ImageBase (63..32 is zero, ignore)
mov eax,[ebp+028h] ; eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
add eax,edi ; eax = ImageBase + EntryPoint
mov ebx, offset EfiLdrOffset
mov dword ptr [ebx],eax ; Modify far jump instruction for correct entry point
mov bx,word ptr[ebp+6] ; bx = Number of sections
xor eax,eax
mov ax,word ptr[ebp+014h] ; ax = Optional Header Size
add ebp,eax
add ebp,018h ; ebp = Start of 1st Section
SectionLoop:
push esi ; Save Base of EFILDR.C
push edi ; Save ImageBase
add esi,[ebp+014h] ; esi = Base of EFILDR.C + PointerToRawData
add edi,[ebp+00ch] ; edi = ImageBase + VirtualAddress
mov ecx,[ebp+010h] ; ecs = SizeOfRawData
cld
shr ecx,2
rep movsd
pop edi ; Restore ImageBase
pop esi ; Restore Base of EFILDR.C
add bp,028h ; ebp = ebp + 028h = Pointer to next section record
db 66h
db 0ffh
db 0cbh
; dec bx
cmp bx,0
jne SectionLoop
mov edx, offset Idtr
movzx eax, word ptr [edx] ; get size of IDT
db 0ffh
db 0c0h
; inc eax
add eax, dword ptr [edx + 2] ; add to base of IDT to get location of memory map...
xor ecx, ecx
mov ecx, eax ; put argument to RCX
db 48h
db 0c7h
db 0c0h
EfiLdrOffset:
dd 000401000h ; Offset of EFILDR
; mov rax, 401000h
db 50h
; push rax
; ret
db 0c3h
; db "**** DEFAULT IDT ENTRY ***",0
align 02h
Halt:
INT0:
push 0h ; push error code place holder on the stack
push 0h
JmpCommonIdtEntry
; db 0e9h ; jmp 16 bit reletive
; dd commonIdtEntry - $ - 4 ; offset to jump to
INT1:
push 0h ; push error code place holder on the stack
push 1h
JmpCommonIdtEntry
INT2:
push 0h ; push error code place holder on the stack
push 2h
JmpCommonIdtEntry
INT3:
push 0h ; push error code place holder on the stack
push 3h
JmpCommonIdtEntry
INT4:
push 0h ; push error code place holder on the stack
push 4h
JmpCommonIdtEntry
INT5:
push 0h ; push error code place holder on the stack
push 5h
JmpCommonIdtEntry
INT6:
push 0h ; push error code place holder on the stack
push 6h
JmpCommonIdtEntry
INT7:
push 0h ; push error code place holder on the stack
push 7h
JmpCommonIdtEntry
INT8:
; Double fault causes an error code to be pushed so no phony push necessary
nop
nop
push 8h
JmpCommonIdtEntry
INT9:
push 0h ; push error code place holder on the stack
push 9h
JmpCommonIdtEntry
INT10:
; Invalid TSS causes an error code to be pushed so no phony push necessary
nop
nop
push 10
JmpCommonIdtEntry
INT11:
; Segment Not Present causes an error code to be pushed so no phony push necessary
nop
nop
push 11
JmpCommonIdtEntry
INT12:
; Stack fault causes an error code to be pushed so no phony push necessary
nop
nop
push 12
JmpCommonIdtEntry
INT13:
; GP fault causes an error code to be pushed so no phony push necessary
nop
nop
push 13
JmpCommonIdtEntry
INT14:
; Page fault causes an error code to be pushed so no phony push necessary
nop
nop
push 14
JmpCommonIdtEntry
INT15:
push 0h ; push error code place holder on the stack
push 15
JmpCommonIdtEntry
INT16:
push 0h ; push error code place holder on the stack
push 16
JmpCommonIdtEntry
INT17:
; Alignment check causes an error code to be pushed so no phony push necessary
nop
nop
push 17
JmpCommonIdtEntry
INT18:
push 0h ; push error code place holder on the stack
push 18
JmpCommonIdtEntry
INT19:
push 0h ; push error code place holder on the stack
push 19
JmpCommonIdtEntry
INTUnknown:
REPEAT (78h - 20)
push 0h ; push error code place holder on the stack
; push xxh ; push vector number
db 06ah
db ( $ - INTUnknown - 3 ) / 9 + 20 ; vector number
JmpCommonIdtEntry
ENDM
commonIdtEntry:
push eax
push ecx
push edx
push ebx
push esp
push ebp
push esi
push edi
db 41h
db 50h
; push r8
db 41h
db 51h
; push r9
db 41h
db 52h
; push r10
db 41h
db 53h
; push r11
db 41h
db 54h
; push r12
db 41h
db 55h
; push r13
db 41h
db 56h
; push r14
db 41h
db 57h
; push r15
db 48h
mov ebp, esp
; mov rbp, rsp
;;
;; At this point the stack looks like this:
;;
;; Calling SS
;; Calling RSP
;; rflags
;; Calling CS
;; Calling RIP
;; Error code or 0
;; Int num or 0ffh for unknown int num
;; rax
;; rcx
;; rdx
;; rbx
;; rsp
;; rbp
;; rsi
;; rdi
;; r8
;; r9
;; r10
;; r11
;; r12
;; r13
;; r14
;; r15 <------- RSP, RBP
;;
call ClearScreen
mov esi, offset String1
call PrintString
db 48h
mov eax, [ebp + 16*8] ;; move Int number into RAX
db 48h
cmp eax, 18
ja PrintDefaultString
PrintExceptionString:
shl eax, 3 ;; multiply by 8 to get offset from StringTable to actual string address
add eax, offset StringTable
mov esi, [eax]
jmp PrintTheString
PrintDefaultString:
mov esi, offset IntUnknownString
; patch Int number
mov edx, eax
call A2C
mov [esi + 1], al
mov eax, edx
shr eax, 4
call A2C
mov [esi], al
PrintTheString:
call PrintString
mov esi, offset String2
call PrintString
db 48h
mov eax, [ebp+19*8] ; CS
call PrintQword
mov al, ':'
mov byte ptr [edi], al
add edi, 2
db 48h
mov eax, [ebp+18*8] ; RIP
call PrintQword
mov esi, offset String3
call PrintString
mov edi, 0b8140h
mov esi, offset StringRax ; rax
call PrintString
db 48h
mov eax, [ebp+15*8]
call PrintQword
mov esi, offset StringRcx ; rcx
call PrintString
db 48h
mov eax, [ebp+14*8]
call PrintQword
mov esi, offset StringRdx ; rdx
call PrintString
db 48h
mov eax, [ebp+13*8]
call PrintQword
mov edi, 0b81e0h
mov esi, offset StringRbx ; rbx
call PrintString
db 48h
mov eax, [ebp+12*8]
call PrintQword
mov esi, offset StringRsp ; rsp
call PrintString
db 48h
mov eax, [ebp+21*8]
call PrintQword
mov esi, offset StringRbp ; rbp
call PrintString
db 48h
mov eax, [ebp+10*8]
call PrintQword
mov edi, 0b8280h
mov esi, offset StringRsi ; rsi
call PrintString
db 48h
mov eax, [ebp+9*8]
call PrintQword
mov esi, offset StringRdi ; rdi
call PrintString
db 48h
mov eax, [ebp+8*8]
call PrintQword
mov esi, offset StringEcode ; error code
call PrintString
db 48h
mov eax, [ebp+17*8]
call PrintQword
mov edi, 0b8320h
mov esi, offset StringR8 ; r8
call PrintString
db 48h
mov eax, [ebp+7*8]
call PrintQword
mov esi, offset StringR9 ; r9
call PrintString
db 48h
mov eax, [ebp+6*8]
call PrintQword
mov esi, offset StringR10 ; r10
call PrintString
db 48h
mov eax, [ebp+5*8]
call PrintQword
mov edi, 0b83c0h
mov esi, offset StringR11 ; r11
call PrintString
db 48h
mov eax, [ebp+4*8]
call PrintQword
mov esi, offset StringR12 ; r12
call PrintString
db 48h
mov eax, [ebp+3*8]
call PrintQword
mov esi, offset StringR13 ; r13
call PrintString
db 48h
mov eax, [ebp+2*8]
call PrintQword
mov edi, 0b8460h
mov esi, offset StringR14 ; r14
call PrintString
db 48h
mov eax, [ebp+1*8]
call PrintQword
mov esi, offset StringR15 ; r15
call PrintString
db 48h
mov eax, [ebp+0*8]
call PrintQword
mov esi, offset StringSs ; ss
call PrintString
db 48h
mov eax, [ebp+22*8]
call PrintQword
mov edi, 0b8500h
mov esi, offset StringRflags ; rflags
call PrintString
db 48h
mov eax, [ebp+20*8]
call PrintQword
mov edi, 0b8640h
mov esi, ebp
add esi, 23*8
mov ecx, 4
OuterLoop:
push ecx
mov ecx, 4
db 48h
mov edx, edi
InnerLoop:
db 48h
mov eax, [esi]
call PrintQword
add esi, 8
mov al, ' '
mov [edi], al
add edi, 2
loop InnerLoop
pop ecx
add edx, 0a0h
mov edi, edx
loop OuterLoop
mov edi, 0b8960h
db 48h
mov eax, [ebp+18*8] ; RIP
sub eax, 8 * 8
db 48h
mov esi, eax ; esi = rip - 8 QWORD linear (total 16 QWORD)
mov ecx, 4
OuterLoop1:
push ecx
mov ecx, 4
mov edx, edi
InnerLoop1:
db 48h
mov eax, [esi]
call PrintQword
add esi, 8
mov al, ' '
mov [edi], al
add edi, 2
loop InnerLoop1
pop ecx
add edx, 0a0h
mov edi, edx
loop OuterLoop1
;wbinvd
@@:
jmp @b
;
; return
;
mov esp, ebp
; mov rsp, rbp
db 41h
db 5fh
; pop r15
db 41h
db 5eh
; pop r14
db 41h
db 5dh
; pop r13
db 41h
db 5ch
; pop r12
db 41h
db 5bh
; pop r11
db 41h
db 5ah
; pop r10
db 41h
db 59h
; pop r9
db 41h
db 58h
; pop r8
pop edi
pop esi
pop ebp
pop eax ; esp
pop ebx
pop edx
pop ecx
pop eax
db 48h
db 83h
db 0c4h
db 10h
; add esp, 16 ; error code and INT number
db 48h
db 0cfh
; iretq
PrintString:
push eax
@@:
mov al, byte ptr [esi]
cmp al, 0
je @f
mov byte ptr [edi], al
db 0ffh
db 0c6h
; inc esi
add edi, 2
jmp @b
@@:
pop eax
ret
;; RAX contains qword to print
;; RDI contains memory location (screen location) to print it to
PrintQword:
push ecx
push ebx
push eax
db 48h
db 0c7h
db 0c1h
dd 16
; mov rcx, 16
looptop:
db 48h
rol eax, 4
mov bl, al
and bl, 0fh
add bl, '0'
cmp bl, '9'
jle @f
add bl, 7
@@:
mov byte ptr [edi], bl
add edi, 2
loop looptop
;wbinvd
pop eax
pop ebx
pop ecx
ret
ClearScreen:
push eax
push ecx
mov al, ' '
mov ah, 0ch
mov edi, 0b8000h
mov ecx, 80 * 24
@@:
mov word ptr [edi], ax
add edi, 2
loop @b
mov edi, 0b8000h
pop ecx
pop eax
ret
A2C:
and al, 0fh
add al, '0'
cmp al, '9'
jle @f
add al, 7
@@:
ret
String1 db "*** INT ",0
Int0String db "00h Divide by 0 -",0
Int1String db "01h Debug exception -",0
Int2String db "02h NMI -",0
Int3String db "03h Breakpoint -",0
Int4String db "04h Overflow -",0
Int5String db "05h Bound -",0
Int6String db "06h Invalid opcode -",0
Int7String db "07h Device not available -",0
Int8String db "08h Double fault -",0
Int9String db "09h Coprocessor seg overrun (reserved) -",0
Int10String db "0Ah Invalid TSS -",0
Int11String db "0Bh Segment not present -",0
Int12String db "0Ch Stack fault -",0
Int13String db "0Dh General protection fault -",0
Int14String db "0Eh Page fault -",0
Int15String db "0Fh (Intel reserved) -",0
Int16String db "10h Floating point error -",0
Int17String db "11h Alignment check -",0
Int18String db "12h Machine check -",0
Int19String db "13h SIMD Floating-Point Exception -",0
IntUnknownString db "??h Unknown interrupt -",0
StringTable dq offset Int0String, offset Int1String, offset Int2String, offset Int3String,
offset Int4String, offset Int5String, offset Int6String, offset Int7String,
offset Int8String, offset Int9String, offset Int10String, offset Int11String,
offset Int12String, offset Int13String, offset Int14String, offset Int15String,
offset Int16String, offset Int17String, offset Int18String, offset Int19String
String2 db " HALT!! *** (",0
String3 db ")",0
StringRax db "RAX=",0
StringRcx db " RCX=",0
StringRdx db " RDX=",0
StringRbx db "RBX=",0
StringRsp db " RSP=",0
StringRbp db " RBP=",0
StringRsi db "RSI=",0
StringRdi db " RDI=",0
StringEcode db " ECODE=",0
StringR8 db "R8 =",0
StringR9 db " R9 =",0
StringR10 db " R10=",0
StringR11 db "R11=",0
StringR12 db " R12=",0
StringR13 db " R13=",0
StringR14 db "R14=",0
StringR15 db " R15=",0
StringSs db " SS =",0
StringRflags db "RFLAGS=",0
Idtr df 0
df 0
org 21ffeh
BlockSignature:
dw 0aa55h
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,919 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* start.S
#*
#* Abstract:
#*
#------------------------------------------------------------------------------
.stack:
.486p:
.code16
.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
.org 0x0
.global _start
_start:
Ia32Jump:
jmp BootSectorEntryPoint # JMP inst - 3 bytes
nop
OemId: .ascii "INTEL " # OemId - 8 bytes
SectorSize: .word 0 # Sector Size - 16 bits
SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
ReservedSectors: .word 0 # Reserved Sectors - 16 bits
NoFats: .byte 0 # Number of FATs - 8 bits
RootEntries: .word 0 # Root Entries - 16 bits
Sectors: .word 0 # Number of Sectors - 16 bits
Media: .byte 0 # Media - 8 bits - ignored
SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
Heads: .word 0 # Heads - 16 bits - ignored
HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
LargeSectors: .long 0 # Large Sectors - 32 bits
PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
CurrentHead: .byte 0 # Current Head - 8 bits
Signature: .byte 0 # Signature - 8 bits - ignored
VolId: .ascii " " # Volume Serial Number- 4 bytes
FatLabel: .ascii " " # Label - 11 bytes
SystemId: .ascii "FAT12 " # SystemId - 8 bytes
BootSectorEntryPoint:
#ASSUME ds:@code
#ASSUME ss:@code
# ds = 1000, es = 2000 + x (size of first cluster >> 4)
# cx = Start Cluster of EfiLdr
# dx = Start Cluster of Efivar.bin
# Re use the BPB data stored in Boot Sector
movw $0x7c00, %bp
pushw %cx
# Read Efivar.bin
# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
movw $0x1900, %ax
movw %ax, %es
testw %dx, %dx
jnz CheckVarStoreSize
movb $1, %al
NoVarStore:
pushw %es
# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
movb %al, %es:(4)
jmp SaveVolumeId
CheckVarStoreSize:
movw %dx, %di
cmpl $0x4000, %ds:2(%di)
movb $2, %al
jne NoVarStore
LoadVarStore:
movb $0, %al
movb %al, %es:(4)
movw (%di), %cx
# ES:DI = 1500:0
xorw %di, %di
pushw %es
movw $0x1500, %ax
movw %ax, %es
call ReadFile
SaveVolumeId:
popw %es
movw VolId(%bp), %ax
movw %ax, %es:(0) # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
movw VolId+2(%bp), %ax
movw %ax, %es:(2)
# Read Efildr
popw %cx
# cx = Start Cluster of Efildr -> BS.com has filled already
# ES:DI = 2000:0, first cluster will be read again
xorw %di, %di # di = 0
movw $0x2000, %ax
movw %ax, %es
call ReadFile
movw %cs, %ax
movw %ax, %cs:JumpSegment
JumpFarInstruction:
.byte 0xea
JumpOffset:
.word 0x200
JumpSegment:
.word 0x2000
# ****************************************************************************
# ReadFile
#
# Arguments:
# CX = Start Cluster of File
# ES:DI = Buffer to store file content read from disk
#
# Return:
# (ES << 4 + DI) = end of file content Buffer
#
# ****************************************************************************
ReadFile:
# si = NumberOfClusters
# cx = ClusterNumber
# dx = CachedFatSectorNumber
# ds:0000 = CacheFatSectorBuffer
# es:di = Buffer to load file
# bx = NextClusterNumber
pusha
movw $1, %si # NumberOfClusters = 1
pushw %cx # Push Start Cluster onto stack
movw $0xfff, %dx # CachedFatSectorNumber = 0xfff
FatChainLoop:
movw %cx, %ax # ax = ClusterNumber
andw $0xff8, %ax # ax = ax & 0xff8
cmpw $0xff8, %ax # See if this is the last cluster
je FoundLastCluster # Jump if last cluster found
movw %cx, %ax # ax = ClusterNumber
shlw %ax # ax = ClusterNumber * 2
addw %cx, %ax # ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3
shrw %ax # FatOffset = ClusterNumber*3 / 2
pushw %si # Save si
movw %ax, %si # si = FatOffset
shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
andw $BLOCK_MASK,%si # si = FatOffset & BLOCK_MASK
cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber
je SkipFatRead
movw $2, %bx
pushw %es
pushw %ds
popw %es
call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
popw %es
movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber
SkipFatRead:
movw (%si), %bx # bx = NextClusterNumber
movw %cx, %ax # ax = ClusterNumber
andw $1, %ax # See if this is an odd cluster number
je EvenFatEntry
shrw $4, %bx # NextClusterNumber = NextClusterNumber >> 4
EvenFatEntry:
andw $0xfff, %bx # Strip upper 4 bits of NextClusterNumber
popw %si # Restore si
decw %bx # bx = NextClusterNumber - 1
cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber
jne ReadClusters
incw %bx # bx = NextClusterNumber
incw %si # NumberOfClusters++
movw %bx, %cx # ClusterNumber = NextClusterNumber
jmp FatChainLoop
ReadClusters:
incw %bx
popw %ax # ax = StartCluster
pushw %bx # StartCluster = NextClusterNumber
movw %bx, %cx # ClusterNumber = NextClusterNumber
subw $2, %ax # ax = StartCluster - 2
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
pushw %ax # save start sector
movw %si, %ax # ax = NumberOfClusters
mulw %bx # ax = NumberOfClusters * SectorsPerCluster
movw %ax, %bx # bx = Number of Sectors
popw %ax # ax = Start Sector
call ReadBlocks
movw $1, %si # NumberOfClusters = 1
jmp FatChainLoop
FoundLastCluster:
popw %cx
popa
ret
# ****************************************************************************
# ReadBlocks - Reads a set of blocks from a block device
#
# AX = Start LBA
# BX = Number of Blocks to Read
# ES:DI = Buffer to store sectors read from disk
# ****************************************************************************
# cx = Blocks
# bx = NumberOfBlocks
# si = StartLBA
ReadBlocks:
pusha
addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
movl %eax, %esi # esi = Start LBA
movw %bx, %cx # cx = Number of blocks to read
ReadCylinderLoop:
movw $0x7bfc, %bp # bp = 0x7bfc
movl %esi, %eax # eax = Start LBA
xorl %edx, %edx # edx = 0
movzwl (%bp), %ebx # bx = MaxSector
divl %ebx # ax = StartLBA / MaxSector
incw %dx # dx = (StartLBA % MaxSector) + 1
movw (%bp), %bx # bx = MaxSector
subw %dx, %bx # bx = MaxSector - Sector
incw %bx # bx = MaxSector - Sector + 1
cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
movw %cx, %bx # bx = Blocks
LimitTransfer:
pushw %ax # save ax
movw %es, %ax # ax = es
shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
andw $0x7f, %ax # ax = Number of blocks into current seg
addw %bx, %ax # ax = End Block number of transfer
cmpw $0x80, %ax # See if it crosses a 64K boundry
jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
subw $0x80, %ax # ax = Number of blocks past 64K boundry
subw %ax, %bx # Decrease transfer size by block overage
NotCrossing64KBoundry:
popw %ax # restore ax
pushw %cx
movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
xorw %dx, %dx # dx = 0
divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
# dx = ax % (MaxHead + 1) = Head
pushw %bx # Save number of blocks to transfer
movb %dl, %dh # dh = Head
movw $0x7c00, %bp # bp = 0x7c00
movb PhysicalDrive(%bp), %dl # dl = Drive Number
movb %al, %ch # ch = Cylinder
movb %bl, %al # al = Blocks
movb $2, %ah # ah = Function 2
movw %di, %bx # es:bx = Buffer address
int $0x13
jc DiskError
popw %bx
popw %cx
movzwl %bx, %ebx
addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
movw %es, %ax
shlw $(BLOCK_SHIFT-4), %bx
addw %bx, %ax
movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmpw $0, %cx
jne ReadCylinderLoop
popa
ret
DiskError:
pushw %cs
popw %ds
leaw ErrorString, %si
movw $7, %cx
jmp PrintStringAndHalt
PrintStringAndHalt:
movw $0xb800, %ax
movw %ax, %es
movw $160, %di
rep
movsw
Halt:
jmp Halt
ErrorString:
.byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c
.org 0x01fa
LBAOffsetForBootSector:
.long 0x0
.org 0x01fe
.word 0xaa55
#******************************************************************************
#******************************************************************************
#******************************************************************************
.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
.equ KBD_STATUS_PORT, 0x064 # 8042 status port
.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
.org 0x200
jmp start
Em64String:
.byte 'E', 0x0c, 'm', 0x0c, '6', 0x0c, '4', 0x0c, 'T', 0x0c, ' ', 0x0c, 'U', 0x0c, 'n', 0x0c, 's', 0x0c, 'u', 0x0c, 'p', 0x0c, 'p', 0x0c, 'o', 0x0c, 'r', 0x0c, 't', 0x0c, 'e', 0x0c, 'd', 0x0c, '!', 0x0c
start:
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $MyStack, %sp
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[160],'a'
# mov ax,cs
# mov es,ax
movl $0, %ebx
leal MemoryMap, %edi
MemMapLoop:
movl $0xe820, %eax
movl $20, %ecx
movl $0x534d4150, %edx # SMAP
int $0x15
jc MemMapDone
addl $20, %edi
cmpl $0, %ebx
je MemMapDone
jmp MemMapLoop
MemMapDone:
leal MemoryMap, %eax
subl %eax, %edi # Get the address of the memory map
movl %edi, MemoryMapSize # Save the size of the memory map
xorl %ebx, %ebx
movw %cs, %bx # BX=segment
shll $4, %ebx # BX="linear" address of segment base
leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
movl %eax, (gdtr + 2) # Put address of gdt into the gdtr
leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
movl %eax, (idtr + 2) # Put address of idt into the idtr
leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
addl $0x1000, %ebx # Source of EFI32
movl %ebx, JUMP+2
addl $0x1000, %ebx
movl %ebx, %esi # Source of EFILDR32
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[162],'b'
# mov ax,cs
# mov es,ax
#
# Enable A20 Gate
#
movw $0x2401, %ax # Enable A20 Gate
int $0x15
jnc A20GateEnabled # Jump if it suceeded
#
# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
#
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
jnz Timeout8042 # Jump if the 8042 timed out
outw %ax, $DELAY_PORT # Delay 1 uS
mov $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
out %al, $KBD_STATUS_PORT # Send command to the 8042
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
jnz Timeout8042 # Jump if the 8042 timed out
mov $ENABLE_A20_CMD, %al # gate address bit 20 on
out %al, $KBD_CONTROL_PORT # Send command to thre 8042
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
movw $25, %cx # Delay 25 uS for the command to complete on the 8042
Delay25uS:
outw %ax, $DELAY_PORT # Delay 1 uS
loop Delay25uS
Timeout8042:
A20GateEnabled:
movw $0x0008, %bx # Flat data descriptor
#
# DISABLE INTERRUPTS - Entering Protected Mode
#
cli
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[164],'c'
# mov ax,cs
# mov es,ax
.byte 0x66
lgdt gdtr
.byte 0x66
lidt idtr
movl %cr0, %eax
orb $1, %al
movl %eax, %cr0
JUMP:
# jmp far 0010:00020000
.byte 0x66
.byte 0xea
.long 0x00020000
.word 0x0010
Empty8042InputBuffer:
movw $0, %cx
Empty8042Loop:
outw %ax, $DELAY_PORT # Delay 1us
in $KBD_STATUS_PORT, %al # Read the 8042 Status Port
andb $0x2, %al # Check the Input Buffer Full Flag
loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
ret
##############################################################################
# data
##############################################################################
.p2align 1
gdtr: .long GDT_END - GDT_BASE - 1 # GDT limit
.long 0 # (GDT base gets set above)
##############################################################################
# global descriptor table (GDT)
##############################################################################
.p2align 1
GDT_BASE:
# null descriptor
.equ NULL_SEL, .-GDT_BASE
.word 0 # limit 15:0
.word 0 # base 15:0
.byte 0 # base 23:16
.byte 0 # type
.byte 0 # limit 19:16, flags
.byte 0 # base 31:24
# linear data segment descriptor
.equ LINEAR_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x92 # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# linear code segment descriptor
.equ LINEAR_CODE_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x9A # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# system data segment descriptor
.equ SYS_DATA_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x92 # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# system code segment descriptor
.equ SYS_CODE_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x9A # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE3_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE4_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE5_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
GDT_END:
.p2align 1
idtr: .long IDT_END - IDT_BASE - 1 # IDT limit
.long 0 # (IDT base gets set above)
##############################################################################
# interrupt descriptor table (IDT)
#
# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
# mappings. This implementation only uses the system timer and all other
# IRQs will remain masked. The descriptors for vectors 33+ are provided
# for convenience.
##############################################################################
#idt_tag db "IDT",0
.p2align 1
IDT_BASE:
# divide by zero (INT 0)
.equ DIV_ZERO_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# debug exception (INT 1)
.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# NMI (INT 2)
.equ NMI_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# soft breakpoint (INT 3)
.equ BREAKPOINT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# overflow (INT 4)
.equ OVERFLOW_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# bounds check (INT 5)
.equ BOUNDS_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# invalid opcode (INT 6)
.equ INVALID_OPCODE_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# device not available (INT 7)
.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# double fault (INT 8)
.equ DOUBLE_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# Coprocessor segment overrun - reserved (INT 9)
.equ RSVD_INTR_SEL1, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# invalid TSS (INT 0x0a)
.equ INVALID_TSS_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# segment not present (INT 0x0b)
.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# stack fault (INT 0x0c)
.equ STACK_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# general protection (INT 0x0d)
.equ GP_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# page fault (INT 0x0e)
.equ PAGE_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# Intel reserved - do not use (INT 0x0f)
.equ RSVD_INTR_SEL2, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# floating point error (INT 0x10)
.equ FLT_POINT_ERR_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# alignment check (INT 0x11)
.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# machine check (INT 0x12)
.equ MACHINE_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# SIMD floating-point exception (INT 0x13)
.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
.fill 85 * 8, 1, 0 # db (85 * 8) dup(0)
# IRQ 0 (System timer) - (INT 0x68)
.equ IRQ0_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 1 (8042 Keyboard controller) - (INT 0x69)
.equ IRQ1_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 0x6a)
.equ IRQ2_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 3 (COM 2) - (INT 0x6b)
.equ IRQ3_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 4 (COM 1) - (INT 0x6c)
.equ IRQ4_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 5 (LPT 2) - (INT 0x6d)
.equ IRQ5_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 6 (Floppy controller) - (INT 0x6e)
.equ IRQ6_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 7 (LPT 1) - (INT 0x6f)
.equ IRQ7_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 8 (RTC Alarm) - (INT 0x70)
.equ IRQ8_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 9 - (INT 0x71)
.equ IRQ9_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 10 - (INT 0x72)
.equ IRQ10_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 11 - (INT 0x73)
.equ IRQ11_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 12 (PS/2 mouse) - (INT 0x74)
.equ IRQ12_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 13 (Floating point error) - (INT 0x75)
.equ IRQ13_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 14 (Secondary IDE) - (INT 0x76)
.equ IRQ14_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 15 (Primary IDE) - (INT 0x77)
.equ IRQ15_SEL, .-IDT_BASE
.word 0 # offset 15:0
.long SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
IDT_END:
.p2align 1
MemoryMapSize: .long 0
MemoryMap: .long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.org 0x0fe0
MyStack:
# below is the pieces of the IVT that is used to redirect INT 68h - 6fh
# back to INT 08h - 0fh when in real mode... It is 'org'ed to a
# known low address (20f00) so it can be set up by PlMapIrqToVect in
# 8259.c
int $8
iret
int $9
iret
int $10
iret
int $11
iret
int $12
iret
int $13
iret
int $14
iret
int $15
iret
.org 0x0ffe
BlockSignature:
.word 0xaa55

View File

@@ -1,916 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* start.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
.stack
.486p
.code
FAT_DIRECTORY_ENTRY_SIZE EQU 020h
FAT_DIRECTORY_ENTRY_SHIFT EQU 5
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
org 0h
Ia32Jump:
jmp BootSectorEntryPoint ; JMP inst - 3 bytes
nop
OemId db "INTEL " ; OemId - 8 bytes
SectorSize dw 0 ; Sector Size - 16 bits
SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
ReservedSectors dw 0 ; Reserved Sectors - 16 bits
NoFats db 0 ; Number of FATs - 8 bits
RootEntries dw 0 ; Root Entries - 16 bits
Sectors dw 0 ; Number of Sectors - 16 bits
Media db 0 ; Media - 8 bits - ignored
SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
Heads dw 0 ; Heads - 16 bits - ignored
HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
LargeSectors dd 0 ; Large Sectors - 32 bits
PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
CurrentHead db 0 ; Current Head - 8 bits
Signature db 0 ; Signature - 8 bits - ignored
VolId db " " ; Volume Serial Number- 4 bytes
FatLabel db " " ; Label - 11 bytes
SystemId db "FAT12 " ; SystemId - 8 bytes
BootSectorEntryPoint:
ASSUME ds:@code
ASSUME ss:@code
; ds = 1000, es = 2000 + x (size of first cluster >> 4)
; cx = Start Cluster of EfiLdr
; dx = Start Cluster of Efivar.bin
; Re use the BPB data stored in Boot Sector
mov bp,07c00h
push cx
; Read Efivar.bin
; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
mov ax,01900h
mov es,ax
test dx,dx
jnz CheckVarStoreSize
mov al,1
NoVarStore:
push es
; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
mov byte ptr es:[4],al
jmp SaveVolumeId
CheckVarStoreSize:
mov di,dx
cmp dword ptr ds:[di+2], 04000h
mov al,2
jne NoVarStore
LoadVarStore:
mov al,0
mov byte ptr es:[4],al
mov cx,word ptr[di]
; ES:DI = 1500:0
xor di,di
push es
mov ax,01500h
mov es,ax
call ReadFile
SaveVolumeId:
pop es
mov ax,word ptr [bp+VolId]
mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
mov ax,word ptr [bp+VolId+2]
mov word ptr es:[2],ax
; Read Efildr
pop cx
; cx = Start Cluster of Efildr -> BS.com has filled already
; ES:DI = 2000:0, first cluster will be read again
xor di,di ; di = 0
mov ax,02000h
mov es,ax
call ReadFile
mov ax,cs
mov word ptr cs:[JumpSegment],ax
JumpFarInstruction:
db 0eah
JumpOffset:
dw 0200h
JumpSegment:
dw 2000h
; ****************************************************************************
; ReadFile
;
; Arguments:
; CX = Start Cluster of File
; ES:DI = Buffer to store file content read from disk
;
; Return:
; (ES << 4 + DI) = end of file content Buffer
;
; ****************************************************************************
ReadFile:
; si = NumberOfClusters
; cx = ClusterNumber
; dx = CachedFatSectorNumber
; ds:0000 = CacheFatSectorBuffer
; es:di = Buffer to load file
; bx = NextClusterNumber
pusha
mov si,1 ; NumberOfClusters = 1
push cx ; Push Start Cluster onto stack
mov dx,0fffh ; CachedFatSectorNumber = 0xfff
FatChainLoop:
mov ax,cx ; ax = ClusterNumber
and ax,0ff8h ; ax = ax & 0xff8
cmp ax,0ff8h ; See if this is the last cluster
je FoundLastCluster ; Jump if last cluster found
mov ax,cx ; ax = ClusterNumber
shl ax,1 ; ax = ClusterNumber * 2
add ax,cx ; ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3
shr ax,1 ; FatOffset = ClusterNumber*3 / 2
push si ; Save si
mov si,ax ; si = FatOffset
shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
je SkipFatRead
mov bx,2
push es
push ds
pop es
call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
pop es
mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
SkipFatRead:
mov bx,word ptr [si] ; bx = NextClusterNumber
mov ax,cx ; ax = ClusterNumber
and ax,1 ; See if this is an odd cluster number
je EvenFatEntry
shr bx,4 ; NextClusterNumber = NextClusterNumber >> 4
EvenFatEntry:
and bx,0fffh ; Strip upper 4 bits of NextClusterNumber
pop si ; Restore si
dec bx ; bx = NextClusterNumber - 1
cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
jne ReadClusters
inc bx ; bx = NextClusterNumber
inc si ; NumberOfClusters++
mov cx,bx ; ClusterNumber = NextClusterNumber
jmp FatChainLoop
ReadClusters:
inc bx
pop ax ; ax = StartCluster
push bx ; StartCluster = NextClusterNumber
mov cx,bx ; ClusterNumber = NextClusterNumber
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
push ax ; save start sector
mov ax,si ; ax = NumberOfClusters
mul bx ; ax = NumberOfClusters * SectorsPerCluster
mov bx,ax ; bx = Number of Sectors
pop ax ; ax = Start Sector
call ReadBlocks
mov si,1 ; NumberOfClusters = 1
jmp FatChainLoop
FoundLastCluster:
pop cx
popa
ret
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; AX = Start LBA
; BX = Number of Blocks to Read
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; cx = Blocks
; bx = NumberOfBlocks
; si = StartLBA
ReadBlocks:
pusha
add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
mov esi,eax ; esi = Start LBA
mov cx,bx ; cx = Number of blocks to read
ReadCylinderLoop:
mov bp,07bfch ; bp = 0x7bfc
mov eax,esi ; eax = Start LBA
xor edx,edx ; edx = 0
movzx ebx,word ptr [bp] ; bx = MaxSector
div ebx ; ax = StartLBA / MaxSector
inc dx ; dx = (StartLBA % MaxSector) + 1
mov bx,word ptr [bp] ; bx = MaxSector
sub bx,dx ; bx = MaxSector - Sector
inc bx ; bx = MaxSector - Sector + 1
cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
mov bx,cx ; bx = Blocks
LimitTransfer:
push ax ; save ax
mov ax,es ; ax = es
shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
and ax,07fh ; ax = Number of blocks into current seg
add ax,bx ; ax = End Block number of transfer
cmp ax,080h ; See if it crosses a 64K boundry
jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
sub ax,080h ; ax = Number of blocks past 64K boundry
sub bx,ax ; Decrease transfer size by block overage
NotCrossing64KBoundry:
pop ax ; restore ax
push cx
mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
xor dx,dx ; dx = 0
div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
; dx = ax % (MaxHead + 1) = Head
push bx ; Save number of blocks to transfer
mov dh,dl ; dh = Head
mov bp,07c00h ; bp = 0x7c00
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
mov ch,al ; ch = Cylinder
mov al,bl ; al = Blocks
mov ah,2 ; ah = Function 2
mov bx,di ; es:bx = Buffer address
int 013h
jc DiskError
pop bx
pop cx
movzx ebx,bx
add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
sub cx,bx ; Blocks = Blocks - NumberOfBlocks
mov ax,es
shl bx,(BLOCK_SHIFT-4)
add ax,bx
mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmp cx,0
jne ReadCylinderLoop
popa
ret
DiskError:
push cs
pop ds
lea si, [ErrorString]
mov cx, 7
jmp PrintStringAndHalt
PrintStringAndHalt:
mov ax,0b800h
mov es,ax
mov di,160
rep movsw
Halt:
jmp Halt
ErrorString:
db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
org 01fah
LBAOffsetForBootSector:
dd 0h
org 01feh
dw 0aa55h
;******************************************************************************
;******************************************************************************
;******************************************************************************
DELAY_PORT equ 0edh ; Port to use for 1uS delay
KBD_CONTROL_PORT equ 060h ; 8042 control port
KBD_STATUS_PORT equ 064h ; 8042 status port
WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
org 200h
jmp start
Em64String:
db 'E', 0ch, 'm', 0ch, '6', 0ch, '4', 0ch, 'T', 0ch, ' ', 0ch, 'U', 0ch, 'n', 0ch, 's', 0ch, 'u', 0ch, 'p', 0ch, 'p', 0ch, 'o', 0ch, 'r', 0ch, 't', 0ch, 'e', 0ch, 'd', 0ch, '!', 0ch
start:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,MyStack
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[160],'a'
; mov ax,cs
; mov es,ax
mov ebx,0
lea edi,MemoryMap
MemMapLoop:
mov eax,0e820h
mov ecx,20
mov edx,'SMAP'
int 15h
jc MemMapDone
add edi,20
cmp ebx,0
je MemMapDone
jmp MemMapLoop
MemMapDone:
lea eax,MemoryMap
sub edi,eax ; Get the address of the memory map
mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
xor ebx,ebx
mov bx,cs ; BX=segment
shl ebx,4 ; BX="linear" address of segment base
lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
add ebx,01000h ; Source of EFI32
mov dword ptr [JUMP+2],ebx
add ebx,01000h
mov esi,ebx ; Source of EFILDR32
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[162],'b'
; mov ax,cs
; mov es,ax
;
; Enable A20 Gate
;
mov ax,2401h ; Enable A20 Gate
int 15h
jnc A20GateEnabled ; Jump if it suceeded
;
; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
;
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
out DELAY_PORT,ax ; Delay 1 uS
mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
out KBD_STATUS_PORT,al ; Send command to the 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
mov al,ENABLE_A20_CMD ; gate address bit 20 on
out KBD_CONTROL_PORT,al ; Send command to thre 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
mov cx,25 ; Delay 25 uS for the command to complete on the 8042
Delay25uS:
out DELAY_PORT,ax ; Delay 1 uS
loop Delay25uS
Timeout8042:
A20GateEnabled:
mov bx,0008h ; Flat data descriptor
;
; DISABLE INTERRUPTS - Entering Protected Mode
;
cli
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[164],'c'
; mov ax,cs
; mov es,ax
db 66h
lgdt fword ptr [gdtr]
db 66h
lidt fword ptr [idtr]
mov eax,cr0
or al,1
mov cr0,eax
JUMP:
; jmp far 0010:00020000
db 066h
db 0eah
dd 000020000h
dw 00010h
Empty8042InputBuffer:
mov cx,0
Empty8042Loop:
out DELAY_PORT,ax ; Delay 1us
in al,KBD_STATUS_PORT ; Read the 8042 Status Port
and al,02h ; Check the Input Buffer Full Flag
loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
dd 0 ; (GDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; global descriptor table (GDT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
public GDT_BASE
GDT_BASE:
; null descriptor
NULL_SEL equ $-GDT_BASE
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; linear data segment descriptor
LINEAR_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; linear code segment descriptor
LINEAR_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system data segment descriptor
SYS_DATA_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system code segment descriptor
SYS_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE3_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE4_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE5_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
GDT_END:
align 02h
idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
dd 0 ; (IDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; interrupt descriptor table (IDT)
;
; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
; mappings. This implementation only uses the system timer and all other
; IRQs will remain masked. The descriptors for vectors 33+ are provided
; for convenience.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;idt_tag db "IDT",0
align 02h
public IDT_BASE
IDT_BASE:
; divide by zero (INT 0)
DIV_ZERO_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; debug exception (INT 1)
DEBUG_EXCEPT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; NMI (INT 2)
NMI_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; soft breakpoint (INT 3)
BREAKPOINT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; overflow (INT 4)
OVERFLOW_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; bounds check (INT 5)
BOUNDS_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid opcode (INT 6)
INVALID_OPCODE_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; device not available (INT 7)
DEV_NOT_AVAIL_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; double fault (INT 8)
DOUBLE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Coprocessor segment overrun - reserved (INT 9)
RSVD_INTR_SEL1 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid TSS (INT 0ah)
INVALID_TSS_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; segment not present (INT 0bh)
SEG_NOT_PRESENT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; stack fault (INT 0ch)
STACK_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; general protection (INT 0dh)
GP_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; page fault (INT 0eh)
PAGE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Intel reserved - do not use (INT 0fh)
RSVD_INTR_SEL2 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; floating point error (INT 10h)
FLT_POINT_ERR_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; alignment check (INT 11h)
ALIGNMENT_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; machine check (INT 12h)
MACHINE_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; SIMD floating-point exception (INT 13h)
SIMD_EXCEPTION_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
db (85 * 8) dup(0)
; IRQ 0 (System timer) - (INT 68h)
IRQ0_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 1 (8042 Keyboard controller) - (INT 69h)
IRQ1_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
IRQ2_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 3 (COM 2) - (INT 6bh)
IRQ3_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 4 (COM 1) - (INT 6ch)
IRQ4_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 5 (LPT 2) - (INT 6dh)
IRQ5_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 6 (Floppy controller) - (INT 6eh)
IRQ6_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 7 (LPT 1) - (INT 6fh)
IRQ7_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 8 (RTC Alarm) - (INT 70h)
IRQ8_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 9 - (INT 71h)
IRQ9_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 10 - (INT 72h)
IRQ10_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 11 - (INT 73h)
IRQ11_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 12 (PS/2 mouse) - (INT 74h)
IRQ12_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 13 (Floating point error) - (INT 75h)
IRQ13_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 14 (Secondary IDE) - (INT 76h)
IRQ14_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 15 (Primary IDE) - (INT 77h)
IRQ15_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
IDT_END:
align 02h
MemoryMapSize dd 0
MemoryMap dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
org 0fe0h
MyStack:
; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
; known low address (20f00) so it can be set up by PlMapIrqToVect in
; 8259.c
int 8
iret
int 9
iret
int 10
iret
int 11
iret
int 12
iret
int 13
iret
int 14
iret
int 15
iret
org 0ffeh
BlockSignature:
dw 0aa55h
end

View File

@@ -1,910 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* start16.asm
#*
#* Abstract:
#*
#------------------------------------------------------------------------------
#.MODEL small
.stack:
.486p:
.code16
.equ FAT_DIRECTORY_ENTRY_SIZE, 0x0020
.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
.org 0x00
.global _start
_start:
Ia32Jump:
jmp BootSectorEntryPoint # JMP inst - 3 bytes
nop
OemId: .ascii "INTEL " # OemId - 8 bytes
SectorSize: .word 0 # Sector Size - 16 bits
SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
ReservedSectors: .word 0 # Reserved Sectors - 16 bits
NoFats: .byte 0 # Number of FATs - 8 bits
RootEntries: .word 0 # Root Entries - 16 bits
Sectors: .word 0 # Number of Sectors - 16 bits
Media: .byte 0 # Media - 8 bits - ignored
SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
Heads: .word 0 # Heads - 16 bits - ignored
HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
LargeSectors: .long 0 # Large Sectors - 32 bits
PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
CurrentHead: .byte 0 # Current Head - 8 bits
Signature: .byte 0 # Signature - 8 bits - ignored
VolId: .ascii " " # Volume Serial Number- 4 bytes
FatLabel: .ascii " " # Label - 11 bytes
SystemId: .ascii "FAT16 " # SystemId - 8 bytes
BootSectorEntryPoint:
#ASSUME ds:@code
#ASSUME ss:@code
# ds = 1000, es = 2000 + x (size of first cluster >> 4)
# cx = Start Cluster of EfiLdr
# dx = Start Cluster of Efivar.bin
# Re use the BPB data stored in Boot Sector
movw $0x7c00, %bp
pushw %cx
# Read Efivar.bin
# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
movw $0x1900, %ax
movw %ax, %es
testw %dx, %dx
jnz CheckVarStoreSize
movb $1, %al
NoVarStore:
pushw %es
# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
movb %al, %es:4
jmp SaveVolumeId
CheckVarStoreSize:
movw %dx, %di
cmpl $0x4000, %ds:2(%di)
movb $2, %al
jne NoVarStore
LoadVarStore:
movb $0, %al
movb %al, %es:4
movw (%di), %cx
# ES:DI = 1500:0
xorw %di, %di
pushw %es
movw $0x1500, %ax
movw %ax, %es
call ReadFile
SaveVolumeId:
popw %es
movw VolId(%bp), %ax
movw %ax, %es:0 # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
movw VolId+2(%bp), %ax
movw %ax, %es:2
# Read Efildr
popw %cx
# cx = Start Cluster of Efildr -> BS.com has filled already
# ES:DI = 2000:0, first cluster will be read again
xorw %di, %di # di = 0
movw $0x2000, %ax
movw %ax, %es
call ReadFile
movw %cs, %ax
movw %ax, %cs:JumpSegment
JumpFarInstruction:
.byte 0xea
JumpOffset:
.word 0x200
JumpSegment:
.word 0x2000
# ****************************************************************************
# ReadFile
#
# Arguments:
# CX = Start Cluster of File
# ES:DI = Buffer to store file content read from disk
#
# Return:
# (ES << 4 + DI) = end of file content Buffer
#
# ****************************************************************************
ReadFile:
# si = NumberOfClusters
# cx = ClusterNumber
# dx = CachedFatSectorNumber
# ds:0000 = CacheFatSectorBuffer
# es:di = Buffer to load file
# bx = NextClusterNumber
pusha
movw $1, %si # NumberOfClusters = 1
pushw %cx # Push Start Cluster onto stack
movw $0xfff, %dx # CachedFatSectorNumber = 0xfff
FatChainLoop:
movw %cx, %ax # ax = ClusterNumber
andw $0xfff8, %ax # ax = ax & 0xfff8
cmpw $0xfff8, %ax # See if this is the last cluster
je FoundLastCluster # Jump if last cluster found
movw %cx, %ax # ax = ClusterNumber
shlw %ax # FatOffset = ClusterNumber * 2
pushw %si # Save si
movw %ax, %si # si = FatOffset
shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK
cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber
je SkipFatRead
movw $2, %bx
pushw %es
pushw %ds
popw %es
call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
popw %es
movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber
SkipFatRead:
movw (%si), %bx # bx = NextClusterNumber
movw %cx, %ax # ax = ClusterNumber
popw %si # Restore si
decw %bx # bx = NextClusterNumber - 1
cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber
jne ReadClusters
incw %bx # bx = NextClusterNumber
incw %si # NumberOfClusters++
movw %bx, %cx # ClusterNumber = NextClusterNumber
jmp FatChainLoop
ReadClusters:
incw %bx
popw %ax # ax = StartCluster
pushw %bx # StartCluster = NextClusterNumber
movw %bx, %cx # ClusterNumber = NextClusterNumber
subw $2, %ax # ax = StartCluster - 2
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
pushw %ax # save start sector
movw %si, %ax # ax = NumberOfClusters
mulw %bx # ax = NumberOfClusters * SectorsPerCluster
movw %ax, %bx # bx = Number of Sectors
popw %ax # ax = Start Sector
call ReadBlocks
movw $1, %si # NumberOfClusters = 1
jmp FatChainLoop
FoundLastCluster:
popw %cx
popa
ret
# ****************************************************************************
# ReadBlocks - Reads a set of blocks from a block device
#
# AX = Start LBA
# BX = Number of Blocks to Read
# ES:DI = Buffer to store sectors read from disk
# ****************************************************************************
# cx = Blocks
# bx = NumberOfBlocks
# si = StartLBA
ReadBlocks:
pusha
addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
movl %eax, %esi # esi = Start LBA
movw %bx, %cx # cx = Number of blocks to read
ReadCylinderLoop:
movw $0x7bfc, %bp # bp = 0x7bfc
movl %esi, %eax # eax = Start LBA
xorl %edx, %edx # edx = 0
movzwl (%bp), %ebx # bx = MaxSector
divl %ebx # ax = StartLBA / MaxSector
incw %dx # dx = (StartLBA % MaxSector) + 1
movw (%bp), %bx # bx = MaxSector
subw %dx, %bx # bx = MaxSector - Sector
incw %bx # bx = MaxSector - Sector + 1
cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
movw %cx, %bx # bx = Blocks
LimitTransfer:
pushw %ax # save ax
movw %es, %ax # ax = es
shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
andw $0x7f, %ax # ax = Number of blocks into current seg
addw %bx, %ax # ax = End Block number of transfer
cmpw $0x80, %ax # See if it crosses a 64K boundry
jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
subw $0x80, %ax # ax = Number of blocks past 64K boundry
subw %ax, %bx # Decrease transfer size by block overage
NotCrossing64KBoundry:
popw %ax # restore ax
pushw %cx
movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
xorw %dx, %dx # dx = 0
divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
# dx = ax % (MaxHead + 1) = Head
pushw %bx # Save number of blocks to transfer
movb %dl, %dh # dh = Head
movw $0x7c00, %bp # bp = 0x7c00
movb PhysicalDrive(%bp), %dl # dl = Drive Number
movb %al, %ch # ch = Cylinder
movb %bl, %al # al = Blocks
movb $2, %ah # ah = Function 2
movw %di, %bx # es:bx = Buffer address
int $0x13
jc DiskError
popw %bx
popw %cx
movzwl %bx, %ebx
addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
movw %es, %ax
shlw $(BLOCK_SHIFT-4), %bx
addw %bx, %ax
movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmpw $0, %cx
jne ReadCylinderLoop
popa
ret
DiskError:
pushw %cs
popw %ds
leaw ErrorString, %si
movw $7, %cx
jmp PrintStringAndHalt
PrintStringAndHalt:
movw $0xb800, %ax
movw %ax, %es
movw $160, %di
rep
movsw
Halt:
jmp Halt
ErrorString:
.byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
# .org 0x01fa # Just for passing build.
LBAOffsetForBootSector:
.long 0x0
# .org 0x01fe # Just for passing build.
.word 0xaa55
#******************************************************************************
#******************************************************************************
#******************************************************************************
.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
.equ KBD_STATUS_PORT, 0x064 # 8042 status port
.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
# .org 0x0200 # Just for passing build.
jmp start
Em64String:
.byte 'E', 0x0c, 'm', 0x0c, '6', 0x0c, '4', 0x0c, 'T', 0x0c, ' ', 0x0c, 'U', 0x0c, 'n', 0x0c, 's', 0x0c, 'u', 0x0c, 'p', 0x0c, 'p', 0x0c, 'o', 0x0c, 'r', 0x0c, 't', 0x0c, 'e', 0x0c, 'd', 0x0c, '!', 0x0c
start:
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $MyStack, %sp
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[160],'a'
# mov ax,cs
# mov es,ax
movl $0, %ebx
leal MemoryMap, %edi
MemMapLoop:
movl $0xe820, %eax
movl $20, %ecx
movl $0x534d4150, %edx # 0x534d4150 stands for 'SMAP'
int $0x15
jc MemMapDone
addl $20, %edi
cmpl $0, %ebx
je MemMapDone
jmp MemMapLoop
MemMapDone:
leal MemoryMap, %eax
subl %eax, %edi # Get the address of the memory map
movl %edi, MemoryMapSize # Save the size of the memory map
xorl %ebx, %ebx
movw %cs, %bx # BX=segment
shll $4, %ebx # BX="linear" address of segment base
leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
movl %eax, gdtr + 2 # Put address of gdt into the gdtr
leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
movl %eax, idtr + 2 # Put address of idt into the idtr
leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
addl $0x1000, %ebx # Source of EFI32
movl %ebx, JUMP+2
addl $0x1000, %ebx
movl %ebx, %esi # Source of EFILDR32
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[162],'b'
# mov ax,cs
# mov es,ax
#
# Enable A20 Gate
#
movw $0x2401, %ax # Enable A20 Gate
int $0x15
jnc A20GateEnabled # Jump if it suceeded
#
# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
#
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
jnz Timeout8042 # Jump if the 8042 timed out
outw %ax, $DELAY_PORT # Delay 1 uS
movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
outb %al, $KBD_STATUS_PORT # Send command to the 8042
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
jnz Timeout8042 # Jump if the 8042 timed out
movb $ENABLE_A20_CMD, %al # gate address bit 20 on
outb %al, $KBD_CONTROL_PORT # Send command to thre 8042
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
movw $25, %cx # Delay 25 uS for the command to complete on the 8042
Delay25uS:
outw %ax, $DELAY_PORT # Delay 1 uS
loop Delay25uS
Timeout8042:
A20GateEnabled:
movw $0x0008, %bx # Flat data descriptor
#
# DISABLE INTERRUPTS - Entering Protected Mode
#
cli
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[164],'c'
# mov ax,cs
# mov es,ax
.byte 0x66
lgdt gdtr
.byte 0x66
lidt idtr
movl %cr0, %eax
orb $1, %al
movl %eax, %cr0
JUMP:
# jmp far 0010:00020000
.byte 0x66
.byte 0xea
.long 0x00020000
.word 0x0010
Empty8042InputBuffer:
movw $0, %cx
Empty8042Loop:
outw %ax, $DELAY_PORT # Delay 1us
inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port
andb $0x2, %al # Check the Input Buffer Full Flag
loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
ret
##############################################################################
# data
##############################################################################
.p2align 1
gdtr: .word GDT_END - GDT_BASE - 1 # GDT limit
.long 0 # (GDT base gets set above)
##############################################################################
# global descriptor table (GDT)
##############################################################################
.p2align 1
GDT_BASE:
# null descriptor
.equ NULL_SEL, .-GDT_BASE
.word 0 # limit 15:0
.word 0 # base 15:0
.byte 0 # base 23:16
.byte 0 # type
.byte 0 # limit 19:16, flags
.byte 0 # base 31:24
# linear data segment descriptor
.equ LINEAR_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x92 # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# linear code segment descriptor
.equ LINEAR_CODE_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x9A # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# system data segment descriptor
.equ SYS_DATA_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x92 # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# system code segment descriptor
.equ SYS_CODE_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x9A # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE3_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE4_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE5_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
GDT_END:
.p2align 1
idtr: .word IDT_END - IDT_BASE - 1 # IDT limit
.long 0 # (IDT base gets set above)
##############################################################################
# interrupt descriptor table (IDT)
#
# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
# mappings. This implementation only uses the system timer and all other
# IRQs will remain masked. The descriptors for vectors 33+ are provided
# for convenience.
##############################################################################
#idt_tag db "IDT",0
.p2align 1
IDT_BASE:
# divide by zero (INT 0)
.equ DIV_ZERO_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# debug exception (INT 1)
.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# NMI (INT 2)
.equ NMI_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# soft breakpoint (INT 3)
.equ BREAKPOINT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# overflow (INT 4)
.equ OVERFLOW_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# bounds check (INT 5)
.equ BOUNDS_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# invalid opcode (INT 6)
.equ INVALID_OPCODE_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# device not available (INT 7)
.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# double fault (INT 8)
.equ DOUBLE_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# Coprocessor segment overrun - reserved (INT 9)
.equ RSVD_INTR_SEL1, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# invalid TSS (INT 0ah)
.equ INVALID_TSS_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# segment not present (INT 0bh)
.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# stack fault (INT 0ch)
.equ STACK_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# general protection (INT 0dh)
.equ GP_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# page fault (INT 0eh)
.equ PAGE_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# Intel reserved - do not use (INT 0fh)
.equ RSVD_INTR_SEL2, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# floating point error (INT 10h)
.equ FLT_POINT_ERR_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# alignment check (INT 11h)
.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# machine check (INT 12h)
.equ MACHINE_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# SIMD floating-point exception (INT 13h)
.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
.fill 85 * 8, 1, 0
# IRQ 0 (System timer) - (INT 68h)
.equ IRQ0_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 1 (8042 Keyboard controller) - (INT 69h)
.equ IRQ1_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
.equ IRQ2_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 3 (COM 2) - (INT 6bh)
.equ IRQ3_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 4 (COM 1) - (INT 6ch)
.equ IRQ4_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 5 (LPT 2) - (INT 6dh)
.equ IRQ5_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 6 (Floppy controller) - (INT 6eh)
.equ IRQ6_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 7 (LPT 1) - (INT 6fh)
.equ IRQ7_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 8 (RTC Alarm) - (INT 70h)
.equ IRQ8_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 9 - (INT 71h)
.equ IRQ9_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 10 - (INT 72h)
.equ IRQ10_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 11 - (INT 73h)
.equ IRQ11_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 12 (PS/2 mouse) - (INT 74h)
.equ IRQ12_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 13 (Floating point error) - (INT 75h)
.equ IRQ13_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 14 (Secondary IDE) - (INT 76h)
.equ IRQ14_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 15 (Primary IDE) - (INT 77h)
.equ IRQ15_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
.word 0 # offset 31:16
IDT_END:
.p2align 1
MemoryMapSize: .long 0
MemoryMap: .long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.org 0x0fe0
MyStack:
# below is the pieces of the IVT that is used to redirect INT 68h - 6fh
# back to INT 08h - 0fh when in real mode... It is 'org'ed to a
# known low address (20f00) so it can be set up by PlMapIrqToVect in
# 8259.c
int $8
iret
int $9
iret
int $10
iret
int $11
iret
int $12
iret
int $13
iret
int $14
iret
int $15
iret
.org 0x0ffe
BlockSignature:
.word 0xaa55

View File

@@ -1,909 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* start16.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
.stack
.486p
.code
FAT_DIRECTORY_ENTRY_SIZE EQU 020h
FAT_DIRECTORY_ENTRY_SHIFT EQU 5
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
org 0h
Ia32Jump:
jmp BootSectorEntryPoint ; JMP inst - 3 bytes
nop
OemId db "INTEL " ; OemId - 8 bytes
SectorSize dw 0 ; Sector Size - 16 bits
SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
ReservedSectors dw 0 ; Reserved Sectors - 16 bits
NoFats db 0 ; Number of FATs - 8 bits
RootEntries dw 0 ; Root Entries - 16 bits
Sectors dw 0 ; Number of Sectors - 16 bits
Media db 0 ; Media - 8 bits - ignored
SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
Heads dw 0 ; Heads - 16 bits - ignored
HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
LargeSectors dd 0 ; Large Sectors - 32 bits
PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
CurrentHead db 0 ; Current Head - 8 bits
Signature db 0 ; Signature - 8 bits - ignored
VolId db " " ; Volume Serial Number- 4 bytes
FatLabel db " " ; Label - 11 bytes
SystemId db "FAT16 " ; SystemId - 8 bytes
BootSectorEntryPoint:
ASSUME ds:@code
ASSUME ss:@code
; ds = 1000, es = 2000 + x (size of first cluster >> 4)
; cx = Start Cluster of EfiLdr
; dx = Start Cluster of Efivar.bin
; Re use the BPB data stored in Boot Sector
mov bp,07c00h
push cx
; Read Efivar.bin
; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
mov ax,01900h
mov es,ax
test dx,dx
jnz CheckVarStoreSize
mov al,1
NoVarStore:
push es
; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
mov byte ptr es:[4],al
jmp SaveVolumeId
CheckVarStoreSize:
mov di,dx
cmp dword ptr ds:[di+2], 04000h
mov al,2
jne NoVarStore
LoadVarStore:
mov al,0
mov byte ptr es:[4],al
mov cx,word ptr[di]
; ES:DI = 1500:0
xor di,di
push es
mov ax,01500h
mov es,ax
call ReadFile
SaveVolumeId:
pop es
mov ax,word ptr [bp+VolId]
mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
mov ax,word ptr [bp+VolId+2]
mov word ptr es:[2],ax
; Read Efildr
pop cx
; cx = Start Cluster of Efildr -> BS.com has filled already
; ES:DI = 2000:0, first cluster will be read again
xor di,di ; di = 0
mov ax,02000h
mov es,ax
call ReadFile
mov ax,cs
mov word ptr cs:[JumpSegment],ax
JumpFarInstruction:
db 0eah
JumpOffset:
dw 0200h
JumpSegment:
dw 2000h
; ****************************************************************************
; ReadFile
;
; Arguments:
; CX = Start Cluster of File
; ES:DI = Buffer to store file content read from disk
;
; Return:
; (ES << 4 + DI) = end of file content Buffer
;
; ****************************************************************************
ReadFile:
; si = NumberOfClusters
; cx = ClusterNumber
; dx = CachedFatSectorNumber
; ds:0000 = CacheFatSectorBuffer
; es:di = Buffer to load file
; bx = NextClusterNumber
pusha
mov si,1 ; NumberOfClusters = 1
push cx ; Push Start Cluster onto stack
mov dx,0fffh ; CachedFatSectorNumber = 0xfff
FatChainLoop:
mov ax,cx ; ax = ClusterNumber
and ax,0fff8h ; ax = ax & 0xfff8
cmp ax,0fff8h ; See if this is the last cluster
je FoundLastCluster ; Jump if last cluster found
mov ax,cx ; ax = ClusterNumber
shl ax,1 ; FatOffset = ClusterNumber * 2
push si ; Save si
mov si,ax ; si = FatOffset
shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
je SkipFatRead
mov bx,2
push es
push ds
pop es
call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
pop es
mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
SkipFatRead:
mov bx,word ptr [si] ; bx = NextClusterNumber
mov ax,cx ; ax = ClusterNumber
pop si ; Restore si
dec bx ; bx = NextClusterNumber - 1
cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
jne ReadClusters
inc bx ; bx = NextClusterNumber
inc si ; NumberOfClusters++
mov cx,bx ; ClusterNumber = NextClusterNumber
jmp FatChainLoop
ReadClusters:
inc bx
pop ax ; ax = StartCluster
push bx ; StartCluster = NextClusterNumber
mov cx,bx ; ClusterNumber = NextClusterNumber
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
push ax ; save start sector
mov ax,si ; ax = NumberOfClusters
mul bx ; ax = NumberOfClusters * SectorsPerCluster
mov bx,ax ; bx = Number of Sectors
pop ax ; ax = Start Sector
call ReadBlocks
mov si,1 ; NumberOfClusters = 1
jmp FatChainLoop
FoundLastCluster:
pop cx
popa
ret
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; AX = Start LBA
; BX = Number of Blocks to Read
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; cx = Blocks
; bx = NumberOfBlocks
; si = StartLBA
ReadBlocks:
pusha
add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
mov esi,eax ; esi = Start LBA
mov cx,bx ; cx = Number of blocks to read
ReadCylinderLoop:
mov bp,07bfch ; bp = 0x7bfc
mov eax,esi ; eax = Start LBA
xor edx,edx ; edx = 0
movzx ebx,word ptr [bp] ; bx = MaxSector
div ebx ; ax = StartLBA / MaxSector
inc dx ; dx = (StartLBA % MaxSector) + 1
mov bx,word ptr [bp] ; bx = MaxSector
sub bx,dx ; bx = MaxSector - Sector
inc bx ; bx = MaxSector - Sector + 1
cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
mov bx,cx ; bx = Blocks
LimitTransfer:
push ax ; save ax
mov ax,es ; ax = es
shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
and ax,07fh ; ax = Number of blocks into current seg
add ax,bx ; ax = End Block number of transfer
cmp ax,080h ; See if it crosses a 64K boundry
jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
sub ax,080h ; ax = Number of blocks past 64K boundry
sub bx,ax ; Decrease transfer size by block overage
NotCrossing64KBoundry:
pop ax ; restore ax
push cx
mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
xor dx,dx ; dx = 0
div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
; dx = ax % (MaxHead + 1) = Head
push bx ; Save number of blocks to transfer
mov dh,dl ; dh = Head
mov bp,07c00h ; bp = 0x7c00
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
mov ch,al ; ch = Cylinder
mov al,bl ; al = Blocks
mov ah,2 ; ah = Function 2
mov bx,di ; es:bx = Buffer address
int 013h
jc DiskError
pop bx
pop cx
movzx ebx,bx
add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
sub cx,bx ; Blocks = Blocks - NumberOfBlocks
mov ax,es
shl bx,(BLOCK_SHIFT-4)
add ax,bx
mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmp cx,0
jne ReadCylinderLoop
popa
ret
DiskError:
push cs
pop ds
lea si, [ErrorString]
mov cx, 7
jmp PrintStringAndHalt
PrintStringAndHalt:
mov ax,0b800h
mov es,ax
mov di,160
rep movsw
Halt:
jmp Halt
ErrorString:
db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
org 01fah
LBAOffsetForBootSector:
dd 0h
org 01feh
dw 0aa55h
;******************************************************************************
;******************************************************************************
;******************************************************************************
DELAY_PORT equ 0edh ; Port to use for 1uS delay
KBD_CONTROL_PORT equ 060h ; 8042 control port
KBD_STATUS_PORT equ 064h ; 8042 status port
WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
org 200h
jmp start
Em64String:
db 'E', 0ch, 'm', 0ch, '6', 0ch, '4', 0ch, 'T', 0ch, ' ', 0ch, 'U', 0ch, 'n', 0ch, 's', 0ch, 'u', 0ch, 'p', 0ch, 'p', 0ch, 'o', 0ch, 'r', 0ch, 't', 0ch, 'e', 0ch, 'd', 0ch, '!', 0ch
start:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,MyStack
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[160],'a'
; mov ax,cs
; mov es,ax
mov ebx,0
lea edi,MemoryMap
MemMapLoop:
mov eax,0e820h
mov ecx,20
mov edx,'SMAP'
int 15h
jc MemMapDone
add edi,20
cmp ebx,0
je MemMapDone
jmp MemMapLoop
MemMapDone:
lea eax,MemoryMap
sub edi,eax ; Get the address of the memory map
mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
xor ebx,ebx
mov bx,cs ; BX=segment
shl ebx,4 ; BX="linear" address of segment base
lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
add ebx,01000h ; Source of EFI32
mov dword ptr [JUMP+2],ebx
add ebx,01000h
mov esi,ebx ; Source of EFILDR32
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[162],'b'
; mov ax,cs
; mov es,ax
;
; Enable A20 Gate
;
mov ax,2401h ; Enable A20 Gate
int 15h
jnc A20GateEnabled ; Jump if it suceeded
;
; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
;
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
out DELAY_PORT,ax ; Delay 1 uS
mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
out KBD_STATUS_PORT,al ; Send command to the 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
mov al,ENABLE_A20_CMD ; gate address bit 20 on
out KBD_CONTROL_PORT,al ; Send command to thre 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
mov cx,25 ; Delay 25 uS for the command to complete on the 8042
Delay25uS:
out DELAY_PORT,ax ; Delay 1 uS
loop Delay25uS
Timeout8042:
A20GateEnabled:
mov bx,0008h ; Flat data descriptor
;
; DISABLE INTERRUPTS - Entering Protected Mode
;
cli
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[164],'c'
; mov ax,cs
; mov es,ax
db 66h
lgdt fword ptr [gdtr]
db 66h
lidt fword ptr [idtr]
mov eax,cr0
or al,1
mov cr0,eax
JUMP:
; jmp far 0010:00020000
db 066h
db 0eah
dd 000020000h
dw 00010h
Empty8042InputBuffer:
mov cx,0
Empty8042Loop:
out DELAY_PORT,ax ; Delay 1us
in al,KBD_STATUS_PORT ; Read the 8042 Status Port
and al,02h ; Check the Input Buffer Full Flag
loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
dd 0 ; (GDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; global descriptor table (GDT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
public GDT_BASE
GDT_BASE:
; null descriptor
NULL_SEL equ $-GDT_BASE
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; linear data segment descriptor
LINEAR_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; linear code segment descriptor
LINEAR_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system data segment descriptor
SYS_DATA_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system code segment descriptor
SYS_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE3_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE4_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE5_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
GDT_END:
align 02h
idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
dd 0 ; (IDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; interrupt descriptor table (IDT)
;
; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
; mappings. This implementation only uses the system timer and all other
; IRQs will remain masked. The descriptors for vectors 33+ are provided
; for convenience.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;idt_tag db "IDT",0
align 02h
public IDT_BASE
IDT_BASE:
; divide by zero (INT 0)
DIV_ZERO_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; debug exception (INT 1)
DEBUG_EXCEPT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; NMI (INT 2)
NMI_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; soft breakpoint (INT 3)
BREAKPOINT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; overflow (INT 4)
OVERFLOW_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; bounds check (INT 5)
BOUNDS_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid opcode (INT 6)
INVALID_OPCODE_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; device not available (INT 7)
DEV_NOT_AVAIL_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; double fault (INT 8)
DOUBLE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Coprocessor segment overrun - reserved (INT 9)
RSVD_INTR_SEL1 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid TSS (INT 0ah)
INVALID_TSS_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; segment not present (INT 0bh)
SEG_NOT_PRESENT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; stack fault (INT 0ch)
STACK_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; general protection (INT 0dh)
GP_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; page fault (INT 0eh)
PAGE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Intel reserved - do not use (INT 0fh)
RSVD_INTR_SEL2 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; floating point error (INT 10h)
FLT_POINT_ERR_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; alignment check (INT 11h)
ALIGNMENT_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; machine check (INT 12h)
MACHINE_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; SIMD floating-point exception (INT 13h)
SIMD_EXCEPTION_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
db (85 * 8) dup(0)
; IRQ 0 (System timer) - (INT 68h)
IRQ0_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 1 (8042 Keyboard controller) - (INT 69h)
IRQ1_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
IRQ2_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 3 (COM 2) - (INT 6bh)
IRQ3_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 4 (COM 1) - (INT 6ch)
IRQ4_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 5 (LPT 2) - (INT 6dh)
IRQ5_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 6 (Floppy controller) - (INT 6eh)
IRQ6_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 7 (LPT 1) - (INT 6fh)
IRQ7_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 8 (RTC Alarm) - (INT 70h)
IRQ8_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 9 - (INT 71h)
IRQ9_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 10 - (INT 72h)
IRQ10_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 11 - (INT 73h)
IRQ11_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 12 (PS/2 mouse) - (INT 74h)
IRQ12_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 13 (Floating point error) - (INT 75h)
IRQ13_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 14 (Secondary IDE) - (INT 76h)
IRQ14_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 15 (Primary IDE) - (INT 77h)
IRQ15_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
IDT_END:
align 02h
MemoryMapSize dd 0
MemoryMap dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
org 0fe0h
MyStack:
; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
; known low address (20f00) so it can be set up by PlMapIrqToVect in
; 8259.c
int 8
iret
int 9
iret
int 10
iret
int 11
iret
int 12
iret
int 13
iret
int 14
iret
int 15
iret
org 0ffeh
BlockSignature:
dw 0aa55h
end

View File

@@ -1,927 +0,0 @@
#------------------------------------------------------------------------------
#*
#* Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
#* This program and the accompanying materials
#* are licensed and made available under the terms and conditions of the BSD License
#* which accompanies this distribution. The full text of the license may be found at
#* http://opensource.org/licenses/bsd-license.php
#*
#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#*
#* start32.asm
#*
#* Abstract:
#*
#------------------------------------------------------------------------------
#.MODEL small
.stack:
.486p:
.code16
.equ FAT_DIRECTORY_ENTRY_SIZE, 0x020
.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
.equ BLOCK_SIZE, 0x0200
.equ BLOCK_MASK, 0x01ff
.equ BLOCK_SHIFT, 9
.org 0x0
.global _start
_start:
Ia32Jump:
jmp BootSectorEntryPoint # JMP inst - 3 bytes
nop
OemId: .ascii "INTEL " # OemId - 8 bytes
SectorSize: .word 0 # Sector Size - 2 bytes
SectorsPerCluster: .byte 0 # Sector Per Cluster - 1 byte
ReservedSectors: .word 0 # Reserved Sectors - 2 bytes
NoFats: .byte 0 # Number of FATs - 1 byte
RootEntries: .word 0 # Root Entries - 2 bytes
Sectors: .word 0 # Number of Sectors - 2 bytes
Media: .byte 0 # Media - 1 byte
SectorsPerFat16: .word 0 # Sectors Per FAT for FAT12/FAT16 - 2 byte
SectorsPerTrack: .word 0 # Sectors Per Track - 2 bytes
Heads: .word 0 # Heads - 2 bytes
HiddenSectors: .long 0 # Hidden Sectors - 4 bytes
LargeSectors: .long 0 # Large Sectors - 4 bytes
#******************************************************************************
#
#The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
#the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
#
#******************************************************************************
SectorsPerFat32: .long 0 # Sectors Per FAT for FAT32 - 4 bytes
ExtFlags: .word 0 # Mirror Flag - 2 bytes
FSVersion: .word 0 # File System Version - 2 bytes
RootCluster: .long 0 # 1st Cluster Number of Root Dir - 4 bytes
FSInfo: .word 0 # Sector Number of FSINFO - 2 bytes
BkBootSector: .word 0 # Sector Number of Bk BootSector - 2 bytes
Reserved: .fill 12,1,0 # Reserved Field - 12 bytes
PhysicalDrive: .byte 0 # Physical Drive Number - 1 byte
Reserved1: .byte 0 # Reserved Field - 1 byte
Signature: .byte 0 # Extended Boot Signature - 1 byte
VolId: .ascii " " # Volume Serial Number - 4 bytes
FatLabel: .ascii " " # Volume Label - 11 bytes
FileSystemType: .ascii "FAT32 " # File System Type - 8 bytes
BootSectorEntryPoint:
#ASSUME ds:@code
#ASSUME ss:@code
# ds = 1000, es = 2000 + x (size of first cluster >> 4)
# cx = Start Cluster of EfiLdr
# dx = Start Cluster of Efivar.bin
# Re use the BPB data stored in Boot Sector
movw $0x7c00, %bp
pushw %cx
# Read Efivar.bin
# 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
movw $0x1900, %ax
movw %ax, %es
testw %dx, %dx
jnz CheckVarStoreSize
movb $1, %al
NoVarStore:
pushw %es
# Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
movb %al, %es:4
jmp SaveVolumeId
CheckVarStoreSize:
movw %dx, %di
cmpl $0x4000, %ds:2(%di)
movb $2, %al
jne NoVarStore
LoadVarStore:
movb $0, %al
movb %al, %es:4
movw (%di), %cx
# ES:DI = 1500:0
xorw %di, %di
pushw %es
movw $0x1500, %ax
movw %ax, %es
call ReadFile
SaveVolumeId:
popw %es
movw VolId(%bp), %ax
movw %ax, %es:0 # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
movw VolId+2(%bp), %ax
movw %ax, %es:2
# Read Efildr
popw %cx
# cx = Start Cluster of Efildr -> BS.com has filled already
# ES:DI = 2000:0, first cluster will be read again
xorw %di, %di # di = 0
movw $0x2000, %ax
movw %ax, %es
call ReadFile
movw %cs, %ax
movw %ax, %cs:JumpSegment
JumpFarInstruction:
.byte 0xea
JumpOffset:
.word 0x200
JumpSegment:
.word 0x2000
# ****************************************************************************
# ReadFile
#
# Arguments:
# CX = Start Cluster of File
# ES:DI = Buffer to store file content read from disk
#
# Return:
# (ES << 4 + DI) = end of file content Buffer
#
# ****************************************************************************
ReadFile:
# si = NumberOfClusters
# cx = ClusterNumber
# dx = CachedFatSectorNumber
# ds:0000 = CacheFatSectorBuffer
# es:di = Buffer to load file
# bx = NextClusterNumber
pusha
movw $1, %si # NumberOfClusters = 1
pushw %cx # Push Start Cluster onto stack
movw $0xfff, %dx # CachedFatSectorNumber = 0xfff
FatChainLoop:
movw %cx, %ax # ax = ClusterNumber
andw $0xfff8, %ax # ax = ax & 0xfff8
cmpw $0xfff8, %ax # See if this is the last cluster
je FoundLastCluster # Jump if last cluster found
movw %cx, %ax # ax = ClusterNumber
shlw $2, %ax # FatOffset = ClusterNumber * 4
pushw %si # Save si
movw %ax, %si # si = FatOffset
shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
andw $BLOCK_MASK, %si # si = FatOffset & BLOCK_MASK
cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber
je SkipFatRead
movw $2, %bx
pushw %es
pushw %ds
popw %es
call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
popw %es
movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber
SkipFatRead:
movw (%si), %bx # bx = NextClusterNumber
movw %cx, %ax # ax = ClusterNumber
popw %si # Restore si
decw %bx # bx = NextClusterNumber - 1
cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber
jne ReadClusters
incw %bx # bx = NextClusterNumber
incw %si # NumberOfClusters++
movw %bx, %cx # ClusterNumber = NextClusterNumber
jmp FatChainLoop
ReadClusters:
incw %bx
popw %ax # ax = StartCluster
pushw %bx # StartCluster = NextClusterNumber
movw %bx, %cx # ClusterNumber = NextClusterNumber
subw $2, %ax # ax = StartCluster - 2
xorb %bh, %bh
movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
pushw %ax # save start sector
movw %si, %ax # ax = NumberOfClusters
mulw %bx # ax = NumberOfClusters * SectorsPerCluster
movw %ax, %bx # bx = Number of Sectors
popw %ax # ax = Start Sector
call ReadBlocks
movw $1, %si # NumberOfClusters = 1
jmp FatChainLoop
FoundLastCluster:
popw %cx
popa
ret
# ****************************************************************************
# ReadBlocks - Reads a set of blocks from a block device
#
# AX = Start LBA
# BX = Number of Blocks to Read
# ES:DI = Buffer to store sectors read from disk
# ****************************************************************************
# cx = Blocks
# bx = NumberOfBlocks
# si = StartLBA
ReadBlocks:
pusha
addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
movl %eax, %esi # esi = Start LBA
movw %bx, %cx # cx = Number of blocks to read
ReadCylinderLoop:
movw $0x7bfc, %bp # bp = 0x7bfc
movl %esi, %eax # eax = Start LBA
xorl %edx, %edx # edx = 0
movzwl (%bp), %ebx # bx = MaxSector
divl %ebx # ax = StartLBA / MaxSector
incw %dx # dx = (StartLBA % MaxSector) + 1
movw (%bp), %bx # bx = MaxSector
subw %dx, %bx # bx = MaxSector - Sector
incw %bx # bx = MaxSector - Sector + 1
cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
movw %cx, %bx # bx = Blocks
LimitTransfer:
pushw %ax # save ax
movw %es, %ax # ax = es
shrw $(BLOCK_SHIFT-4), %ax # ax = Number of blocks into mem system
andw $0x7f, %ax # ax = Number of blocks into current seg
addw %bx, %ax # ax = End Block number of transfer
cmpw $0x80, %ax # See if it crosses a 64K boundry
jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
subw $0x80, %ax # ax = Number of blocks past 64K boundry
subw %ax, %bx # Decrease transfer size by block overage
NotCrossing64KBoundry:
popw %ax # restore ax
pushw %cx
movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
xorw %dx, %dx # dx = 0
divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
# dx = ax % (MaxHead + 1) = Head
pushw %bx # Save number of blocks to transfer
movb %dl, %dh # dh = Head
movw $0x7c00, %bp # bp = 0x7c00
movb PhysicalDrive(%bp), %dl # dl = Drive Number
movb %al, %ch # ch = Cylinder
movb %bl, %al # al = Blocks
movb $2, %ah # ah = Function 2
movw %di, %bx # es:bx = Buffer address
int $0x13
jc DiskError
popw %bx
popw %cx
movzwl %bx, %ebx
addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
movw %es, %ax
shlw $(BLOCK_SHIFT-4), %bx
addw %bx, %ax
movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmpw $0, %cx
jne ReadCylinderLoop
popa
ret
DiskError:
pushw %cs
popw %ds
leaw ErrorString, %si
movw $7, %cx
jmp PrintStringAndHalt
PrintStringAndHalt:
movw $0xb800, %ax
movw %ax, %es
movw $160, %di
rep
movsw
Halt:
jmp Halt
ErrorString:
.byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
.org 0x01fa
LBAOffsetForBootSector:
.long 0x0
.org 0x01fe
.word 0xaa55
#******************************************************************************
#******************************************************************************
#******************************************************************************
.equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
.equ KBD_CONTROL_PORT, 0x060 # 8042 control port
.equ KBD_STATUS_PORT, 0x064 # 8042 status port
.equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
.equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
.org 0x200
jmp start
Em64String:
.byte 'E', 0x0c, 'm', 0x0c, '6', 0x0c, '4', 0x0c, 'T', 0x0c, ' ', 0x0c, 'U', 0x0c, 'n', 0x0c, 's', 0x0c, 'u', 0x0c, 'p', 0x0c, 'p', 0x0c, 'o', 0x0c, 'r', 0x0c, 't', 0x0c, 'e', 0x0c, 'd', 0x0c, '!', 0x0c
start:
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $MyStack, %sp
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[160],'a'
# mov ax,cs
# mov es,ax
movl $0, %ebx
leal MemoryMap, %edi
MemMapLoop:
movl $0xe820, %eax
movl $20, %ecx
movl $0x534d4150, %edx # 0x534d4150 = 'SMAP'
int $0x15
jc MemMapDone
addl $20, %edi
cmpl $0, %ebx
je MemMapDone
jmp MemMapLoop
MemMapDone:
leal MemoryMap, %eax
subl %eax, %edi # Get the address of the memory map
movl %edi, MemoryMapSize # Save the size of the memory map
xorl %ebx, %ebx
movw %cs, %bx # BX=segment
shll $4, %ebx # BX="linear" address of segment base
leal GDT_BASE(%ebx), %eax # EAX=PHYSICAL address of gdt
movl %eax, gdtr + 2 # Put address of gdt into the gdtr
leal IDT_BASE(%ebx), %eax # EAX=PHYSICAL address of idt
movl %eax, idtr + 2 # Put address of idt into the idtr
leal MemoryMapSize(%ebx), %edx # Physical base address of the memory map
addl $0x1000, %ebx # Source of EFI32
movl %ebx, JUMP+2
addl $0x1000, %ebx
movl %ebx, %esi # Source of EFILDR32
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[162],'b'
# mov ax,cs
# mov es,ax
#
# Enable A20 Gate
#
movw $0x2401, %ax # Enable A20 Gate
int $0x15
jnc A20GateEnabled # Jump if it suceeded
#
# If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
#
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
jnz Timeout8042 # Jump if the 8042 timed out
outw %ax, $DELAY_PORT # Delay 1 uS
movb $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
outb %al, $KBD_STATUS_PORT # Send command to the 8042
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
jnz Timeout8042 # Jump if the 8042 timed out
movb $ENABLE_A20_CMD, %al # gate address bit 20 on
outb %al, $KBD_CONTROL_PORT # Send command to thre 8042
call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
movw $25, %cx # Delay 25 uS for the command to complete on the 8042
Delay25uS:
outw %ax, $DELAY_PORT # Delay 1 uS
loopl Delay25uS
Timeout8042:
A20GateEnabled:
movw $0x0008, %bx # Flat data descriptor
#
# DISABLE INTERRUPTS - Entering Protected Mode
#
cli
# mov ax,0b800h
# mov es,ax
# mov byte ptr es:[164],'c'
# mov ax,cs
# mov es,ax
.byte 0x66
lgdt gdtr
.byte 0x66
lidt idtr
movl %cr0, %eax
orb $1, %al
movl %eax, %cr0
JUMP:
# jmp far 0010:00020000
.byte 0x66
.byte 0xea
.long 0x00020000
.word 0x0010
Empty8042InputBuffer:
movw $0, %cx
Empty8042Loop:
outw %ax, $DELAY_PORT # Delay 1us
inb $KBD_STATUS_PORT, %al # Read the 8042 Status Port
andb $0x2, %al # Check the Input Buffer Full Flag
loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
ret
##############################################################################
# data
##############################################################################
.p2align 1
gdtr: .word GDT_END - GDT_BASE - 1
.long 0 # (GDT base gets set above)
##############################################################################
# global descriptor table (GDT)
##############################################################################
.p2align 1
GDT_BASE:
# null descriptor
.equ NULL_SEL, .-GDT_BASE
.word 0 # limit 15:0
.word 0 # base 15:0
.byte 0 # base 23:16
.byte 0 # type
.byte 0 # limit 19:16, flags
.byte 0 # base 31:24
# linear data segment descriptor
.equ LINEAR_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x92 # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# linear code segment descriptor
.equ LINEAR_CODE_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x9A # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# system data segment descriptor
.equ SYS_DATA_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x92 # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# system code segment descriptor
.equ SYS_CODE_SEL, .-GDT_BASE
.word 0xFFFF # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0x9A # present, ring 0, data, expand-up, writable
.byte 0xCF # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE3_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE4_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
# spare segment descriptor
.equ SPARE5_SEL, .-GDT_BASE
.word 0 # limit 0xFFFFF
.word 0 # base 0
.byte 0
.byte 0 # present, ring 0, data, expand-up, writable
.byte 0 # page-granular, 32-bit
.byte 0
GDT_END:
.p2align 1
idtr: .word IDT_END - IDT_BASE - 1
.long 0 # (IDT base gets set above)
##############################################################################
# interrupt descriptor table (IDT)
#
# Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
# mappings. This implementation only uses the system timer and all other
# IRQs will remain masked. The descriptors for vectors 33+ are provided
# for convenience.
##############################################################################
#idt_tag db "IDT",0
.p2align 1
IDT_BASE:
# divide by zero (INT 0)
.equ DIV_ZERO_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# debug exception (INT 1)
.equ DEBUG_EXCEPT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# NMI (INT 2)
.equ NMI_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# soft breakpoint (INT 3)
.equ BREAKPOINT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# overflow (INT 4)
.equ OVERFLOW_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# bounds check (INT 5)
.equ BOUNDS_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# invalid opcode (INT 6)
.equ INVALID_OPCODE_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# device not available (INT 7)
.equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# double fault (INT 8)
.equ DOUBLE_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# Coprocessor segment overrun - reserved (INT 9)
.equ RSVD_INTR_SEL1, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# invalid TSS (INT 0ah)
.equ INVALID_TSS_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# segment not present (INT 0bh)
.equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# stack fault (INT 0ch)
.equ STACK_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# general protection (INT 0dh)
.equ GP_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# page fault (INT 0eh)
.equ PAGE_FAULT_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# Intel reserved - do not use (INT 0fh)
.equ RSVD_INTR_SEL2, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# floating point error (INT 10h)
.equ FLT_POINT_ERR_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# alignment check (INT 11h)
.equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# machine check (INT 12h)
.equ MACHINE_CHECK_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# SIMD floating-point exception (INT 13h)
.equ SIMD_EXCEPTION_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
.fill 85 * 8, 1, 0
# IRQ 0 (System timer) - (INT 68h)
.equ IRQ0_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 1 (8042 Keyboard controller) - (INT 69h)
.equ IRQ1_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
.equ IRQ2_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 3 (COM 2) - (INT 6bh)
.equ IRQ3_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 4 (COM 1) - (INT 6ch)
.equ IRQ4_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 5 (LPT 2) - (INT 6dh)
.equ IRQ5_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 6 (Floppy controller) - (INT 6eh)
.equ IRQ6_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 7 (LPT 1) - (INT 6fh)
.equ IRQ7_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 8 (RTC Alarm) - (INT 70h)
.equ IRQ8_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 9 - (INT 71h)
.equ IRQ9_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 10 - (INT 72h)
.equ IRQ10_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 11 - (INT 73h)
.equ IRQ11_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 12 (PS/2 mouse) - (INT 74h)
.equ IRQ12_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 13 (Floating point error) - (INT 75h)
.equ IRQ13_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 14 (Secondary IDE) - (INT 76h)
.equ IRQ14_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
# IRQ 15 (Primary IDE) - (INT 77h)
.equ IRQ15_SEL, .-IDT_BASE
.word 0 # offset 15:0
.word SYS_CODE_SEL # selector 15:0
.byte 0 # 0 for interrupt gate
.byte 0x0e | 0x80 # type = 386 interrupt gate, present
.word 0 # offset 31:16
IDT_END:
.p2align 1
MemoryMapSize: .long 0
MemoryMap: .long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.org 0x0fe0
MyStack:
# below is the pieces of the IVT that is used to redirect INT 68h - 6fh
# back to INT 08h - 0fh when in real mode... It is 'org'ed to a
# known low address (20f00) so it can be set up by PlMapIrqToVect in
# 8259.c
int $8
iret
int $9
iret
int $10
iret
int $11
iret
int $12
iret
int $13
iret
int $14
iret
int $15
iret
.org 0x0ffe
BlockSignature:
.word 0xaa55

View File

@@ -1,924 +0,0 @@
;------------------------------------------------------------------------------
;*
;* Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
;* This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;* start32.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
.stack
.486p
.code
FAT_DIRECTORY_ENTRY_SIZE EQU 020h
FAT_DIRECTORY_ENTRY_SHIFT EQU 5
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
org 0h
Ia32Jump:
jmp BootSectorEntryPoint ; JMP inst - 3 bytes
nop
OemId db "INTEL " ; OemId - 8 bytes
SectorSize dw 0 ; Sector Size - 2 bytes
SectorsPerCluster db 0 ; Sector Per Cluster - 1 byte
ReservedSectors dw 0 ; Reserved Sectors - 2 bytes
NoFats db 0 ; Number of FATs - 1 byte
RootEntries dw 0 ; Root Entries - 2 bytes
Sectors dw 0 ; Number of Sectors - 2 bytes
Media db 0 ; Media - 1 byte
SectorsPerFat16 dw 0 ; Sectors Per FAT for FAT12/FAT16 - 2 byte
SectorsPerTrack dw 0 ; Sectors Per Track - 2 bytes
Heads dw 0 ; Heads - 2 bytes
HiddenSectors dd 0 ; Hidden Sectors - 4 bytes
LargeSectors dd 0 ; Large Sectors - 4 bytes
;******************************************************************************
;
;The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
;the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
;
;******************************************************************************
SectorsPerFat32 dd 0 ; Sectors Per FAT for FAT32 - 4 bytes
ExtFlags dw 0 ; Mirror Flag - 2 bytes
FSVersion dw 0 ; File System Version - 2 bytes
RootCluster dd 0 ; 1st Cluster Number of Root Dir - 4 bytes
FSInfo dw 0 ; Sector Number of FSINFO - 2 bytes
BkBootSector dw 0 ; Sector Number of Bk BootSector - 2 bytes
Reserved db 12 dup(0) ; Reserved Field - 12 bytes
PhysicalDrive db 0 ; Physical Drive Number - 1 byte
Reserved1 db 0 ; Reserved Field - 1 byte
Signature db 0 ; Extended Boot Signature - 1 byte
VolId db " " ; Volume Serial Number - 4 bytes
FatLabel db " " ; Volume Label - 11 bytes
FileSystemType db "FAT32 " ; File System Type - 8 bytes
BootSectorEntryPoint:
ASSUME ds:@code
ASSUME ss:@code
; ds = 1000, es = 2000 + x (size of first cluster >> 4)
; cx = Start Cluster of EfiLdr
; dx = Start Cluster of Efivar.bin
; Re use the BPB data stored in Boot Sector
mov bp,07c00h
push cx
; Read Efivar.bin
; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
mov ax,01900h
mov es,ax
test dx,dx
jnz CheckVarStoreSize
mov al,1
NoVarStore:
push es
; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
mov byte ptr es:[4],al
jmp SaveVolumeId
CheckVarStoreSize:
mov di,dx
cmp dword ptr ds:[di+2], 04000h
mov al,2
jne NoVarStore
LoadVarStore:
mov al,0
mov byte ptr es:[4],al
mov cx,word ptr[di]
; ES:DI = 1500:0
xor di,di
push es
mov ax,01500h
mov es,ax
call ReadFile
SaveVolumeId:
pop es
mov ax,word ptr [bp+VolId]
mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
mov ax,word ptr [bp+VolId+2]
mov word ptr es:[2],ax
; Read Efildr
pop cx
; cx = Start Cluster of Efildr -> BS.com has filled already
; ES:DI = 2000:0, first cluster will be read again
xor di,di ; di = 0
mov ax,02000h
mov es,ax
call ReadFile
mov ax,cs
mov word ptr cs:[JumpSegment],ax
JumpFarInstruction:
db 0eah
JumpOffset:
dw 0200h
JumpSegment:
dw 2000h
; ****************************************************************************
; ReadFile
;
; Arguments:
; CX = Start Cluster of File
; ES:DI = Buffer to store file content read from disk
;
; Return:
; (ES << 4 + DI) = end of file content Buffer
;
; ****************************************************************************
ReadFile:
; si = NumberOfClusters
; cx = ClusterNumber
; dx = CachedFatSectorNumber
; ds:0000 = CacheFatSectorBuffer
; es:di = Buffer to load file
; bx = NextClusterNumber
pusha
mov si,1 ; NumberOfClusters = 1
push cx ; Push Start Cluster onto stack
mov dx,0fffh ; CachedFatSectorNumber = 0xfff
FatChainLoop:
mov ax,cx ; ax = ClusterNumber
and ax,0fff8h ; ax = ax & 0xfff8
cmp ax,0fff8h ; See if this is the last cluster
je FoundLastCluster ; Jump if last cluster found
mov ax,cx ; ax = ClusterNumber
shl ax,2 ; FatOffset = ClusterNumber * 4
push si ; Save si
mov si,ax ; si = FatOffset
shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
je SkipFatRead
mov bx,2
push es
push ds
pop es
call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
pop es
mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
SkipFatRead:
mov bx,word ptr [si] ; bx = NextClusterNumber
mov ax,cx ; ax = ClusterNumber
pop si ; Restore si
dec bx ; bx = NextClusterNumber - 1
cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
jne ReadClusters
inc bx ; bx = NextClusterNumber
inc si ; NumberOfClusters++
mov cx,bx ; ClusterNumber = NextClusterNumber
jmp FatChainLoop
ReadClusters:
inc bx
pop ax ; ax = StartCluster
push bx ; StartCluster = NextClusterNumber
mov cx,bx ; ClusterNumber = NextClusterNumber
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
push ax ; save start sector
mov ax,si ; ax = NumberOfClusters
mul bx ; ax = NumberOfClusters * SectorsPerCluster
mov bx,ax ; bx = Number of Sectors
pop ax ; ax = Start Sector
call ReadBlocks
mov si,1 ; NumberOfClusters = 1
jmp FatChainLoop
FoundLastCluster:
pop cx
popa
ret
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; AX = Start LBA
; BX = Number of Blocks to Read
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; cx = Blocks
; bx = NumberOfBlocks
; si = StartLBA
ReadBlocks:
pusha
add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
mov esi,eax ; esi = Start LBA
mov cx,bx ; cx = Number of blocks to read
ReadCylinderLoop:
mov bp,07bfch ; bp = 0x7bfc
mov eax,esi ; eax = Start LBA
xor edx,edx ; edx = 0
movzx ebx,word ptr [bp] ; bx = MaxSector
div ebx ; ax = StartLBA / MaxSector
inc dx ; dx = (StartLBA % MaxSector) + 1
mov bx,word ptr [bp] ; bx = MaxSector
sub bx,dx ; bx = MaxSector - Sector
inc bx ; bx = MaxSector - Sector + 1
cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
mov bx,cx ; bx = Blocks
LimitTransfer:
push ax ; save ax
mov ax,es ; ax = es
shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
and ax,07fh ; ax = Number of blocks into current seg
add ax,bx ; ax = End Block number of transfer
cmp ax,080h ; See if it crosses a 64K boundry
jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
sub ax,080h ; ax = Number of blocks past 64K boundry
sub bx,ax ; Decrease transfer size by block overage
NotCrossing64KBoundry:
pop ax ; restore ax
push cx
mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
xor dx,dx ; dx = 0
div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
; dx = ax % (MaxHead + 1) = Head
push bx ; Save number of blocks to transfer
mov dh,dl ; dh = Head
mov bp,07c00h ; bp = 0x7c00
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
mov ch,al ; ch = Cylinder
mov al,bl ; al = Blocks
mov ah,2 ; ah = Function 2
mov bx,di ; es:bx = Buffer address
int 013h
jc DiskError
pop bx
pop cx
movzx ebx,bx
add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
sub cx,bx ; Blocks = Blocks - NumberOfBlocks
mov ax,es
shl bx,(BLOCK_SHIFT-4)
add ax,bx
mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmp cx,0
jne ReadCylinderLoop
popa
ret
DiskError:
push cs
pop ds
lea si, [ErrorString]
mov cx, 7
jmp PrintStringAndHalt
PrintStringAndHalt:
mov ax,0b800h
mov es,ax
mov di,160
rep movsw
Halt:
jmp Halt
ErrorString:
db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
org 01fah
LBAOffsetForBootSector:
dd 0h
org 01feh
dw 0aa55h
;******************************************************************************
;******************************************************************************
;******************************************************************************
DELAY_PORT equ 0edh ; Port to use for 1uS delay
KBD_CONTROL_PORT equ 060h ; 8042 control port
KBD_STATUS_PORT equ 064h ; 8042 status port
WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
org 200h
jmp start
Em64String:
db 'E', 0ch, 'm', 0ch, '6', 0ch, '4', 0ch, 'T', 0ch, ' ', 0ch, 'U', 0ch, 'n', 0ch, 's', 0ch, 'u', 0ch, 'p', 0ch, 'p', 0ch, 'o', 0ch, 'r', 0ch, 't', 0ch, 'e', 0ch, 'd', 0ch, '!', 0ch
start:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,MyStack
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[160],'a'
; mov ax,cs
; mov es,ax
mov ebx,0
lea edi,MemoryMap
MemMapLoop:
mov eax,0e820h
mov ecx,20
mov edx,'SMAP'
int 15h
jc MemMapDone
add edi,20
cmp ebx,0
je MemMapDone
jmp MemMapLoop
MemMapDone:
lea eax,MemoryMap
sub edi,eax ; Get the address of the memory map
mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
xor ebx,ebx
mov bx,cs ; BX=segment
shl ebx,4 ; BX="linear" address of segment base
lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
add ebx,01000h ; Source of EFI32
mov dword ptr [JUMP+2],ebx
add ebx,01000h
mov esi,ebx ; Source of EFILDR32
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[162],'b'
; mov ax,cs
; mov es,ax
;
; Enable A20 Gate
;
mov ax,2401h ; Enable A20 Gate
int 15h
jnc A20GateEnabled ; Jump if it suceeded
;
; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
;
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
out DELAY_PORT,ax ; Delay 1 uS
mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
out KBD_STATUS_PORT,al ; Send command to the 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
mov al,ENABLE_A20_CMD ; gate address bit 20 on
out KBD_CONTROL_PORT,al ; Send command to thre 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
mov cx,25 ; Delay 25 uS for the command to complete on the 8042
Delay25uS:
out DELAY_PORT,ax ; Delay 1 uS
loop Delay25uS
Timeout8042:
A20GateEnabled:
mov bx,0008h ; Flat data descriptor
;
; DISABLE INTERRUPTS - Entering Protected Mode
;
cli
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[164],'c'
; mov ax,cs
; mov es,ax
db 66h
lgdt fword ptr [gdtr]
db 66h
lidt fword ptr [idtr]
mov eax,cr0
or al,1
mov cr0,eax
JUMP:
; jmp far 0010:00020000
db 066h
db 0eah
dd 000020000h
dw 00010h
Empty8042InputBuffer:
mov cx,0
Empty8042Loop:
out DELAY_PORT,ax ; Delay 1us
in al,KBD_STATUS_PORT ; Read the 8042 Status Port
and al,02h ; Check the Input Buffer Full Flag
loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
dd 0 ; (GDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; global descriptor table (GDT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
public GDT_BASE
GDT_BASE:
; null descriptor
NULL_SEL equ $-GDT_BASE
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; linear data segment descriptor
LINEAR_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; linear code segment descriptor
LINEAR_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system data segment descriptor
SYS_DATA_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system code segment descriptor
SYS_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE3_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE4_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE5_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
GDT_END:
align 02h
idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
dd 0 ; (IDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; interrupt descriptor table (IDT)
;
; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
; mappings. This implementation only uses the system timer and all other
; IRQs will remain masked. The descriptors for vectors 33+ are provided
; for convenience.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;idt_tag db "IDT",0
align 02h
public IDT_BASE
IDT_BASE:
; divide by zero (INT 0)
DIV_ZERO_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; debug exception (INT 1)
DEBUG_EXCEPT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; NMI (INT 2)
NMI_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; soft breakpoint (INT 3)
BREAKPOINT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; overflow (INT 4)
OVERFLOW_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; bounds check (INT 5)
BOUNDS_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid opcode (INT 6)
INVALID_OPCODE_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; device not available (INT 7)
DEV_NOT_AVAIL_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; double fault (INT 8)
DOUBLE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Coprocessor segment overrun - reserved (INT 9)
RSVD_INTR_SEL1 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid TSS (INT 0ah)
INVALID_TSS_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; segment not present (INT 0bh)
SEG_NOT_PRESENT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; stack fault (INT 0ch)
STACK_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; general protection (INT 0dh)
GP_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; page fault (INT 0eh)
PAGE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Intel reserved - do not use (INT 0fh)
RSVD_INTR_SEL2 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; floating point error (INT 10h)
FLT_POINT_ERR_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; alignment check (INT 11h)
ALIGNMENT_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; machine check (INT 12h)
MACHINE_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; SIMD floating-point exception (INT 13h)
SIMD_EXCEPTION_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
db (85 * 8) dup(0)
; IRQ 0 (System timer) - (INT 68h)
IRQ0_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 1 (8042 Keyboard controller) - (INT 69h)
IRQ1_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
IRQ2_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 3 (COM 2) - (INT 6bh)
IRQ3_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 4 (COM 1) - (INT 6ch)
IRQ4_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 5 (LPT 2) - (INT 6dh)
IRQ5_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 6 (Floppy controller) - (INT 6eh)
IRQ6_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 7 (LPT 1) - (INT 6fh)
IRQ7_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 8 (RTC Alarm) - (INT 70h)
IRQ8_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 9 - (INT 71h)
IRQ9_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 10 - (INT 72h)
IRQ10_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 11 - (INT 73h)
IRQ11_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 12 (PS/2 mouse) - (INT 74h)
IRQ12_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 13 (Floating point error) - (INT 75h)
IRQ13_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 14 (Secondary IDE) - (INT 76h)
IRQ14_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 15 (Primary IDE) - (INT 77h)
IRQ15_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
IDT_END:
align 02h
MemoryMapSize dd 0
MemoryMap dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
org 0fe0h
MyStack:
; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
; known low address (20f00) so it can be set up by PlMapIrqToVect in
; 8259.c
int 8
iret
int 9
iret
int 10
iret
int 11
iret
int 12
iret
int 13
iret
int 14
iret
int 15
iret
org 0ffeh
BlockSignature:
dw 0aa55h
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,145 +0,0 @@
@echo off
@REM ## @file
@REM #
@REM # Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
@REM #
@REM # This program and the accompanying materials
@REM # are licensed and made available under the terms and conditions of the BSD License
@REM # which accompanies this distribution. The full text of the license may be found at
@REM # http://opensource.org/licenses/bsd-license.php
@REM # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
@REM # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@REM #
@REM #
@REM ##
@REM Set up environment at first.
set BASETOOLS_DIR=%EDK_TOOLS_BIN%
set BOOTSECTOR_BIN_DIR=%WORKSPACE%\DuetPkg\BootSector\bin
set DISK_LABEL=DUET
set PROCESSOR=""
set STEP=1
if "%1"=="" goto Help
if "%2"=="" goto Help
if "%3"=="" goto Help
if "%4"=="" goto Set_BootDisk
if "%4"=="step2" (@set STEP=2) else @set TARGET_ARCH=%4
if "%5"=="step2" @set STEP=2
:Set_BootDisk
set EFI_BOOT_DISK=%2
if "%TARGET_ARCH%"=="IA32" set PROCESSOR=IA32
if "%TARGET_ARCH%"=="X64" set PROCESSOR=X64
if %PROCESSOR%=="" goto WrongArch
call %WORKSPACE%\DuetPkg\SetEnv_%PROCESSOR%.bat
set BUILD_DIR=%WORKSPACE%\Build\DuetPkg%PROCESSOR%\%TARGET%_%TOOL_CHAIN_TAG%
if "%1"=="floppy" goto CreateFloppy
if "%1"=="file" goto CreateFile
if "%1"=="usb" goto CreateUsb
if "%1"=="ide" goto CreateIde
goto Help
:CreateFloppy
if NOT "%3"=="FAT12" goto WrongFATType
echo Start to create floppy boot disk ...
echo Format %EFI_BOOT_DISK% ...
echo.> FormatCommandInput.txt
echo.n>> FormatCommandInput.txt
format /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
del FormatCommandInput.txt
echo Create boot sector ...
%BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o FDBs.com
copy %BOOTSECTOR_BIN_DIR%\Bootsect.com FDBs-1.com
%BASETOOLS_DIR%\Bootsectimage.exe -g FDBs.com FDBs-1.com -f
@REM @del FDBS.com
%BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i FDBs-1.com
del FDBs-1.com
echo Done.
copy %BUILD_DIR%\FV\EfiLdr %EFI_BOOT_DISK%
goto CreateBootFile
:CreateFile
if NOT "%3"=="FAT12" goto WrongFATType
echo Start to create file boot disk ...
echo Create boot sector ...
%BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o FDBs.com
copy %BOOTSECTOR_BIN_DIR%\Bootsect.com FDBs-1.com
%BASETOOLS_DIR%\Bootsectimage.exe -g FDBs.com FDBs-1.com -f
REM @del FDBS.com
%BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i FDBs-1.com
del FDBs-1.com
echo Done.
goto end
:CreateUsb
echo Start to create usb boot disk ...
if "%3"=="FAT16" goto CreateUsb_FAT16
if "%3"=="FAT32" goto CreateUsb_FAT32
if "%3"=="FAT12" goto WrongFATType
:CreateUsb_FAT16
if "%STEP%"=="2" goto CreateUsb_FAT16_step2
echo Format %EFI_BOOT_DISK% ...
echo.> FormatCommandInput.txt
format /FS:FAT /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
del FormatCommandInput.txt
echo Create boot sector ...
%BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o UsbBs16.com
copy %BOOTSECTOR_BIN_DIR%\Bs16.com Bs16-1.com
%BASETOOLS_DIR%\Bootsectimage.exe -g UsbBs16.com Bs16-1.com -f
%BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i Bs16-1.com
del Bs16-1.com
%BASETOOLS_DIR%\Genbootsector.exe -m -o %EFI_BOOT_DISK% -i %BOOTSECTOR_BIN_DIR%\Mbr.com
echo Done.
echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN!
goto end
:CreateUsb_FAT16_step2
copy %BUILD_DIR%\FV\EfiLdr16 %EFI_BOOT_DISK%
goto CreateBootFile
:CreateUsb_FAT32
if "%STEP%"=="2" goto CreateUsb_FAT32_step2
echo Format %EFI_BOOT_DISK% ...
echo.> FormatCommandInput.txt
format /FS:FAT32 /v:%DISK_LABEL% /q %EFI_BOOT_DISK% < FormatCommandInput.txt > NUL
del FormatCommandInput.txt
echo Create boot sector ...
%BASETOOLS_DIR%\Genbootsector.exe -i %EFI_BOOT_DISK% -o UsbBs32.com
copy %BOOTSECTOR_BIN_DIR%\Bs32.com Bs32-1.com
%BASETOOLS_DIR%\Bootsectimage.exe -g UsbBs32.com Bs32-1.com -f
del UsbBs32.com
%BASETOOLS_DIR%\Genbootsector.exe -o %EFI_BOOT_DISK% -i Bs32-1.com
del Bs32-1.com
%BASETOOLS_DIR%\Genbootsector.exe -m -o %EFI_BOOT_DISK% -i %BOOTSECTOR_BIN_DIR%\Mbr.com
echo Done.
echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN!
goto end
:CreateUsb_FAT32_step2
copy %BUILD_DIR%\FV\EfiLdr20 %EFI_BOOT_DISK%
goto CreateBootFile
:CreateIde
goto end
:CreateBootFile
mkdir %EFI_BOOT_DISK%\efi\boot
copy %WORKSPACE%\ShellBinPkg\UefiShell\%PROCESSOR%\Shell.efi %EFI_BOOT_DISK%\efi\boot\boot%PROCESSOR%.efi /y
goto end
:WrongFATType
echo Wrong FAT type %3 for %1
goto end
:WrongArch
echo Error! Wrong architecture.
goto Help
:Help
echo "Usage: CreateBootDisk [usb|floppy|ide] DiskNumber [FAT12|FAT16|FAT32] [IA32|X64]"
:end
echo on

View File

@@ -1,212 +0,0 @@
#! /bin/sh
## @file
#
# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
# Set up environment at fisrt.
if [ -z "$EDK_TOOLS_PATH" ]
then
export BASETOOLS_DIR=$WORKSPACE/Conf/BaseToolsSource/Source/C/bin
else
export BASETOOLS_DIR=$EDK_TOOLS_PATH/Source/C/bin
fi
export BOOTSECTOR_BIN_DIR=$WORKSPACE/DuetPkg/BootSector/bin
export DISK_LABEL=DUET
export PROCESS_MARK=TRUE
if [ \
-z "$*" -o \
"$*" = "-?" -o \
"$*" = "-h" -o \
"$*" = "--help" \
]
then
echo "Usage: CreateBootDisk [usb|floppy|ide|file] MediaPath DevicePath [FAT12|FAT16|FAT32] [IA32|X64]"
echo "e.g. : CreateBootDisk floppy /media/floppy0 /dev/fd0 FAT12 IA32"
PROCESS_MARK=FALSE
fi
case "$5" in
IA32)
export PROCESSOR=IA32
;;
X64)
export PROCESSOR=X64
;;
*)
echo Invalid Architecture string, should be only IA32 or X64
return 1
esac
. $WORKSPACE/DuetPkg/SetEnv_$PROCESSOR.sh
export BUILD_DIR=$WORKSPACE/Build/DuetPkg$PROCESSOR/DEBUG_$TOOLCHAIN
export EFI_BOOT_MEDIA=$2
export EFI_BOOT_DEVICE=$3
if [ "$PROCESS_MARK" = TRUE ]
then
case "$1" in
floppy)
if [ "$4" = FAT12 ]
then
echo Start to create floppy boot disk ...
echo Format $EFI_BOOT_MEDIA ...
## Format floppy disk
umount $EFI_BOOT_MEDIA
mkfs.msdos $EFI_BOOT_DEVICE
mount $EFI_BOOT_DEVICE $EFI_BOOT_MEDIA
echo Create boot sector ...
## Linux version of GenBootSector has not pass build yet.
$BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o FDBs.com
cp $BOOTSECTOR_BIN_DIR/bootsect.com FDBs-1.com
$BASETOOLS_DIR/BootSectImage -g FDBs.com FDBs-1.com -f
$BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i FDBs-1.com
rm FDBs-1.com
cp $BUILD_DIR/FV/Efildr $EFI_BOOT_MEDIA
mkdir -p $EFI_BOOT_MEDIA/efi
mkdir -p $EFI_BOOT_MEDIA/efi/boot
if [ "$5" = IA32 ]
then
cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
else
if [ "$5" = X64 ]
then
cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
else
echo Wrong Arch!
fi
fi
echo Done.
else
echo "Wrong FAT type $4 for floppy!"
fi
;;
file) # CreateFile
if [ "$4" = FAT12 ]
then
echo "Start to create file boot disk ..."
dd bs=512 count=2880 if=/dev/zero of=$EFI_BOOT_MEDIA
mkfs.msdos -F 12 $EFI_BOOT_MEDIA
mcopy -i $EFI_BOOT_MEDIA $BUILD_DIR/FV/Efildr ::/Efildr
mmd -i $EFI_BOOT_MEDIA ::/efi ::/efi/boot
if [ "$5" = IA32 ]
then
mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi ::/efi/boot/boot$5.efi
elif [ "$5" = X64 ]
then
mcopy -i $EFI_BOOT_MEDIA $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi ::/efi/boot/boot$5.efi
else
echo Wrong Arch!
fi
mdir -i $EFI_BOOT_MEDIA -s ::
## Linux version of GenBootSector has not pass build yet.
$BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_MEDIA -o $EFI_BOOT_MEDIA.bs0
cp $BOOTSECTOR_BIN_DIR/bootsect.com $EFI_BOOT_MEDIA.bs1
$BASETOOLS_DIR/BootSectImage -g $EFI_BOOT_MEDIA.bs0 $EFI_BOOT_MEDIA.bs1
$BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_MEDIA -i $EFI_BOOT_MEDIA.bs1
rm $EFI_BOOT_MEDIA.bs[0-1]
echo Done.
else
echo "Wrong FAT type" $4 "for floppy!"
fi
;;
usb) # CreateUsb
if [ "$4" = FAT16 ]
then
if [ "$6" = step2 ]
then
cp $BUILD_DIR/FV/Efildr16 $EFI_BOOT_MEDIA
mkdir $EFI_BOOT_MEDIA/efi/boot
if [ "$5" = IA32 ]
then
cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
else
if [ "$5" = X64 ]
then
cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
else
echo Wrong Arch!
fi
fi
echo "step2 Done!"
else
echo Format $EFI_BOOT_DEVICE ...
#Do format command.
echo Create boot sector ...
## Linux version of GenBootSector & Bootsectimage has not pass build yet.
$BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs16.com
cp $BOOTSECTOR_BIN_DIR/bs16.com Bs16-1.com
$BASETOOLS_DIR/BootSectImage -g UsbBs16.com Bs16-1.com -f
$BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i Bs16-1.com
rm Bs16-1.com
$BASETOOLS_DIR/GnuGenBootSector -m -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/Mbr.com
echo Done.
echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2!
fi
elif [ "$4" = FAT32 ]
then
if [ "$6" = step2 ]
then
cp $BUILD_DIR/FV/Efildr20 $EFI_BOOT_MEDIA
mkdir $EFI_BOOT_MEDIA/efi/boot
if [ "$5" = IA32 ]
then
cp $WORKSPACE/ShellBinPkg/UefiShell/Ia32/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
else
if [ "$5" = X64 ]
then
cp $WORKSPACE/ShellBinPkg/UefiShell/X64/Shell.efi $EFI_BOOT_MEDIA/efi/boot/boot$5.efi
else
echo Wrong Arch!
fi
fi
echo "step2 Done!"
else
echo Format $EFI_BOOT_DEVICE ...
#Do format command.
echo Create boot sector ...
## Linux version of GenBootSector & Bootsectimage has not pass build yet.
$BASETOOLS_DIR/GnuGenBootSector -i $EFI_BOOT_DEVICE -o UsbBs32.com
cp $BOOTSECTOR_BIN_DIR/bs32.com Bs32-1.com
$BASETOOLS_DIR/BootSectImage -g UsbBs32.com Bs32-1.com -f
$BASETOOLS_DIR/GnuGenBootSector -o $EFI_BOOT_DEVICE -i Bs32-1.com
rm Bs32-1.com
$BASETOOLS_DIR/GnuGenBootSector -m -o $EFI_BOOT_DEVICE -i $BOOTSECTOR_BIN_DIR/Mbr.com
echo Done.
echo PLEASE UNPLUG USB, THEN PLUG IT AGAIN TO DO STEP2!
fi
else
echo "Wrong FAT type $1 for floppy!"
fi
;;
ide) # CreateIde
echo "Not support yet!"
;;
*)
echo "Arg1 should be [floppy | file | usb | ide] !"
esac
fi

View File

@@ -1,42 +0,0 @@
## @file
#
# This Package provides all definitions(including functions, MACROs, structures and library classes)
# and libraries instances, which are only used by Duet platform.
#
# Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available under
# the terms and conditions of the BSD License which accompanies this distribution.
# The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
DEC_SPECIFICATION = 0x00010005
PACKAGE_NAME = DuetPkg
PACKAGE_GUID = 151B568B-B390-4cf1-ABD6-228E0AB96F57
PACKAGE_VERSION = 0.4
[Includes]
Include
[Guids]
gEfiPciExpressBaseAddressGuid = {0x3677d529, 0x326f, 0x4603, {0xa9, 0x26, 0xea, 0xac, 0xe0, 0x1d, 0xcb, 0xb0 }}
gEfiAcpiDescriptionGuid = {0x3c699197, 0x093c, 0x4c69, {0xb0, 0x6b, 0x12, 0x8a, 0xe3, 0x48, 0x1d, 0xc9 }}
gEfiFlashMapHobGuid = { 0xb091e7d2, 0x5a0, 0x4198, {0x94, 0xf0, 0x74, 0xb7, 0xb8, 0xc5, 0x54, 0x59 }}
## Include/Guid/PciOptionRomTable.h
gEfiPciOptionRomTableGuid = { 0x7462660F, 0x1CBD, 0x48DA, { 0xAD, 0x11, 0x91, 0x71, 0x79, 0x13, 0x83, 0x1C }}
## Include/Guid/ConsoleOutConfig.h
gDuetConsoleOutConfigGuid = { 0xED150714, 0xDF30, 0x407D, { 0xB2, 0x4A, 0x4B, 0x74, 0x2F, 0xD5, 0xCE, 0xA2 }}
## Include/Guid/DxeCoreFileName.h
gDxeCoreFileNameGuid = { 0xD6A2CB7F, 0x6A18, 0x4e2f, { 0xB4, 0x3B, 0x99, 0x20, 0xA7, 0x33, 0x70, 0x0A }}
## Include/Guid/LdrMemoryDescriptor.h
gLdrMemoryDescriptorGuid = { 0x7701d7e5, 0x7d1d, 0x4432, { 0xa4, 0x68, 0x67, 0x3d, 0xab, 0x8a, 0xde, 0x60 }}

View File

@@ -1,150 +0,0 @@
## @file
# This is DUET FDF file with UEFI HII features enabled
#
# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
################################################################################
#
# FV Section
#
# [FV] section is used to define what components or modules are placed within a flash
# device file. This section also defines order the components and modules are positioned
# within the image. The [FV] section consists of define statements, set statements and
# module statements.
#
################################################################################
[FV.DuetEfiMainFv]
BlockSize = 0x10000
FvAlignment = 16 #FV alignment and FV attributes setting.
ERASE_POLARITY = 1
MEMORY_MAPPED = TRUE
STICKY_WRITE = TRUE
LOCK_CAP = TRUE
LOCK_STATUS = TRUE
WRITE_DISABLED_CAP = TRUE
WRITE_ENABLED_CAP = TRUE
WRITE_STATUS = TRUE
WRITE_LOCK_CAP = TRUE
WRITE_LOCK_STATUS = TRUE
READ_DISABLED_CAP = TRUE
READ_ENABLED_CAP = TRUE
READ_STATUS = TRUE
READ_LOCK_CAP = TRUE
READ_LOCK_STATUS = TRUE
APRIORI DXE {
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
INF PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf
}
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
INF DuetPkg/FSVariable/FSVariable.inf
INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
INF DuetPkg/SmbiosGenDxe/SmbiosGen.inf
#INF DuetPkg/FvbRuntimeService/DUETFwh.inf
INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf
INF UefiCpuPkg/CpuDxe/CpuDxe.inf
INF PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf
INF DuetPkg/AcpiResetDxe/Reset.inf
INF DuetPkg/LegacyMetronome/Metronome.inf
INF PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
INF DuetPkg/PciRootBridgeNoEnumerationDxe/PciRootBridgeNoEnumeration.inf
INF DuetPkg/PciBusNoEnumerationDxe/PciBusNoEnumeration.inf
INF IntelFrameworkModulePkg/Bus/Pci/VgaMiniPortDxe/VgaMiniPortDxe.inf
INF IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClassDxe.inf
# IDE/AHCI Support
INF DuetPkg/SataControllerDxe/SataControllerDxe.inf
INF MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf
INF MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf
INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
# Usb Support
INF MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
INF MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf
INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
# ISA Support
INF PcAtChipsetPkg/IsaAcpiDxe/IsaAcpi.inf
INF IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBusDxe.inf
INF IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/IsaSerialDxe.inf
INF IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboardDxe.inf
INF IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppyDxe.inf
INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
INF DuetPkg/BiosVideoThunkDxe/BiosVideo.inf
INF FatPkg/EnhancedFatDxe/Fat.inf
FILE FREEFORM = PCD(gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile) {
SECTION RAW = MdeModulePkg/Logo/Logo.bmp
}
[Rule.Common.DXE_CORE]
FILE DXE_CORE = $(NAMED_GUID) {
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
}
[Rule.Common.UEFI_DRIVER]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
}
[Rule.Common.DXE_DRIVER]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
}
[Rule.Common.DXE_RUNTIME_DRIVER]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
}
[Rule.Common.UEFI_APPLICATION]
FILE APPLICATION = $(NAMED_GUID) {
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
}
[Rule.Common.UEFI_DRIVER.BINARY]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional |.depex
PE32 PE32 |.efi
}

View File

@@ -1,283 +0,0 @@
## @file
# An EFI/Framework Emulation Platform with UEFI HII interface supported.
#
# Developer's UEFI Emulation. DUET provides an EFI/UEFI IA32/X64 environment on legacy BIOS,
# to help developing and debugging native EFI/UEFI drivers.
#
# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
################################################################################
#
# Defines Section - statements that will be processed to create a Makefile.
#
################################################################################
[Defines]
PLATFORM_NAME = DuetPkg
PLATFORM_GUID = 199E24E0-0989-42aa-87F2-611A8C397E72
PLATFORM_VERSION = 0.4
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/DuetPkgIA32
SUPPORTED_ARCHITECTURES = IA32
BUILD_TARGETS = DEBUG
SKUID_IDENTIFIER = DEFAULT
FLASH_DEFINITION = DuetPkg/DuetPkg.fdf
!if $(TOOL_CHAIN_TAG) == GCC47 || $(TOOL_CHAIN_TAG) == GCC48 || $(TOOL_CHAIN_TAG) == GCC49 || $(TOOL_CHAIN_TAG) == GCC5
POSTBUILD = DuetPkg/PostBuild.sh
!else
POSTBUILD = DuetPkg/PostBuild.bat
!endif
################################################################################
#
# Library Class section - list of all Library Classes needed by this Platform.
#
################################################################################
[LibraryClasses]
#
# Entry point
#
PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
#
# Basic
#
BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
#
# UEFI & PI
#
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
#
# Generic Modules
#
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
#
# Platform
#
PlatformBdsLib|DuetPkg/Library/DuetBdsLib/PlatformBds.inf
TimerLib|DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf
#
# Misc
#
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
#
# To save size, use NULL library for DebugLib and ReportStatusCodeLib.
# If need status code output, do library instance overriden as below DxeMain.inf does
#
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
[LibraryClasses.common.DXE_CORE]
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
################################################################################
#
# Pcd Section - list of all EDK II PCD Entries defined by this Platform
#
################################################################################
[PcdsFixedAtBuild]
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x0
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x0
gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
[PcdsFeatureFlag]
gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE
###################################################################################################
#
# Components Section - list of the modules and components that will be processed by compilation
# tools and the EDK II tools to generate PE32/PE32+/Coff image files.
#
# Note: The EDK II DSC file is not used to specify how compiled binary images get placed
# into firmware volume images. This section is just a list of modules to compile from
# source into UEFI-compliant binaries.
# It is the FDF file that contains information on combining binary files into firmware
# volume images, whose concept is beyond UEFI and is described in PI specification.
# Binary modules do not need to be listed in this section, as they should be
# specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),
# Logo (Logo.bmp), and etc.
# There may also be modules listed in this section that are not required in the FDF file,
# When a module listed here is excluded from FDF file, then UEFI-compliant binary will be
# generated for it, but the binary will not be put into any firmware volume.
#
###################################################################################################
[Components]
DuetPkg/DxeIpl/DxeIpl.inf {
<LibraryClasses>
#
# If no following overriden for ReportStatusCodeLib library class,
# All other module can *not* output debug information even they are use not NULL library
# instance for DebugLib and ReportStatusCodeLib
#
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
}
MdeModulePkg/Core/Dxe/DxeMain.inf {
#
# Enable debug output for DxeCore module, this is a sample for how to enable debug output
# for a module. If need turn on debug output for other module, please copy following overriden
# PCD and library instance to other module's override section.
#
<PcdsFixedAtBuild>
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000042
<LibraryClasses>
DebugLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
ReportStatusCodeLib|DuetPkg/Library/DxeCoreReportStatusCodeLibFromHob/DxeCoreReportStatusCodeLibFromHob.inf
}
MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
DuetPkg/FSVariable/FSVariable.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
}
MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
DuetPkg/SmbiosGenDxe/SmbiosGen.inf
#DuetPkg/FvbRuntimeService/DUETFwh.inf
DuetPkg/EfiLdr/EfiLdr.inf {
<LibraryClasses>
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
}
IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
}
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf
UefiCpuPkg/CpuDxe/CpuDxe.inf
PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf
DuetPkg/AcpiResetDxe/Reset.inf
DuetPkg/LegacyMetronome/Metronome.inf
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
DuetPkg/PciRootBridgeNoEnumerationDxe/PciRootBridgeNoEnumeration.inf
DuetPkg/PciBusNoEnumerationDxe/PciBusNoEnumeration.inf
IntelFrameworkModulePkg/Bus/Pci/VgaMiniPortDxe/VgaMiniPortDxe.inf
IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClassDxe.inf
# IDE/AHCI Support
DuetPkg/SataControllerDxe/SataControllerDxe.inf
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf
MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf
MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
# Usb Support
MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
# ISA Support
PcAtChipsetPkg/IsaAcpiDxe/IsaAcpi.inf
IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBusDxe.inf
IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/IsaSerialDxe.inf
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboardDxe.inf
IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppyDxe.inf
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
FatPkg/EnhancedFatDxe/Fat.inf
# Bios Thunk
DuetPkg/BiosVideoThunkDxe/BiosVideo.inf
#
# Sample Application
#
MdeModulePkg/Application/HelloWorld/HelloWorld.inf
###################################################################################################
#
# BuildOptions Section - Define the module specific tool chain flags that should be used as
# the default flags for a module. These flags are appended to any
# standard flags that are defined by the build process. They can be
# applied for any modules or only those modules with the specific
# module style (EDK or EDKII) specified in [Components] section.
#
###################################################################################################
[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /FAsc /FR$(@R).SBR

View File

@@ -1,284 +0,0 @@
## @file
# An EFI/Framework Emulation Platform with UEFI HII interface supported.
#
# Developer's UEFI Emulation. DUET provides an EFI/UEFI IA32/X64 environment on legacy BIOS,
# to help developing and debugging native EFI/UEFI drivers.
#
# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
################################################################################
#
# Defines Section - statements that will be processed to create a Makefile.
#
################################################################################
[Defines]
PLATFORM_NAME = DuetPkg
PLATFORM_GUID = 199E24E0-0989-42aa-87F2-611A8C397E72
PLATFORM_VERSION = 0.4
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/DuetPkgX64
SUPPORTED_ARCHITECTURES = X64
BUILD_TARGETS = DEBUG
SKUID_IDENTIFIER = DEFAULT
FLASH_DEFINITION = DuetPkg/DuetPkg.fdf
!if $(TOOL_CHAIN_TAG) == GCC47 || $(TOOL_CHAIN_TAG) == GCC48 || $(TOOL_CHAIN_TAG) == GCC49 || $(TOOL_CHAIN_TAG) == GCC5
POSTBUILD = DuetPkg/PostBuild.sh
!else
POSTBUILD = DuetPkg/PostBuild.bat
!endif
################################################################################
#
# Library Class section - list of all Library Classes needed by this Platform.
#
################################################################################
[LibraryClasses]
#
# Entry point
#
PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
#
# Basic
#
BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
#
# UEFI & PI
#
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
#
# Generic Modules
#
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
#
# Platform
#
PlatformBdsLib|DuetPkg/Library/DuetBdsLib/PlatformBds.inf
TimerLib|DuetPkg/Library/DuetTimerLib/DuetTimerLib.inf
#
# Misc
#
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf
LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
#
# To save size, use NULL library for DebugLib and ReportStatusCodeLib.
# If need status code output, do library instance overriden as below DxeMain.inf does
#
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
[LibraryClasses.common.DXE_CORE]
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
################################################################################
#
# Pcd Section - list of all EDK II PCD Entries defined by this Platform
#
################################################################################
[PcdsFixedAtBuild]
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x0
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x0
gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
[PcdsFeatureFlag]
gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE
###################################################################################################
#
# Components Section - list of the modules and components that will be processed by compilation
# tools and the EDK II tools to generate PE32/PE32+/Coff image files.
#
# Note: The EDK II DSC file is not used to specify how compiled binary images get placed
# into firmware volume images. This section is just a list of modules to compile from
# source into UEFI-compliant binaries.
# It is the FDF file that contains information on combining binary files into firmware
# volume images, whose concept is beyond UEFI and is described in PI specification.
# Binary modules do not need to be listed in this section, as they should be
# specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),
# Logo (Logo.bmp), and etc.
# There may also be modules listed in this section that are not required in the FDF file,
# When a module listed here is excluded from FDF file, then UEFI-compliant binary will be
# generated for it, but the binary will not be put into any firmware volume.
#
###################################################################################################
[Components]
DuetPkg/DxeIpl/DxeIpl.inf {
<LibraryClasses>
#
# If no following overriden for ReportStatusCodeLib library class,
# All other module can *not* output debug information even they are use not NULL library
# instance for DebugLib and ReportStatusCodeLib
#
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
}
MdeModulePkg/Core/Dxe/DxeMain.inf {
#
# Enable debug output for DxeCore module, this is a sample for how to enable debug output
# for a module. If need turn on debug output for other module, please copy following overriden
# PCD and library instance to other module's override section.
#
<PcdsFixedAtBuild>
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000042
<LibraryClasses>
DebugLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
ReportStatusCodeLib|DuetPkg/Library/DxeCoreReportStatusCodeLibFromHob/DxeCoreReportStatusCodeLibFromHob.inf
}
MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
DuetPkg/FSVariable/FSVariable.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
}
MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
DuetPkg/SmbiosGenDxe/SmbiosGen.inf
#DuetPkg/FvbRuntimeService/DUETFwh.inf
DuetPkg/EfiLdr/EfiLdr.inf {
<LibraryClasses>
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
}
IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
}
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf
UefiCpuPkg/CpuDxe/CpuDxe.inf
PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf
DuetPkg/AcpiResetDxe/Reset.inf
DuetPkg/LegacyMetronome/Metronome.inf
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
DuetPkg/PciRootBridgeNoEnumerationDxe/PciRootBridgeNoEnumeration.inf
DuetPkg/PciBusNoEnumerationDxe/PciBusNoEnumeration.inf
IntelFrameworkModulePkg/Bus/Pci/VgaMiniPortDxe/VgaMiniPortDxe.inf
IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClassDxe.inf
# IDE/AHCI Support
DuetPkg/SataControllerDxe/SataControllerDxe.inf
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf
MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf
MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
# Usb Support
MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
# ISA Support
PcAtChipsetPkg/IsaAcpiDxe/IsaAcpi.inf
IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBusDxe.inf
IntelFrameworkModulePkg/Bus/Isa/IsaSerialDxe/IsaSerialDxe.inf
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboardDxe.inf
IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppyDxe.inf
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
FatPkg/EnhancedFatDxe/Fat.inf
# Bios Thunk
DuetPkg/BiosVideoThunkDxe/BiosVideo.inf
#
# Sample Application
#
MdeModulePkg/Application/HelloWorld/HelloWorld.inf
###################################################################################################
#
# BuildOptions Section - Define the module specific tool chain flags that should be used as
# the default flags for a module. These flags are appended to any
# standard flags that are defined by the build process. They can be
# applied for any modules or only those modules with the specific
# module style (EDK or EDKII) specified in [Components] section.
#
###################################################################################################
[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /FAsc /FR$(@R).SBR

View File

@@ -1,83 +0,0 @@
/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Debug.c
Abstract:
Revision History:
**/
#include "DxeIpl.h"
#include <Library/SerialPortLib.h>
#include "SerialStatusCode.h"
#include "Debug.h"
UINT8 *mCursor;
UINT8 mHeaderIndex = 10;
VOID
PrintHeader (
CHAR8 Char
)
{
*(UINT8 *)(UINTN)(0x000b8000 + mHeaderIndex) = Char;
mHeaderIndex += 2;
}
VOID
ClearScreen (
VOID
)
{
UINT32 Index;
mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160);
for (Index = 0; Index < 80 * 49; Index++) {
*mCursor = ' ';
mCursor += 2;
}
mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160);
}
VOID
EFIAPI
PrintString (
IN CONST CHAR8 *FormatString,
...
)
{
UINTN Index;
CHAR8 PrintBuffer[1000];
VA_LIST Marker;
VA_START (Marker, FormatString);
AsciiVSPrint (PrintBuffer, sizeof (PrintBuffer), FormatString, Marker);
VA_END (Marker);
for (Index = 0; PrintBuffer[Index] != 0; Index++) {
if (PrintBuffer[Index] == '\n') {
mCursor = (UINT8 *) (UINTN) (0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160));
} else {
*mCursor = (UINT8) PrintBuffer[Index];
mCursor += 2;
}
}
//
// All information also output to serial port.
//
SerialPortWrite ((UINT8 *) PrintBuffer, Index);
}

View File

@@ -1,41 +0,0 @@
/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Debug.h
Abstract:
Revision History:
**/
#ifndef _EFILDR_DEBUG_H_
#define _EFILDR_DEBUG_H_
VOID
PrintHeader (
CHAR8 Char
);
VOID
EFIAPI
PrintString (
IN CONST CHAR8 *FormatString,
...
);
VOID
ClearScreen (
VOID
);
#endif

View File

@@ -1,278 +0,0 @@
/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DxeInit.c
Abstract:
Revision History:
**/
#include "DxeIpl.h"
#include "LegacyTable.h"
#include "HobGeneration.h"
#include "PpisNeededByDxeCore.h"
#include "Debug.h"
/*
--------------------------------------------------------
Memory Map: (XX=32,64)
--------------------------------------------------------
0x0
IVT
0x400
BDA
0x500
0x7C00
BootSector
0x10000
EfiLdr (relocate by efiXX.COM)
0x15000
Efivar.bin (Load by StartXX.COM)
0x20000
StartXX.COM (E820 table, Temporary GDT, Temporary IDT)
0x21000
EfiXX.COM (Temporary Interrupt Handler)
0x22000
EfiLdr.efi + DxeIpl.Z + DxeMain.Z + BFV.Z
0x86000
MemoryFreeUnder1M (For legacy driver DMA)
0x90000
Temporary 4G PageTable for X64 (6 page)
0x9F800
EBDA
0xA0000
VGA
0xC0000
OPROM
0xE0000
FIRMEWARE
0x100000 (1M)
Temporary Stack (1M)
0x200000
MemoryAbove1MB.PhysicalStart <-----------------------------------------------------+
... |
... |
<- Phit.EfiMemoryBottom -------------------+ |
HOB | |
<- Phit.EfiFreeMemoryBottom | |
| MemoryFreeAbove1MB.ResourceLength
<- Phit.EfiFreeMemoryTop ------+ | |
MemoryDescriptor (For ACPINVS, ACPIReclaim) | 4M = CONSUMED_MEMORY |
| | |
Permament 4G PageTable for IA32 or MemoryAllocation | |
Permament 64G PageTable for X64 | | |
<------------------------------+ | |
Permament Stack (0x20 Pages = 128K) | |
<- Phit.EfiMemoryTop ----------+-----------+---------------+
NvFV (64K) |
MMIO
FtwFV (128K) |
<----------------------------------------------------------+<---------+
DxeCore | |
DxeCore |
DxeIpl | Allocated in EfiLdr
<----------------------------------------------------------+ |
BFV MMIO |
<- Top of Free Memory reported by E820 --------------------+<---------+
ACPINVS or
ACPIReclaim or
Reserved
<- Memory Top on RealMemory
0x100000000 (4G)
MemoryFreeAbove4G.Physicalstart <--------------------------------------------------+
|
|
MemoryFreeAbove4GB.ResourceLength
|
|
<--------------------------------------------------+
*/
VOID
EnterDxeMain (
IN VOID *StackTop,
IN VOID *DxeCoreEntryPoint,
IN VOID *Hob,
IN VOID *PageTable
);
VOID
DxeInit (
IN EFILDRHANDOFF *Handoff
)
/*++
Routine Description:
This is the entry point after this code has been loaded into memory.
Arguments:
Returns:
Calls into EFI Firmware
--*/
{
VOID *StackTop;
VOID *StackBottom;
VOID *PageTableBase;
VOID *MemoryTopOnDescriptor;
VOID *MemoryDescriptor;
VOID *NvStorageBase;
EFILDRHANDOFF HandoffCopy;
CopyMem ((VOID*) &HandoffCopy, (VOID*) Handoff, sizeof (EFILDRHANDOFF));
Handoff = &HandoffCopy;
ClearScreen();
PrintString (
"Enter DxeIpl ...\n"
"Handoff:\n"
"Handoff.BfvBase = %p, BfvLength = %x\n"
"Handoff.DxeIplImageBase = %p, DxeIplImageSize = %x\n"
"Handoff.DxeCoreImageBase = %p, DxeCoreImageSize = %x\n",
Handoff->BfvBase, Handoff->BfvSize,
Handoff->DxeIplImageBase, Handoff->DxeIplImageSize,
Handoff->DxeCoreImageBase, Handoff->DxeCoreImageSize
);
//
// Hob Generation Guild line:
// * Don't report FV as physical memory
// * MemoryAllocation Hob should only cover physical memory
// * Use ResourceDescriptor Hob to report physical memory or Firmware Device and they shouldn't be overlapped
PrintString ("Prepare Cpu HOB information ...\n");
PrepareHobCpu ();
//
// 1. BFV
//
PrintString ("Prepare BFV HOB information ...\n");
PrepareHobBfv (Handoff->BfvBase, Handoff->BfvSize);
//
// 2. Updates Memory information, and get the top free address under 4GB
//
PrintString ("Prepare Memory HOB information ...\n");
MemoryTopOnDescriptor = PrepareHobMemory (Handoff->MemDescCount, Handoff->MemDesc);
//
// 3. Put [NV], [Stack], [PageTable], [MemDesc], [HOB] just below the [top free address under 4GB]
//
// 3.1 NV data
PrintString ("Prepare NV Storage information ...\n");
NvStorageBase = PrepareHobNvStorage (MemoryTopOnDescriptor);
PrintString ("NV Storage Base = %p\n", NvStorageBase);
// 3.2 Stack
StackTop = NvStorageBase;
StackBottom = PrepareHobStack (StackTop);
PrintString ("Stack Top=0x%x, Stack Bottom=0x%x\n", StackTop, StackBottom);
// 3.3 Page Table
PageTableBase = PreparePageTable (StackBottom, gHob->Cpu.SizeOfMemorySpace);
// 3.4 MemDesc (will be used in PlatformBds)
MemoryDescriptor = PrepareHobMemoryDescriptor (PageTableBase, Handoff->MemDescCount, Handoff->MemDesc);
// 3.5 Copy the Hob itself to EfiMemoryBottom, and update the PHIT Hob
PrepareHobPhit (StackTop, MemoryDescriptor);
//
// 4. Register the memory occupied by DxeCore and DxeIpl together as DxeCore
//
PrintString ("Prepare DxeCore memory Hob ...\n");
PrepareHobDxeCore (
Handoff->DxeCoreEntryPoint,
(EFI_PHYSICAL_ADDRESS)(UINTN)Handoff->DxeCoreImageBase,
(UINTN)Handoff->DxeIplImageBase + (UINTN)Handoff->DxeIplImageSize - (UINTN)Handoff->DxeCoreImageBase
);
PrepareHobLegacyTable (gHob);
PreparePpisNeededByDxeCore (gHob);
CompleteHobGeneration ();
//
// Print Hob Info
//
ClearScreen();
PrintString (
"HobStart = %p\n"
"Memory Top = %lx, Bottom = %lx\n"
"Free Memory Top = %lx, Bottom = %lx\n"
"NvStorageFvb = %lx, Length = %lx\n"
"BfvResource = %lx, Length = %lx\n"
"NvStorageFvResource = %lx, Length = %lx\n"
"NvStorage = %lx, Length = %lx\n"
"NvFtwFvResource = %lx, Length = %lx\n"
"NvFtwWorking = %lx, Length = %lx\n"
"NvFtwSpare = %lx, Length = %lx\n"
"Stack = %lx, StackLength = %lx\n"
"PageTable = %p\n"
"MemoryFreeUnder1MB = %lx, MemoryFreeUnder1MBLength = %lx\n"
"MemoryAbove1MB = %lx, MemoryAbove1MBLength = %lx\n"
"MemoryAbove4GB = %lx, MemoryAbove4GBLength = %lx\n"
"DxeCore = %lx, DxeCoreLength = %lx\n"
"MemoryAllocation = %lx, MemoryLength = %lx\n"
"$",
gHob,
gHob->Phit.EfiMemoryTop, gHob->Phit.EfiMemoryBottom,
gHob->Phit.EfiFreeMemoryTop, gHob->Phit.EfiFreeMemoryBottom,
gHob->NvStorageFvb.FvbInfo.Entries[0].Base, gHob->NvFtwFvb.FvbInfo.Entries[0].Length,
gHob->BfvResource.PhysicalStart, gHob->BfvResource.ResourceLength,
gHob->NvStorageFvResource.PhysicalStart, gHob->NvStorageFvResource.ResourceLength,
gHob->NvStorage.FvbInfo.Entries[0].Base, gHob->NvStorage.FvbInfo.Entries[0].Length,
gHob->NvFtwFvResource.PhysicalStart, gHob->NvFtwFvResource.ResourceLength,
gHob->NvFtwWorking.FvbInfo.Entries[0].Base, gHob->NvFtwWorking.FvbInfo.Entries[0].Length,
gHob->NvFtwSpare.FvbInfo.Entries[0].Base, gHob->NvFtwSpare.FvbInfo.Entries[0].Length,
gHob->Stack.AllocDescriptor.MemoryBaseAddress, gHob->Stack.AllocDescriptor.MemoryLength,
PageTableBase,
gHob->MemoryFreeUnder1MB.PhysicalStart, gHob->MemoryFreeUnder1MB.ResourceLength,
gHob->MemoryAbove1MB.PhysicalStart, gHob->MemoryAbove1MB.ResourceLength,
gHob->MemoryAbove4GB.PhysicalStart, gHob->MemoryAbove4GB.ResourceLength,
gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress, gHob->DxeCore.MemoryAllocationHeader.MemoryLength,
gHob->MemoryAllocation.AllocDescriptor.MemoryBaseAddress, gHob->MemoryAllocation.AllocDescriptor.MemoryLength
);
ClearScreen();
PrintString (
"\n\n\n\n\n\n\n\n\n\n"
" WELCOME TO EFI WORLD!\n"
);
EnterDxeMain (StackTop, Handoff->DxeCoreEntryPoint, gHob, PageTableBase);
PrintString ("Fail to enter DXE main!\n");
//
// Should never get here
//
CpuDeadLoop ();
}
EFI_STATUS
EFIAPI
_ModuleEntryPoint (
IN EFILDRHANDOFF *Handoff
)
{
DxeInit(Handoff);
return EFI_SUCCESS;
}

View File

@@ -1,49 +0,0 @@
/** @file
Internal header file for DxeIpl module.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _DUET_DXEIPL_H_
#define _DUET_DXEIPL_H_
#include <FrameworkPei.h>
#include "EfiLdrHandoff.h"
#include "EfiFlashMap.h"
#include <Guid/MemoryTypeInformation.h>
#include <Guid/PciExpressBaseAddress.h>
#include <Guid/AcpiDescription.h>
#include <Guid/MemoryAllocationHob.h>
#include <Guid/Acpi.h>
#include <Guid/SmBios.h>
#include <Guid/Mps.h>
#include <Guid/FlashMapHob.h>
#include <Guid/SystemNvDataGuid.h>
#include <Guid/VariableFormat.h>
#include <Guid/StatusCodeDataTypeDebug.h>
#include <Guid/DxeCoreFileName.h>
#include <Guid/LdrMemoryDescriptor.h>
#include <Protocol/Decompress.h>
#include <Protocol/StatusCode.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/PrintLib.h>
#include <Library/IoLib.h>
#endif // _DUET_DXEIPL_H_

View File

@@ -1,70 +0,0 @@
## @file
#
# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
# DxeIpl.inf
#
# Abstract:
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeIpl
FILE_GUID = 2119BBD7-9432-4f47-B5E2-5C4EA31B6BDC
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
[Packages]
MdePkg/MdePkg.dec
DuetPkg/DuetPkg.dec
MdeModulePkg/MdeModulePkg.dec
IntelFrameworkPkg/IntelFrameworkPkg.dec
[LibraryClasses]
BaseLib
BaseMemoryLib
PrintLib
SerialPortLib
ReportStatusCodeLib
IoLib
[Guids]
gEfiVariableGuid
gDxeCoreFileNameGuid
gLdrMemoryDescriptorGuid
[Sources]
DxeIpl.h
DxeInit.c
LegacyTable.c
LegacyTable.h
PpisNeededByDxeCore.c
PpisNeededByDxeCore.h
HobGeneration.c
HobGeneration.h
SerialStatusCode.c
SerialStatusCode.h
Debug.c
Debug.h
[Sources.x64]
X64/EnterDxeCore.c
X64/Paging.c
X64/VirtualMemory.h
[Sources.Ia32]
Ia32/EnterDxeCore.c
Ia32/Paging.c
Ia32/VirtualMemory.h
[Depex]
TRUE

File diff suppressed because it is too large Load Diff

View File

@@ -1,171 +0,0 @@
/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
HobGeneration.h
Abstract:
Revision History:
**/
#ifndef _DXELDR_HOB_GENERATION_H_
#define _DXELDR_HOB_GENERATION_H_
#include "DxeIpl.h"
#define EFI_MEMORY_BELOW_1MB_START 0x86000
#define EFI_MEMORY_BELOW_1MB_END 0x9F800
#define EFI_MEMORY_STACK_PAGE_NUM 0x20
#define CONSUMED_MEMORY 0x100000 * 80
#define NV_STORAGE_START 0x15000
#define NV_STORAGE_STATE 0x19000
#pragma pack(1)
typedef struct {
EFI_HOB_GUID_TYPE Hob;
EFI_MEMORY_TYPE_INFORMATION Info[10];
} MEMORY_TYPE_INFORMATION_HOB;
typedef struct {
EFI_HOB_GUID_TYPE Hob;
EFI_PHYSICAL_ADDRESS Table;
} TABLE_HOB;
typedef struct {
EFI_HOB_GUID_TYPE Hob;
EFI_PHYSICAL_ADDRESS Interface;
} PROTOCOL_HOB;
typedef struct {
EFI_HOB_GUID_TYPE Hob;
// Note: we get only one PCI Segment now.
EFI_PCI_EXPRESS_BASE_ADDRESS_INFORMATION PciExpressBaseAddressInfo;
} PCI_EXPRESS_BASE_HOB;
typedef struct {
EFI_HOB_GUID_TYPE Hob;
EFI_ACPI_DESCRIPTION AcpiDescription;
} ACPI_DESCRIPTION_HOB;
typedef struct {
EFI_HOB_GUID_TYPE Hob;
EFI_FLASH_MAP_FS_ENTRY_DATA FvbInfo;
} FVB_HOB;
typedef struct {
EFI_HOB_HANDOFF_INFO_TABLE Phit;
EFI_HOB_FIRMWARE_VOLUME Bfv;
EFI_HOB_RESOURCE_DESCRIPTOR BfvResource;
EFI_HOB_CPU Cpu;
EFI_HOB_MEMORY_ALLOCATION_STACK Stack;
EFI_HOB_MEMORY_ALLOCATION MemoryAllocation;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryFreeUnder1MB;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove1MB;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove4GB;
EFI_HOB_MEMORY_ALLOCATION_MODULE DxeCore;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryDxeCore;
MEMORY_TYPE_INFORMATION_HOB MemoryTypeInfo;
TABLE_HOB Acpi;
TABLE_HOB Acpi20;
TABLE_HOB Smbios;
TABLE_HOB Mps;
/**
PROTOCOL_HOB FlushInstructionCache;
PROTOCOL_HOB TransferControl;
PROTOCOL_HOB PeCoffLoader;
PROTOCOL_HOB EfiDecompress;
PROTOCOL_HOB TianoDecompress;
**/
PROTOCOL_HOB SerialStatusCode;
MEMORY_DESC_HOB MemoryDescriptor;
PCI_EXPRESS_BASE_HOB PciExpress;
ACPI_DESCRIPTION_HOB AcpiInfo;
EFI_HOB_RESOURCE_DESCRIPTOR NvStorageFvResource;
FVB_HOB NvStorageFvb;
FVB_HOB NvStorage;
EFI_HOB_RESOURCE_DESCRIPTOR NvFtwFvResource;
FVB_HOB NvFtwFvb;
FVB_HOB NvFtwWorking;
FVB_HOB NvFtwSpare;
EFI_HOB_GENERIC_HEADER EndOfHobList;
} HOB_TEMPLATE;
#pragma pack()
extern HOB_TEMPLATE *gHob;
VOID *
PrepareHobStack (
IN VOID *StackTop
);
VOID
PrepareHobBfv (
VOID *Bfv,
UINTN BfvLength
);
VOID *
PrepareHobMemory (
IN UINTN NumberOfMemoryMapEntries,
IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
);
VOID
PrepareHobDxeCore (
VOID *DxeCoreEntryPoint,
EFI_PHYSICAL_ADDRESS DxeCoreImageBase,
UINT64 DxeCoreLength
);
VOID *
PreparePageTable (
VOID *PageNumberTop,
UINT8 SizeOfMemorySpace
);
VOID *
PrepareHobMemoryDescriptor (
VOID *MemoryDescriptorTop,
UINTN MemDescCount,
EFI_MEMORY_DESCRIPTOR *MemDesc
);
VOID
PrepareHobPhit (
VOID *MemoryTop,
VOID *FreeMemoryTop
);
VOID *
PrepareHobNvStorage (
VOID *NvStorageTop
);
VOID
PrepareHobCpu (
VOID
);
VOID
CompleteHobGeneration (
VOID
);
#endif

View File

@@ -1,31 +0,0 @@
/** @file
IA32 specific code to enter DxeCore
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "DxeIpl.h"
VOID
EnterDxeMain (
IN VOID *StackTop,
IN VOID *DxeCoreEntryPoint,
IN VOID *Hob,
IN VOID *PageTable
)
{
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
Hob,
NULL,
StackTop
);
}

View File

@@ -1,172 +0,0 @@
/** @file
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Paging.c
Abstract:
Revision History:
**/
#include "DxeIpl.h"
#include "HobGeneration.h"
#include "VirtualMemory.h"
#include "Debug.h"
#define EFI_PAGE_SIZE_4K 0x1000
#define EFI_PAGE_SIZE_4M 0x400000
//
// Create 4G 4M-page table
// PDE (31:22) : 1024 entries
//
#define EFI_MAX_ENTRY_NUM 1024
#define EFI_PDE_ENTRY_NUM EFI_MAX_ENTRY_NUM
#define EFI_PDE_PAGE_NUM 1
#define EFI_PAGE_NUMBER_4M (EFI_PDE_PAGE_NUM)
//
// Create 4M 4K-page table
// PTE (21:12) : 1024 entries
//
#define EFI_PTE_ENTRY_NUM EFI_MAX_ENTRY_NUM
#define EFI_PTE_PAGE_NUM 1
#define EFI_PAGE_NUMBER_4K (EFI_PTE_PAGE_NUM)
#define EFI_PAGE_NUMBER (EFI_PAGE_NUMBER_4M + EFI_PAGE_NUMBER_4K)
VOID
EnableNullPointerProtection (
UINT8 *PageTable
)
{
IA32_PAGE_TABLE_ENTRY_4K *PageTableEntry4KB;
PageTableEntry4KB = (IA32_PAGE_TABLE_ENTRY_4K *)((UINTN)PageTable + EFI_PAGE_NUMBER_4M * EFI_PAGE_SIZE_4K);
//
// Fill in the Page Table entries
// Mark 0~4K as not present
//
PageTableEntry4KB->Bits.Present = 0;
return ;
}
VOID
Ia32Create4KPageTables (
UINT8 *PageTable
)
{
UINT64 PageAddress;
UINTN PTEIndex;
IA32_PAGE_DIRECTORY_ENTRY_4K *PageDirectoryEntry4KB;
IA32_PAGE_TABLE_ENTRY_4K *PageTableEntry4KB;
PageAddress = 0;
//
// Page Table structure 2 level 4K.
//
// Page Table 4K : PageDirectoryEntry4K : bits 31-22
// PageTableEntry : bits 21-12
//
PageTableEntry4KB = (IA32_PAGE_TABLE_ENTRY_4K *)((UINTN)PageTable + EFI_PAGE_NUMBER_4M * EFI_PAGE_SIZE_4K);
PageDirectoryEntry4KB = (IA32_PAGE_DIRECTORY_ENTRY_4K *)((UINTN)PageTable);
PageDirectoryEntry4KB->Uint32 = (UINT32)(UINTN)PageTableEntry4KB;
PageDirectoryEntry4KB->Bits.ReadWrite = 0;
PageDirectoryEntry4KB->Bits.Present = 1;
PageDirectoryEntry4KB->Bits.MustBeZero = 1;
for (PTEIndex = 0; PTEIndex < EFI_PTE_ENTRY_NUM; PTEIndex++, PageTableEntry4KB++) {
//
// Fill in the Page Table entries
//
PageTableEntry4KB->Uint32 = (UINT32)PageAddress;
PageTableEntry4KB->Bits.ReadWrite = 1;
PageTableEntry4KB->Bits.Present = 1;
PageAddress += EFI_PAGE_SIZE_4K;
}
return ;
}
VOID
Ia32Create4MPageTables (
UINT8 *PageTable
)
{
UINT32 PageAddress;
UINT8 *TempPageTable;
UINTN PDEIndex;
IA32_PAGE_TABLE_ENTRY_4M *PageDirectoryEntry4MB;
TempPageTable = PageTable;
PageAddress = 0;
//
// Page Table structure 1 level 4MB.
//
// Page Table 4MB : PageDirectoryEntry4M : bits 31-22
//
PageDirectoryEntry4MB = (IA32_PAGE_TABLE_ENTRY_4M *)TempPageTable;
for (PDEIndex = 0; PDEIndex < EFI_PDE_ENTRY_NUM; PDEIndex++, PageDirectoryEntry4MB++) {
//
// Fill in the Page Directory entries
//
PageDirectoryEntry4MB->Uint32 = (UINT32)PageAddress;
PageDirectoryEntry4MB->Bits.ReadWrite = 1;
PageDirectoryEntry4MB->Bits.Present = 1;
PageDirectoryEntry4MB->Bits.MustBe1 = 1;
PageAddress += EFI_PAGE_SIZE_4M;
}
return ;
}
VOID *
PreparePageTable (
VOID *PageNumberTop,
UINT8 SizeOfMemorySpace
)
/*++
Description:
Generate pagetable below PageNumberTop,
and return the bottom address of pagetable for putting other things later.
--*/
{
VOID *PageNumberBase;
PageNumberBase = (VOID *)((UINTN)PageNumberTop - EFI_PAGE_NUMBER * EFI_PAGE_SIZE_4K);
ZeroMem (PageNumberBase, EFI_PAGE_NUMBER * EFI_PAGE_SIZE_4K);
Ia32Create4MPageTables (PageNumberBase);
Ia32Create4KPageTables (PageNumberBase);
//
// Not enable NULL Pointer Protection if using INTX call
//
// EnableNullPointerProtection (PageNumberBase);
return PageNumberBase;
}

View File

@@ -1,88 +0,0 @@
/** @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
VirtualMemory.h
Abstract:
Revision History:
**/
#ifndef _VIRTUAL_MEMORY_H_
#define _VIRTUAL_MEMORY_H_
#pragma pack(1)
//
// Page Directory Entry 4K
//
typedef union {
struct {
UINT32 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT32 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT32 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT32 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT32 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT32 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT32 MustBeZero:3; // Must Be Zero
UINT32 Available:3; // Available for use by system software
UINT32 PageTableBaseAddress:20; // Page Table Base Address
} Bits;
UINT32 Uint32;
} IA32_PAGE_DIRECTORY_ENTRY_4K;
//
// Page Table Entry 4K
//
typedef union {
struct {
UINT32 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT32 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT32 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT32 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT32 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT32 Accessed:1; // 0 = Not accessed (cleared by software), 1 = Accessed (set by CPU)
UINT32 Dirty:1; // 0 = Not written to (cleared by software), 1 = Written to (set by CPU)
UINT32 PAT:1; // 0 = Disable PAT, 1 = Enable PAT
UINT32 Global:1; // Ignored
UINT32 Available:3; // Available for use by system software
UINT32 PageTableBaseAddress:20; // Page Table Base Address
} Bits;
UINT32 Uint32;
} IA32_PAGE_TABLE_ENTRY_4K;
//
// Page Table Entry 4M
//
typedef union {
struct {
UINT32 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT32 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT32 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT32 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT32 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT32 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT32 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT32 MustBe1:1; // Must be 1
UINT32 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT32 Available:3; // Available for use by system software
UINT32 PAT:1; //
UINT32 MustBeZero:9; // Must be zero;
UINT32 PageTableBaseAddress:10; // Page Table Base Address
} Bits;
UINT32 Uint32;
} IA32_PAGE_TABLE_ENTRY_4M;
#pragma pack()
#endif

View File

@@ -1,357 +0,0 @@
/** @file
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
LegacyTable.c
Abstract:
Revision History:
**/
#include "DxeIpl.h"
#include "HobGeneration.h"
#include "Debug.h"
#define MPS_PTR SIGNATURE_32('_','M','P','_')
#define SMBIOS_PTR SIGNATURE_32('_','S','M','_')
#define EBDA_BASE_ADDRESS 0x40E
VOID *
FindAcpiRsdPtr (
VOID
)
{
UINTN Address;
UINTN Index;
//
// First Seach 0x0e0000 - 0x0fffff for RSD Ptr
//
for (Address = 0xe0000; Address < 0xfffff; Address += 0x10) {
if (*(UINT64 *)(Address) == EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE) {
return (VOID *)Address;
}
}
//
// Search EBDA
//
Address = (*(UINT16 *)(UINTN)(EBDA_BASE_ADDRESS)) << 4;
for (Index = 0; Index < 0x400 ; Index += 16) {
if (*(UINT64 *)(Address + Index) == EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE) {
return (VOID *)Address;
}
}
return NULL;
}
VOID *
FindSMBIOSPtr (
VOID
)
{
UINTN Address;
//
// First Seach 0x0f0000 - 0x0fffff for SMBIOS Ptr
//
for (Address = 0xf0000; Address < 0xfffff; Address += 0x10) {
if (*(UINT32 *)(Address) == SMBIOS_PTR) {
return (VOID *)Address;
}
}
return NULL;
}
VOID *
FindMPSPtr (
VOID
)
{
UINTN Address;
UINTN Index;
//
// First Seach 0x0e0000 - 0x0fffff for MPS Ptr
//
for (Address = 0xe0000; Address < 0xfffff; Address += 0x10) {
if (*(UINT32 *)(Address) == MPS_PTR) {
return (VOID *)Address;
}
}
//
// Search EBDA
//
Address = (*(UINT16 *)(UINTN)(EBDA_BASE_ADDRESS)) << 4;
for (Index = 0; Index < 0x400 ; Index += 16) {
if (*(UINT32 *)(Address + Index) == MPS_PTR) {
return (VOID *)Address;
}
}
return NULL;
}
#pragma pack(1)
typedef struct {
EFI_ACPI_DESCRIPTION_HEADER Header;
UINT32 Entry;
} RSDT_TABLE;
typedef struct {
EFI_ACPI_DESCRIPTION_HEADER Header;
UINT64 Entry;
} XSDT_TABLE;
#pragma pack()
VOID
ScanTableInRSDT (
RSDT_TABLE *Rsdt,
UINT32 Signature,
EFI_ACPI_DESCRIPTION_HEADER **FoundTable
)
{
UINTN Index;
UINT32 EntryCount;
UINT32 *EntryPtr;
EFI_ACPI_DESCRIPTION_HEADER *Table;
*FoundTable = NULL;
EntryCount = (Rsdt->Header.Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT32);
EntryPtr = &Rsdt->Entry;
for (Index = 0; Index < EntryCount; Index ++, EntryPtr ++) {
Table = (EFI_ACPI_DESCRIPTION_HEADER*)((UINTN)(*EntryPtr));
if (Table->Signature == Signature) {
*FoundTable = Table;
break;
}
}
return;
}
VOID
ScanTableInXSDT (
XSDT_TABLE *Xsdt,
UINT32 Signature,
EFI_ACPI_DESCRIPTION_HEADER **FoundTable
)
{
UINTN Index;
UINT32 EntryCount;
UINT64 EntryPtr;
UINTN BasePtr;
EFI_ACPI_DESCRIPTION_HEADER *Table;
*FoundTable = NULL;
EntryCount = (Xsdt->Header.Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT64);
BasePtr = (UINTN)(&(Xsdt->Entry));
for (Index = 0; Index < EntryCount; Index ++) {
CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * sizeof(UINT64)), sizeof(UINT64));
Table = (EFI_ACPI_DESCRIPTION_HEADER*)((UINTN)(EntryPtr));
if (Table->Signature == Signature) {
*FoundTable = Table;
break;
}
}
return;
}
VOID *
FindAcpiPtr (
IN HOB_TEMPLATE *Hob,
UINT32 Signature
)
{
EFI_ACPI_DESCRIPTION_HEADER *AcpiTable;
EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
RSDT_TABLE *Rsdt;
XSDT_TABLE *Xsdt;
AcpiTable = NULL;
//
// Check ACPI2.0 table
//
if ((int)Hob->Acpi20.Table != -1) {
Rsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)(UINTN)Hob->Acpi20.Table;
Rsdt = (RSDT_TABLE *)(UINTN)Rsdp->RsdtAddress;
Xsdt = NULL;
if ((Rsdp->Revision >= 2) && (Rsdp->XsdtAddress < (UINT64)(UINTN)-1)) {
Xsdt = (XSDT_TABLE *)(UINTN)Rsdp->XsdtAddress;
}
//
// Check Xsdt
//
if (Xsdt != NULL) {
ScanTableInXSDT (Xsdt, Signature, &AcpiTable);
}
//
// Check Rsdt
//
if ((AcpiTable == NULL) && (Rsdt != NULL)) {
ScanTableInRSDT (Rsdt, Signature, &AcpiTable);
}
}
//
// Check ACPI1.0 table
//
if ((AcpiTable == NULL) && ((int)Hob->Acpi.Table != -1)) {
Rsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)(UINTN)Hob->Acpi.Table;
Rsdt = (RSDT_TABLE *)(UINTN)Rsdp->RsdtAddress;
//
// Check Rsdt
//
if (Rsdt != NULL) {
ScanTableInRSDT (Rsdt, Signature, &AcpiTable);
}
}
return AcpiTable;
}
#pragma pack(1)
typedef struct {
UINT64 BaseAddress;
UINT16 PciSegmentGroupNumber;
UINT8 StartBusNumber;
UINT8 EndBusNumber;
UINT32 Reserved;
} MCFG_STRUCTURE;
#pragma pack()
VOID
PrepareMcfgTable (
IN HOB_TEMPLATE *Hob
)
{
EFI_ACPI_DESCRIPTION_HEADER *McfgTable;
MCFG_STRUCTURE *Mcfg;
UINTN McfgCount;
UINTN Index;
McfgTable = FindAcpiPtr (Hob, EFI_ACPI_3_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE);
if (McfgTable == NULL) {
return ;
}
Mcfg = (MCFG_STRUCTURE *)((UINTN)McfgTable + sizeof(EFI_ACPI_DESCRIPTION_HEADER) + sizeof(UINT64));
McfgCount = (McfgTable->Length - sizeof(EFI_ACPI_DESCRIPTION_HEADER) - sizeof(UINT64)) / sizeof(MCFG_STRUCTURE);
//
// Fill PciExpress info on Hob
// Note: Only for 1st segment
//
for (Index = 0; Index < McfgCount; Index++) {
if (Mcfg[Index].PciSegmentGroupNumber == 0) {
Hob->PciExpress.PciExpressBaseAddressInfo.PciExpressBaseAddress = Mcfg[Index].BaseAddress;
break;
}
}
return ;
}
VOID
PrepareFadtTable (
IN HOB_TEMPLATE *Hob
)
{
EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;
EFI_ACPI_DESCRIPTION *AcpiDescription;
Fadt = FindAcpiPtr (Hob, EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE);
if (Fadt == NULL) {
return ;
}
AcpiDescription = &Hob->AcpiInfo.AcpiDescription;
//
// Fill AcpiDescription according to FADT
// Currently, only for PM_TMR
//
AcpiDescription->PM_TMR_LEN = Fadt->PmTmrLen;
AcpiDescription->TMR_VAL_EXT = (UINT8)((Fadt->Flags & 0x100) != 0);
//
// For fields not included in ACPI 1.0 spec, we get the value based on table length
//
if (Fadt->Header.Length >= OFFSET_OF (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE, XPmTmrBlk) + sizeof (Fadt->XPmTmrBlk)) {
CopyMem (
&AcpiDescription->PM_TMR_BLK,
&Fadt->XPmTmrBlk,
sizeof(EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE)
);
}
if (Fadt->Header.Length >= OFFSET_OF (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE, ResetValue) + sizeof (Fadt->ResetValue)) {
CopyMem (
&AcpiDescription->RESET_REG,
&Fadt->ResetReg,
sizeof(EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE)
);
AcpiDescription->RESET_VALUE = Fadt->ResetValue;
}
if (AcpiDescription->PM_TMR_BLK.Address == 0) {
AcpiDescription->PM_TMR_BLK.Address = Fadt->PmTmrBlk;
AcpiDescription->PM_TMR_BLK.AddressSpaceId = EFI_ACPI_3_0_SYSTEM_IO;
}
//
// It's possible that the PM_TMR_BLK.RegisterBitWidth is always 32,
// we need to set the correct RegisterBitWidth value according to the TMR_VAL_EXT
// A zero indicates TMR_VAL is implemented as a 24-bit value.
// A one indicates TMR_VAL is implemented as a 32-bit value
//
AcpiDescription->PM_TMR_BLK.RegisterBitWidth = (UINT8) ((AcpiDescription->TMR_VAL_EXT == 0) ? 24 : 32);
return ;
}
VOID
PrepareHobLegacyTable (
IN HOB_TEMPLATE *Hob
)
{
CHAR8 PrintBuffer[256];
Hob->Acpi.Table = (EFI_PHYSICAL_ADDRESS)(UINTN)FindAcpiRsdPtr ();
AsciiSPrint (PrintBuffer, 256, "\nAcpiTable=0x%x ", (UINT32)(UINTN)Hob->Acpi.Table);
PrintString (PrintBuffer);
Hob->Acpi20.Table = (EFI_PHYSICAL_ADDRESS)(UINTN)FindAcpiRsdPtr ();
Hob->Smbios.Table = (EFI_PHYSICAL_ADDRESS)(UINTN)FindSMBIOSPtr ();
AsciiSPrint (PrintBuffer, 256, "SMBIOS Table=0x%x ", (UINT32)(UINTN)Hob->Smbios.Table);
PrintString (PrintBuffer);
Hob->Mps.Table = (EFI_PHYSICAL_ADDRESS)(UINTN)FindMPSPtr ();
AsciiSPrint (PrintBuffer, 256, "MPS Table=0x%x\n", (UINT32)(UINTN)Hob->Mps.Table);
PrintString (PrintBuffer);
PrepareMcfgTable (Hob);
PrepareFadtTable (Hob);
return ;
}

View File

@@ -1,31 +0,0 @@
/** @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
LegacyTable.h
Abstract:
Revision History:
**/
#ifndef _DXELDR_LEGACY_TABLE_H_
#define _DXELDR_LEGACY_TABLE_H_
#include "HobGeneration.h"
VOID
PrepareHobLegacyTable (
IN HOB_TEMPLATE *Hob
);
#endif

View File

@@ -1,59 +0,0 @@
/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PpisNeededByDxeCore.c
Abstract:
Revision History:
**/
#include "PpisNeededByDxeCore.h"
#include "HobGeneration.h"
#include "SerialStatusCode.h"
EFI_STATUS
EFIAPI
PreparePpisNeededByDxeCore (
IN HOB_TEMPLATE *Hob
)
/*++
Routine Description:
This routine adds the PPI/Protocol Hobs that are consumed by the DXE Core.
Normally these come from PEI, but since our PEI was 32-bit we need an
alternate source. That is this driver.
This driver does not consume PEI or DXE services and thus updates the
Phit (HOB list) directly
Arguments:
HobStart - Pointer to the beginning of the HOB List from PEI
Returns:
This function should after it has add it's HOBs
--*/
{
EFI_REPORT_STATUS_CODE ReportStatusCode;
InstallSerialStatusCode (&ReportStatusCode);
Hob->SerialStatusCode.Interface = (EFI_PHYSICAL_ADDRESS) (UINTN) ReportStatusCode;
return EFI_SUCCESS;
}

View File

@@ -1,64 +0,0 @@
/** @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PpisNeededByDxeCore.h
Abstract:
Revision History:
**/
#ifndef _DXELDR_PPIS_NEEDED_BY_DXE_CORE_H_
#define _DXELDR_PPIS_NEEDED_BY_DXE_CORE_H_
#include "DxeIpl.h"
#include "HobGeneration.h"
//EFI_STATUS
//InstallEfiPeiTransferControl (
// IN OUT EFI_PEI_TRANSFER_CONTROL_PROTOCOL **This
// );
//EFI_STATUS
//InstallEfiPeiFlushInstructionCache (
// IN OUT EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL **This
// );
EFI_STATUS
EFIAPI
PreparePpisNeededByDxeCore (
IN HOB_TEMPLATE *HobStart
)
/*++
Routine Description:
This routine adds the PPI/Protocol Hobs that are consumed by the DXE Core.
Normally these come from PEI, but since our PEI was 32-bit we need an
alternate source. That is this driver.
This driver does not consume PEI or DXE services and thus updates the
Phit (HOB list) directly
Arguments:
HobStart - Pointer to the beginning of the HOB List from PEI
Returns:
This function should after it has add it's HOBs
--*/
;
#endif

View File

@@ -1,760 +0,0 @@
/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SerialStatusCode.c
Abstract:
Revision History:
**/
#include <Library/SerialPortLib.h>
#include "SerialStatusCode.h"
//
// All of the lookup tables are only needed in debug.
//
typedef struct {
UINT32 Value;
CHAR8 *Token;
} STATUS_CODE_LOOKUP_TABLE;
STATUS_CODE_LOOKUP_TABLE mSeverityToken[] = {
{ EFI_ERROR_MINOR, "ERROR_MINOR" },
{ EFI_ERROR_MAJOR, "ERROR_MAJOR" },
{ EFI_ERROR_UNRECOVERED, "ERROR_UNRECOVERED" },
{ EFI_ERROR_UNCONTAINED, "ERROR_UNCONTAINED" },
{ 0xFFFFFFFF, "ERROR_UNRECOGNIZED" }
};
STATUS_CODE_LOOKUP_TABLE mClassSubClassToken[] = {
{ EFI_COMPUTING_UNIT_UNSPECIFIED, "COMPUTING_UNIT_UNSPECIFIED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR, "COMPUTING_UNIT_HOST_PROCESSOR" },
{ EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR, "COMPUTING_UNIT_FIRMWARE_PROCESSOR" },
{ EFI_COMPUTING_UNIT_IO_PROCESSOR, "COMPUTING_UNIT_IO_PROCESSOR" },
{ EFI_COMPUTING_UNIT_CACHE, "COMPUTING_UNIT_CACHE" },
{ EFI_COMPUTING_UNIT_MEMORY, "COMPUTING_UNIT_MEMORY" },
{ EFI_COMPUTING_UNIT_CHIPSET, "COMPUTING_UNIT_CHIPSET" },
{ EFI_PERIPHERAL_UNSPECIFIED, "PERIPHERAL_UNSPECIFIED" },
{ EFI_PERIPHERAL_KEYBOARD, "PERIPHERAL_KEYBOARD" },
{ EFI_PERIPHERAL_MOUSE, "PERIPHERAL_MOUSE" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE, "PERIPHERAL_LOCAL_CONSOLE" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE, "PERIPHERAL_REMOTE_CONSOLE" },
{ EFI_PERIPHERAL_SERIAL_PORT, "PERIPHERAL_SERIAL_PORT" },
{ EFI_PERIPHERAL_PARALLEL_PORT, "PERIPHERAL_PARALLEL_PORT" },
{ EFI_PERIPHERAL_FIXED_MEDIA, "PERIPHERAL_FIXED_MEDIA" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA, "PERIPHERAL_REMOVABLE_MEDIA" },
{ EFI_PERIPHERAL_AUDIO_INPUT, "PERIPHERAL_AUDIO_INPUT" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT, "PERIPHERAL_AUDIO_OUTPUT" },
{ EFI_PERIPHERAL_LCD_DEVICE, "PERIPHERAL_LCD_DEVICE" },
{ EFI_IO_BUS_UNSPECIFIED, "IO_BUS_UNSPECIFIED" },
{ EFI_IO_BUS_PCI, "IO_BUS_PCI" },
{ EFI_IO_BUS_USB, "IO_BUS_USB" },
{ EFI_IO_BUS_IBA, "IO_BUS_IBA" },
{ EFI_IO_BUS_AGP, "IO_BUS_AGP" },
{ EFI_IO_BUS_PC_CARD, "IO_BUS_PC_CARD" },
{ EFI_IO_BUS_LPC, "IO_BUS_LPC" },
{ EFI_IO_BUS_SCSI, "IO_BUS_SCSI" },
{ EFI_IO_BUS_ATA_ATAPI, "IO_BUS_ATA_ATAPI" },
{ EFI_IO_BUS_FC, "IO_BUS_FC" },
{ EFI_IO_BUS_IP_NETWORK, "IO_BUS_IP_NETWORK" },
{ EFI_IO_BUS_SMBUS, "IO_BUS_SMBUS" },
{ EFI_IO_BUS_I2C, "IO_BUS_I2C" },
{ EFI_SOFTWARE_UNSPECIFIED, "SOFTWARE_UNSPECIFIED" },
{ EFI_SOFTWARE_SEC, "SOFTWARE_SEC" },
{ EFI_SOFTWARE_PEI_CORE, "SOFTWARE_PEI_CORE" },
{ EFI_SOFTWARE_PEI_MODULE, "SOFTWARE_PEI_MODULE" },
{ EFI_SOFTWARE_DXE_CORE, "SOFTWARE_DXE_CORE" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE, "SOFTWARE_EFI_BOOT_SERVICE" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE, "SOFTWARE_EFI_RUNTIME_SERVICE" },
{ EFI_SOFTWARE_DXE_BS_DRIVER, "SOFTWARE_DXE_BS_DRIVER" },
{ EFI_SOFTWARE_DXE_RT_DRIVER, "SOFTWARE_DXE_RT_DRIVER" },
{ EFI_SOFTWARE_SMM_DRIVER, "SOFTWARE_SMM_DRIVER" },
{ EFI_SOFTWARE_RT, "SOFTWARE_EFI_RT" },
{ EFI_SOFTWARE_AL, "SOFTWARE_EFI_AL" },
{ EFI_SOFTWARE_EFI_APPLICATION, "SOFTWARE_EFI_APPLICATION" },
{ EFI_SOFTWARE_EFI_OS_LOADER, "SOFTWARE_EFI_OS_LOADER" },
{ 0xFFFFFFFF, "ERROR_UNRECOGNIZED" }
};
STATUS_CODE_LOOKUP_TABLE mOperationToken[] = {
{ EFI_COMPUTING_UNIT_UNSPECIFIED | EFI_CU_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_COMPUTING_UNIT_UNSPECIFIED | EFI_CU_EC_DISABLED, "DISABLED" },
{ EFI_COMPUTING_UNIT_UNSPECIFIED | EFI_CU_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_COMPUTING_UNIT_UNSPECIFIED | EFI_CU_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_COMPUTING_UNIT_UNSPECIFIED | EFI_CU_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_EC_DISABLED, "DISABLED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_INVALID_TYPE, "INVALID_TYPE" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_INVALID_SPEED, "INVALID_SPEED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_MISMATCH, "MISMATCH" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_TIMER_EXPIRED, "TIMER_EXPIRED" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST, "SELF_TEST" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_INTERNAL, "INTERNAL" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_THERMAL, "THERMAL" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_LOW_VOLTAGE, "LOW_VOLTAGE" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_HIGH_VOLTAGE, "HIGH_VOLTAGE" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_CACHE, "CACHE" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_MICROCODE_UPDATE, "MICROCODE_UPDATE" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_NO_MICROCODE_UPDATE, "NO_MICROCODE_UPDATE" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_CORRECTABLE, "1XECC" },
{ EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_UNCORRECTABLE, "2XECC" },
{ EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR | EFI_CU_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR | EFI_CU_EC_DISABLED, "DISABLED" },
{ EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR | EFI_CU_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR | EFI_CU_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR | EFI_CU_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_COMPUTING_UNIT_IO_PROCESSOR | EFI_CU_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_COMPUTING_UNIT_IO_PROCESSOR | EFI_CU_EC_DISABLED, "DISABLED" },
{ EFI_COMPUTING_UNIT_IO_PROCESSOR | EFI_CU_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_COMPUTING_UNIT_IO_PROCESSOR | EFI_CU_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_COMPUTING_UNIT_IO_PROCESSOR | EFI_CU_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_EC_DISABLED, "DISABLED" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_CACHE_EC_INVALID_TYPE, "INVALID_TYPE" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_CACHE_EC_INVALID_SPEED, "INVALID_SPEED" },
{ EFI_COMPUTING_UNIT_CACHE | EFI_CU_CACHE_EC_INVALID_SIZE, "INVALID_SIZE" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_EC_DISABLED, "DISABLED" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_INVALID_TYPE, "INVALID_TYPE" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_INVALID_SPEED, "INVALID_SPEED" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_CORRECTABLE, "1XECC" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE, "2XECC" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_SPD_FAIL, "SPD_FAIL" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_INVALID_SIZE, "INVALID_SIZE" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_MISMATCH, "MISMATCH" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_S3_RESUME_FAIL, "S3_RESUME_FAIL" },
{ EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UPDATE_FAIL, "UPDATE_FAIL" },
{ EFI_COMPUTING_UNIT_CHIPSET | EFI_CU_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_COMPUTING_UNIT_CHIPSET | EFI_CU_EC_DISABLED, "DISABLED" },
{ EFI_COMPUTING_UNIT_CHIPSET | EFI_CU_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_COMPUTING_UNIT_CHIPSET | EFI_CU_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_COMPUTING_UNIT_CHIPSET | EFI_CU_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_UNSPECIFIED | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_LOCKED, "LOCKED" },
{ EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_STUCK_KEY, "STUCK_KEY" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_MOUSE | EFI_P_MOUSE_EC_LOCKED, "LOCKED" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_SERIAL_PORT | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_PARALLEL_PORT | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_AUDIO_INPUT | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_AUDIO_OUTPUT | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_DISABLED, "DISABLED" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_INPUT_ERROR, "INPUT_ERROR" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_OUTPUT_ERROR, "OUTPUT_ERROR" },
{ EFI_PERIPHERAL_LCD_DEVICE | EFI_P_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_UNSPECIFIED | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_PCI | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_PCI | EFI_IOB_PCI_EC_PERR, "PERR" },
{ EFI_IO_BUS_PCI | EFI_IOB_PCI_EC_SERR, "SERR" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_USB | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_IBA | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_AGP | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_PC_CARD | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_LPC | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_SCSI | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_FC | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_IP_NETWORK | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_SMBUS | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_DISABLED, "DISABLED" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_NOT_SUPPORTED, "NOT_SUPPORTED" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_NOT_DETECTED, "NOT_DETECTED" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_NOT_CONFIGURED, "NOT_CONFIGURED" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_INTERFACE_ERROR, "INTERFACE_ERROR" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_CONTROLLER_ERROR, "CONTROLLER_ERROR" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_READ_ERROR, "READ_ERROR" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_WRITE_ERROR, "WRITE_ERROR" },
{ EFI_IO_BUS_I2C | EFI_IOB_EC_RESOURCE_CONFLICT, "RESOURCE_CONFLICT" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_UNSPECIFIED | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_SEC | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_PEI_CORE | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_DXE_CORE | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_RT | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_AL | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_EFI_APPLICATION | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_NON_SPECIFIC, "NON_SPECIFIC" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_LOAD_ERROR, "LOAD_ERROR" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_INVALID_PARAMETER, "INVALID_PARAMETER" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_UNSUPPORTED, "NOT_SUPPORTED" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_INVALID_BUFFER, "INVALID_BUFFER" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_OUT_OF_RESOURCES, "OUT_OF_RESOURCES" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_ABORTED, "ABORTED" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, "ILLEGAL_SOFTWARE_STATE" },
{ EFI_SOFTWARE_EFI_OS_LOADER | EFI_SW_EC_ILLEGAL_HARDWARE_STATE, "ILLEGAL_HARDWARE_STATE" },
{ 0xFFFFFFFF, "ERROR_UNRECOGNIZED" }
};
EFI_STATUS
MatchString (
IN STATUS_CODE_LOOKUP_TABLE *Table,
IN UINT32 Value,
OUT CHAR8 **Token
);
//
// Function implemenations
//
//
// Match is only needed for debug.
//
EFI_STATUS
MatchString (
IN STATUS_CODE_LOOKUP_TABLE *Table,
IN UINT32 Value,
OUT CHAR8 **Token
)
/*++
Routine Description:
Search the input table for a matching value and return the token associated
with that value. Well formed tables will have the last value == 0 and will
return a default token.
Arguments:
Table Pointer to first entry in an array of table entries.
Value Value to look up.
Token String to return.
Returns:
EFI_SUCCESS The function always returns success.
--*/
{
UINTN Current;
Current = 0;
*Token = 0;
while (!*Token) {
//
// Found token if values match or current entry is the last entry.
//
if ((Table[Current].Value == (-1)) ||
(Table[Current].Value == Value)) {
*Token = Table[Current].Token;
}
Current++;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
SerialReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN EFI_GUID *CallerId,
IN EFI_STATUS_CODE_DATA *Data OPTIONAL
)
/*++
Routine Description:
Provide a serial port print
Arguments:
PeiServices - General purpose services available to every PEIM.
Returns:
Status - EFI_SUCCESS if the interface could be successfully
installed
--*/
{
CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
UINT32 LineNumber;
CHAR8 *Filename;
CHAR8 *Description;
CHAR8 *Format;
BASE_LIST Marker;
UINT32 ErrorLevel;
UINTN CharCount = 0;
Buffer[0] = '\0';
if (Data != NULL &&
ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
//
// Processes PEI_ASSERT ()
//
CharCount = AsciiSPrint (
Buffer,
sizeof (Buffer),
"\nPEI_ASSERT!: %a (%d): %a\n",
Filename,
LineNumber,
Description
);
} else if (Data != NULL &&
ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
//
// Process PEI_DEBUG () macro to Serial
//
CharCount = AsciiBSPrint (Buffer, sizeof (Buffer), Format, Marker);
} else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
//
// Process Errors
//
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "ERROR: C%x:V%x I%x", CodeType, Value, Instance);
//
// Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
//
if (CallerId) {
CharCount += AsciiSPrint (&Buffer[CharCount - 1], (sizeof (Buffer) - (sizeof(Buffer[0]) * CharCount)), " %g", CallerId);
}
if (Data) {
CharCount += AsciiSPrint (&Buffer[CharCount - 1], (sizeof (Buffer) - (sizeof(Buffer[0]) * CharCount)), " %x", Data);
}
CharCount += AsciiSPrint (&Buffer[CharCount - 1], (sizeof (Buffer) - (sizeof(Buffer[0]) * CharCount)), "\n");
}
if (Buffer[0] != '\0') {
//
// Callout to platform Lib function to do print.
//
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
//
// Debug code to display human readable code information.
//
{
CHAR8 *SeverityToken;
CHAR8 *SubClassToken;
CHAR8 *OperationToken;
if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
//
// Get the severity token
//
MatchString (
mSeverityToken,
(CodeType & EFI_STATUS_CODE_SEVERITY_MASK),
&SeverityToken
);
//
// Get the Class/SubClass token
//
MatchString (
mClassSubClassToken,
(Value & (EFI_STATUS_CODE_CLASS_MASK | EFI_STATUS_CODE_SUBCLASS_MASK)),
&SubClassToken
);
//
// Get the operation token
//
MatchString (
mOperationToken,
(Value & (EFI_STATUS_CODE_CLASS_MASK | EFI_STATUS_CODE_SUBCLASS_MASK | EFI_STATUS_CODE_OPERATION_MASK)),
&OperationToken
);
//
// Concatenate the instance
//
CharCount = AsciiSPrint (
Buffer,
sizeof (Buffer),
"%a:%a:%a:%d\n",
SeverityToken,
SubClassToken,
OperationToken,
Instance
);
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
}
return EFI_SUCCESS;
}
VOID
InstallSerialStatusCode (
IN EFI_REPORT_STATUS_CODE *ReportStatusCode
)
/*++
Routine Description:
Initialize Serial Port and Status Code Handler
Arguments:
ReportStatusCode - A pointer to the handler
Returns:
None
--*/
{
SerialPortInitialize();
*ReportStatusCode = SerialReportStatusCode;
}

View File

@@ -1,39 +0,0 @@
/** @file
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SerialStatusCode.h
Abstract:
Revision History:
**/
#ifndef _DXELDR_SERIAL_STATUS_CODE_H_
#define _DXELDR_SERIAL_STATUS_CODE_H_
//
// Statements that include other files
//
#include "DxeIpl.h"
//
// GUID consumed
//
VOID
InstallSerialStatusCode (
IN EFI_REPORT_STATUS_CODE *ReportStatusCode
);
#endif

View File

@@ -1,32 +0,0 @@
/** @file
x64 specific code to enter DxeCore
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "DxeIpl.h"
VOID
EnterDxeMain (
IN VOID *StackTop,
IN VOID *DxeCoreEntryPoint,
IN VOID *Hob,
IN VOID *PageTable
)
{
AsmWriteCr3 ((UINTN) PageTable);
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
Hob,
NULL,
StackTop
);
}

View File

@@ -1,238 +0,0 @@
/** @file
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Paging.c
Abstract:
Revision History:
**/
#include "HobGeneration.h"
#include "VirtualMemory.h"
//
// Create 2M-page table
// PML4 (47:39)
// PDPTE (38:30)
// PDE (29:21)
//
#define EFI_2M_PAGE_BITS_NUM 21
#define EFI_MAX_ENTRY_BITS_NUM 9
#define EFI_PAGE_SIZE_4K 0x1000
#define EFI_PAGE_SIZE_2M (1 << EFI_2M_PAGE_BITS_NUM)
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#define ENTRY_NUM(x) ((UINTN)1 << (x))
UINT8 gPML4BitsNum;
UINT8 gPDPTEBitsNum;
UINT8 gPDEBitsNum;
UINTN gPageNum2M;
UINTN gPageNum4K;
VOID
EnableNullPointerProtection (
UINT8 *PageTable
)
{
X64_PAGE_TABLE_ENTRY_4K *PageTableEntry4KB;
PageTableEntry4KB = (X64_PAGE_TABLE_ENTRY_4K *) (PageTable + gPageNum2M * EFI_PAGE_SIZE_4K);
//
// Fill in the Page Table entries
// Mark 0~4K as not present
//
PageTableEntry4KB->Bits.Present = 0;
return ;
}
VOID
X64Create4KPageTables (
UINT8 *PageTable
)
/*++
Routine Description:
Create 4K-Page-Table for the low 2M memory.
This will change the previously created 2M-Page-Table-Entry.
--*/
{
UINT64 PageAddress;
UINTN PTEIndex;
X64_PAGE_DIRECTORY_ENTRY_4K *PageDirectoryEntry4KB;
X64_PAGE_TABLE_ENTRY_4K *PageTableEntry4KB;
//
// Page Table structure 4 level 4K.
//
// PageMapLevel4Entry : bits 47-39
// PageDirectoryPointerEntry : bits 38-30
// Page Table 4K : PageDirectoryEntry4K : bits 29-21
// PageTableEntry : bits 20-12
//
PageTableEntry4KB = (X64_PAGE_TABLE_ENTRY_4K *)(PageTable + gPageNum2M * EFI_PAGE_SIZE_4K);
PageDirectoryEntry4KB = (X64_PAGE_DIRECTORY_ENTRY_4K *) (PageTable + 2 * EFI_PAGE_SIZE_4K);
PageDirectoryEntry4KB->Uint64 = (UINT64)(UINTN)PageTableEntry4KB;
PageDirectoryEntry4KB->Bits.ReadWrite = 1;
PageDirectoryEntry4KB->Bits.Present = 1;
PageDirectoryEntry4KB->Bits.MustBeZero = 0;
for (PTEIndex = 0, PageAddress = 0;
PTEIndex < ENTRY_NUM (EFI_MAX_ENTRY_BITS_NUM);
PTEIndex++, PageTableEntry4KB++, PageAddress += EFI_PAGE_SIZE_4K
) {
//
// Fill in the Page Table entries
//
PageTableEntry4KB->Uint64 = (UINT64)PageAddress;
PageTableEntry4KB->Bits.ReadWrite = 1;
PageTableEntry4KB->Bits.Present = 1;
}
return ;
}
VOID
X64Create2MPageTables (
UINT8 *PageTable
)
{
UINT64 PageAddress;
UINT8 *TempPageTable;
UINTN PML4Index;
UINTN PDPTEIndex;
UINTN PDEIndex;
X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *PageMapLevel4Entry;
X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *PageDirectoryPointerEntry;
X64_PAGE_TABLE_ENTRY_2M *PageDirectoryEntry2MB;
TempPageTable = PageTable;
PageAddress = 0;
//
// Page Table structure 3 level 2MB.
//
// PageMapLevel4Entry : bits 47-39
// PageDirectoryPointerEntry : bits 38-30
// Page Table 2MB : PageDirectoryEntry2M : bits 29-21
//
PageMapLevel4Entry = (X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *)TempPageTable;
for (PML4Index = 0; PML4Index < ENTRY_NUM (gPML4BitsNum); PML4Index++, PageMapLevel4Entry++) {
//
// Each PML4 entry points to a page of Page Directory Pointer entires.
//
TempPageTable += EFI_PAGE_SIZE_4K;
PageDirectoryPointerEntry = (X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K *)TempPageTable;
//
// Make a PML4 Entry
//
PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)(TempPageTable);
PageMapLevel4Entry->Bits.ReadWrite = 1;
PageMapLevel4Entry->Bits.Present = 1;
for (PDPTEIndex = 0; PDPTEIndex < ENTRY_NUM (gPDPTEBitsNum); PDPTEIndex++, PageDirectoryPointerEntry++) {
//
// Each Directory Pointer entries points to a page of Page Directory entires.
//
TempPageTable += EFI_PAGE_SIZE_4K;
PageDirectoryEntry2MB = (X64_PAGE_TABLE_ENTRY_2M *)TempPageTable;
//
// Fill in a Page Directory Pointer Entries
//
PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)(TempPageTable);
PageDirectoryPointerEntry->Bits.ReadWrite = 1;
PageDirectoryPointerEntry->Bits.Present = 1;
for (PDEIndex = 0; PDEIndex < ENTRY_NUM (gPDEBitsNum); PDEIndex++, PageDirectoryEntry2MB++) {
//
// Fill in the Page Directory entries
//
PageDirectoryEntry2MB->Uint64 = (UINT64)PageAddress;
PageDirectoryEntry2MB->Bits.ReadWrite = 1;
PageDirectoryEntry2MB->Bits.Present = 1;
PageDirectoryEntry2MB->Bits.MustBe1 = 1;
PageAddress += EFI_PAGE_SIZE_2M;
}
}
}
return ;
}
VOID *
PreparePageTable (
VOID *PageNumberTop,
UINT8 SizeOfMemorySpace
)
/*++
Description:
Generate pagetable below PageNumberTop,
and return the bottom address of pagetable for putting other things later.
--*/
{
VOID *PageNumberBase;
SizeOfMemorySpace -= EFI_2M_PAGE_BITS_NUM;
gPDEBitsNum = (UINT8) MIN (SizeOfMemorySpace, EFI_MAX_ENTRY_BITS_NUM);
SizeOfMemorySpace = (UINT8) (SizeOfMemorySpace - gPDEBitsNum);
gPDPTEBitsNum = (UINT8) MIN (SizeOfMemorySpace, EFI_MAX_ENTRY_BITS_NUM);
SizeOfMemorySpace = (UINT8) (SizeOfMemorySpace - gPDPTEBitsNum);
gPML4BitsNum = SizeOfMemorySpace;
if (gPML4BitsNum > EFI_MAX_ENTRY_BITS_NUM) {
return NULL;
}
//
// Suppose we have:
// 2MPage:
// Entry: PML4 -> PDPTE -> PDE -> Page
// EntryNum: a b c
// then
// Occupy4KPage: 1 a a*b
//
// 2M 4KPage:
// Entry: PTE -> Page
// EntryNum: 512
// then
// Occupy4KPage: 1
//
gPageNum2M = 1 + ENTRY_NUM (gPML4BitsNum) + ENTRY_NUM (gPML4BitsNum + gPDPTEBitsNum);
gPageNum4K = 1;
PageNumberBase = (VOID *)((UINTN)PageNumberTop - (gPageNum2M + gPageNum4K) * EFI_PAGE_SIZE_4K);
ZeroMem (PageNumberBase, (gPageNum2M + gPageNum4K) * EFI_PAGE_SIZE_4K);
X64Create2MPageTables (PageNumberBase);
X64Create4KPageTables (PageNumberBase);
//
// Not enable NULL Pointer Protection if using INTx call
//
// EnableNullPointerProtection (PageNumberBase);
return PageNumberBase;
}

View File

@@ -1,117 +0,0 @@
/** @file
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
VirtualMemory.h
Abstract:
Revision History:
**/
#ifndef _VIRTUAL_MEMORY_H_
#define _VIRTUAL_MEMORY_H_
#pragma pack(1)
//
// Page Map Level 4 Offset (PML4) and
// Page Directory Pointer Table (PDPE) entries 4K & 2M
//
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Reserved:1; // Reserved
UINT64 MustBeZero:2; // Must Be Zero
UINT64 Available:3; // Available for use by system software
UINT64 PageTableBaseAddress:40; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // No Execute bit
} Bits;
UINT64 Uint64;
} X64_PAGE_MAP_AND_DIRECTORY_POINTER_2MB_4K;
//
// Page Directory Entry 4K
//
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 MustBeZero:3; // Must Be Zero
UINT64 Available:3; // Available for use by system software
UINT64 PageTableBaseAddress:40; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // No Execute bit
} Bits;
UINT64 Uint64;
} X64_PAGE_DIRECTORY_ENTRY_4K;
//
// Page Table Entry 4K
//
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 PAT:1; // 0 = Ignore Page Attribute Table
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available:3; // Available for use by system software
UINT64 PageTableBaseAddress:40; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
} Bits;
UINT64 Uint64;
} X64_PAGE_TABLE_ENTRY_4K;
//
// Page Table Entry 2M
//
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 MustBe1:1; // Must be 1
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available:3; // Available for use by system software
UINT64 PAT:1; //
UINT64 MustBeZero:8; // Must be zero;
UINT64 PageTableBaseAddress:31; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
} Bits;
UINT64 Uint64;
} X64_PAGE_TABLE_ENTRY_2M;
#pragma pack()
#endif

View File

@@ -1,80 +0,0 @@
/*++
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Debug.c
Abstract:
Revision History:
--*/
#include "EfiLdr.h"
#include "Debug.h"
UINT8 *mCursor;
UINT8 mHeaderIndex = 10;
VOID
PrintHeader (
CHAR8 Char
)
{
*(UINT8 *)(UINTN)(0x000b8000 + mHeaderIndex) = Char;
mHeaderIndex += 2;
}
VOID
ClearScreen (
VOID
)
{
UINT32 Index;
mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160);
for (Index = 0; Index < 80 * 49; Index++) {
*mCursor = ' ';
mCursor += 2;
}
mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160);
}
VOID
EFIAPI
PrintString (
IN CONST CHAR8 *FormatString,
...
)
{
UINTN Index;
CHAR8 PrintBuffer[256];
VA_LIST Marker;
VA_START (Marker, FormatString);
AsciiVSPrint (PrintBuffer, sizeof (PrintBuffer), FormatString, Marker);
VA_END (Marker);
for (Index = 0; PrintBuffer[Index] != 0; Index++) {
if (PrintBuffer[Index] == '\n') {
mCursor = (UINT8 *) (UINTN) (0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160));
} else {
*mCursor = (UINT8) PrintBuffer[Index];
mCursor += 2;
}
}
//
// All information also output to serial port.
//
SerialPortWrite ((UINT8 *) PrintBuffer, Index);
}

View File

@@ -1,41 +0,0 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Debug.h
Abstract:
Revision History:
--*/
#ifndef _EFILDR_DEBUG_H_
#define _EFILDR_DEBUG_H_
VOID
PrintHeader (
CHAR8 Char
);
VOID
EFIAPI
PrintString (
IN CONST CHAR8 *FormatString,
...
);
VOID
ClearScreen (
VOID
);
#endif

View File

@@ -1,89 +0,0 @@
/*++
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiLdr.c
Abstract:
Revision History:
--*/
#ifndef _DUET_EFI_LOADER_H_
#define _DUET_EFI_LOADER_H_
#include "Uefi.h"
#include "EfiLdrHandoff.h"
#include <Protocol/LoadedImage.h>
#include <IndustryStandard/PeImage.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PrintLib.h>
#include <Library/SerialPortLib.h>
#define INT15_E820_AddressRangeMemory 1
#define INT15_E820_AddressRangeReserved 2
#define INT15_E820_AddressRangeACPI 3
#define INT15_E820_AddressRangeNVS 4
#define EFI_FIRMWARE_BASE_ADDRESS 0x00200000
#define EFI_DECOMPRESSED_BUFFER_ADDRESS 0x00600000
#define EFI_MAX_MEMORY_DESCRIPTORS 64
#define LOADED_IMAGE_SIGNATURE SIGNATURE_32('l','d','r','i')
typedef struct {
UINTN Signature;
CHAR16 *Name; // Displayable name
UINTN Type;
BOOLEAN Started; // If entrypoint has been called
VOID *StartImageContext;
EFI_IMAGE_ENTRY_POINT EntryPoint; // The image's entry point
EFI_LOADED_IMAGE_PROTOCOL Info; // loaded image protocol
//
EFI_PHYSICAL_ADDRESS ImageBasePage; // Location in memory
UINTN NoPages; // Number of pages
UINT8 *ImageBase; // As a char pointer
UINT8 *ImageEof; // End of memory image
// relocate info
UINT8 *ImageAdjust; // Bias for reloc calculations
UINTN StackAddress;
UINT8 *FixupData; // Original fixup data
} EFILDR_LOADED_IMAGE;
#pragma pack(4)
typedef struct {
UINT64 BaseAddress;
UINT64 Length;
UINT32 Type;
} BIOS_MEMORY_MAP_ENTRY;
#pragma pack()
typedef struct {
UINT32 MemoryMapSize;
BIOS_MEMORY_MAP_ENTRY MemoryMapEntry[1];
} BIOS_MEMORY_MAP;
typedef
VOID
(EFIAPI * EFI_MAIN_ENTRYPOINT) (
IN EFILDRHANDOFF *Handoff
);
#endif //_DUET_EFI_LOADER_H_

View File

@@ -1,55 +0,0 @@
## @file
#
# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
# EfiLdr.inf
#
# Abstract:
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EfiLoader
FILE_GUID = A9620E5C-5FA1-40b7-8B21-50B632F88F38
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
[LibraryClasses]
BaseLib
BaseMemoryLib
PrintLib
SerialPortLib
[Sources]
Debug.h
PeLoader.h
Support.h
EfiLdrHandoff.h
EfiLdr.h
EfiLoader.c
Debug.c
PeLoader.c
Support.c
#TianoDecompress.c
#TianoDecompress.h
LzmaDecompress.h
[Guids]
gTianoCustomDecompressGuid
[BuildOptions]
MSFT:*_*_*_DLINK_FLAGS = /BASE:0x10000

View File

@@ -1,56 +0,0 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiLdrHandoff.h
Abstract:
Revision History:
--*/
#ifndef _EFILDR_HANDOFF_H_
#define _EFILDR_HANDOFF_H_
#define EFILDR_BASE_SEGMENT 0x2000
#define EFILDR_LOAD_ADDRESS (EFILDR_BASE_SEGMENT << 4)
#define EFILDR_HEADER_ADDRESS (EFILDR_LOAD_ADDRESS+0x2000)
#define EFILDR_CB_VA 0x00
typedef struct _EFILDRHANDOFF {
UINTN MemDescCount;
EFI_MEMORY_DESCRIPTOR *MemDesc;
VOID *BfvBase;
UINTN BfvSize;
VOID *DxeIplImageBase;
UINTN DxeIplImageSize;
VOID *DxeCoreImageBase;
UINTN DxeCoreImageSize;
VOID *DxeCoreEntryPoint;
} EFILDRHANDOFF;
typedef struct {
UINT32 CheckSum;
UINT32 Offset;
UINT32 Length;
UINT8 FileName[52];
} EFILDR_IMAGE;
typedef struct {
UINT32 Signature;
UINT32 HeaderCheckSum;
UINT32 FileLength;
UINT32 NumberOfImages;
} EFILDR_HEADER;
#endif

View File

@@ -1,294 +0,0 @@
/*++
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiLoader.c
Abstract:
Revision History:
--*/
#include "EfiLdr.h"
#include "Support.h"
#include "Debug.h"
#include "PeLoader.h"
#include "LzmaDecompress.h"
EFILDR_LOADED_IMAGE DxeCoreImage;
EFILDR_LOADED_IMAGE DxeIplImage;
VOID
SystemHang (
CHAR8 *Message
)
{
PrintString (
"%s## FATAL ERROR ##: Fail to load DUET images! System hang!\n",
Message
);
CpuDeadLoop();
}
VOID
EfiLoader (
UINT32 BiosMemoryMapBaseAddress
)
{
BIOS_MEMORY_MAP *BiosMemoryMap;
EFILDR_IMAGE *EFILDRImage;
EFI_MEMORY_DESCRIPTOR EfiMemoryDescriptor[EFI_MAX_MEMORY_DESCRIPTORS];
EFI_STATUS Status;
UINTN NumberOfMemoryMapEntries;
UINT32 DestinationSize;
UINT32 ScratchSize;
UINTN BfvPageNumber;
UINTN BfvBase;
EFI_MAIN_ENTRYPOINT EfiMainEntrypoint;
EFILDRHANDOFF Handoff;
UINTN Index;
ClearScreen();
PrintHeader ('A');
PrintString ("Enter DUET Loader...\n");
PrintString ("BiosMemoryMapBaseAddress = %x\n", (UINTN) BiosMemoryMapBaseAddress);
//
// Add all EfiConventionalMemory descriptors to the table. If there are partial pages, then
// round the start address up to the next page, and round the length down to a page boundary.
//
BiosMemoryMap = (BIOS_MEMORY_MAP *) (UINTN) BiosMemoryMapBaseAddress;
NumberOfMemoryMapEntries = 0;
GenMemoryMap (&NumberOfMemoryMapEntries, EfiMemoryDescriptor, BiosMemoryMap);
PrintString ("Get %d entries of memory map!\n", NumberOfMemoryMapEntries);
//
// Get information on where the image is in memory
//
EFILDRImage = (EFILDR_IMAGE *)(UINTN)(EFILDR_HEADER_ADDRESS + sizeof(EFILDR_HEADER));
//
// Point to the 4th image (Bfv)
//
EFILDRImage += 3;
//
// Decompress the image
//
PrintString (
"Decompress BFV image, Image Address = %x Offset = %x\n",
(UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
(UINTN) EFILDRImage->Offset
);
Status = LzmaUefiDecompressGetInfo (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
&DestinationSize,
&ScratchSize
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to get decompress information for BFV!\n");
}
PrintString ("BFV decompress: DestinationSize = %x, ScratchSize = %x\n", (UINTN) DestinationSize, (UINTN) ScratchSize);
Status = LzmaUefiDecompress (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
(VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to decompress BFV!\n");
}
BfvPageNumber = EFI_SIZE_TO_PAGES (DestinationSize);
BfvBase = (UINTN) FindSpace (BfvPageNumber, &NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);
if (BfvBase == 0) {
SystemHang ("Failed to find free space to hold decompressed BFV\n");
}
ZeroMem ((VOID *)(UINTN)BfvBase, BfvPageNumber * EFI_PAGE_SIZE);
CopyMem ((VOID *)(UINTN)BfvBase, (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, DestinationSize);
PrintHeader ('B');
//
// Point to the 2nd image (DxeIpl)
//
EFILDRImage -= 2;
//
// Decompress the image
//
PrintString (
"Decompress DxeIpl image, Image Address = %x Offset = %x\n",
(UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
(UINTN) EFILDRImage->Offset
);
Status = LzmaUefiDecompressGetInfo (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
&DestinationSize,
&ScratchSize
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to get decompress information for DxeIpl!\n");
}
Status = LzmaUefiDecompress (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
(VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to decompress DxeIpl image\n");
}
PrintString ("Start load DxeIpl PE image\n");
//
// Load and relocate the EFI PE/COFF Firmware Image
//
Status = EfiLdrPeCoffLoadPeImage (
(VOID *)(UINTN)(EFI_DECOMPRESSED_BUFFER_ADDRESS),
&DxeIplImage,
&NumberOfMemoryMapEntries,
EfiMemoryDescriptor
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to load and relocate DxeIpl PE image!\n");
}
PrintString (
"DxeIpl PE image is successed loaded at %lx, entry=%p\n",
DxeIplImage.ImageBasePage,
DxeIplImage.EntryPoint
);
PrintHeader ('C');
//
// Point to the 3rd image (DxeMain)
//
EFILDRImage++;
//
// Decompress the image
//
PrintString (
"Decompress DxeMain FV image, Image Address = %x Offset = %x\n",
(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
(UINTN) EFILDRImage->Offset
);
Status = LzmaUefiDecompressGetInfo (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
&DestinationSize,
&ScratchSize
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to get decompress information for DxeMain FV image!\n");
}
Status = LzmaUefiDecompress (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
(VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to decompress DxeMain FV image!\n");
}
//
// Load and relocate the EFI PE/COFF Firmware Image
//
Status = EfiLdrPeCoffLoadPeImage (
(VOID *)(UINTN)(EFI_DECOMPRESSED_BUFFER_ADDRESS),
&DxeCoreImage,
&NumberOfMemoryMapEntries,
EfiMemoryDescriptor
);
if (EFI_ERROR (Status)) {
SystemHang ("Failed to load/relocate DxeMain!\n");
}
PrintString (
"DxeCore PE image is successed loaded at %lx, entry=%p\n",
DxeCoreImage.ImageBasePage,
DxeCoreImage.EntryPoint
);
PrintHeader ('E');
//
// Display the table of memory descriptors.
//
PrintString ("\nEFI Memory Descriptors\n");
for (Index = 0; Index < NumberOfMemoryMapEntries; Index++) {
PrintString (
"Type = %x Start = %08lx NumberOfPages = %08lx\n",
EfiMemoryDescriptor[Index].Type, EfiMemoryDescriptor[Index].PhysicalStart, EfiMemoryDescriptor[Index].NumberOfPages
);
}
//
// Jump to EFI Firmware
//
if (DxeIplImage.EntryPoint != NULL) {
Handoff.MemDescCount = NumberOfMemoryMapEntries;
Handoff.MemDesc = EfiMemoryDescriptor;
Handoff.BfvBase = (VOID *)(UINTN)BfvBase;
Handoff.BfvSize = BfvPageNumber * EFI_PAGE_SIZE;
Handoff.DxeIplImageBase = (VOID *)(UINTN)DxeIplImage.ImageBasePage;
Handoff.DxeIplImageSize = DxeIplImage.NoPages * EFI_PAGE_SIZE;
Handoff.DxeCoreImageBase = (VOID *)(UINTN)DxeCoreImage.ImageBasePage;
Handoff.DxeCoreImageSize = DxeCoreImage.NoPages * EFI_PAGE_SIZE;
Handoff.DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreImage.EntryPoint;
PrintString ("Transfer to DxeIpl ...EntryPoint = %p\n", DxeIplImage.EntryPoint);
EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT) DxeIplImage.EntryPoint;
EfiMainEntrypoint (&Handoff);
}
PrintHeader ('F');
//
// There was a problem loading the image, so HALT the system.
//
SystemHang ("Failed to jump to DxeIpl!\n");
}
EFI_STATUS
EFIAPI
_ModuleEntryPoint (
UINT32 BiosMemoryMapBaseAddress
)
{
SerialPortInitialize ();
EfiLoader(BiosMemoryMapBaseAddress);
return EFI_SUCCESS;
}

View File

@@ -1,70 +0,0 @@
/** @file
LZMA Decompress Library header file
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __LZMADECOMPRESS_H__
#define __LZMADECOMPRESS_H__
/**
The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().
@param Source The source buffer containing the compressed data.
@param SourceSize The size of source buffer
@param DestinationSize The size of destination buffer.
@param ScratchSize The size of scratch buffer.
@retval RETURN_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
@retval RETURN_INVALID_PARAMETER - The source data is corrupted
**/
RETURN_STATUS
EFIAPI
LzmaUefiDecompressGetInfo (
IN CONST VOID *Source,
IN UINT32 SourceSize,
OUT UINT32 *DestinationSize,
OUT UINT32 *ScratchSize
);
/**
Decompresses a Lzma compressed source buffer.
Extracts decompressed data to its original form.
If the compressed source data specified by Source is successfully decompressed
into Destination, then RETURN_SUCCESS is returned. If the compressed source data
specified by Source is not in a valid compressed data format,
then RETURN_INVALID_PARAMETER is returned.
@param Source The source buffer containing the compressed data.
@param SourceSize The size of source buffer.
@param Destination The destination buffer to store the decompressed data
@param Scratch A temporary scratch buffer that is used to perform the decompression.
This is an optional parameter that may be NULL if the
required scratch buffer size is 0.
@retval RETURN_SUCCESS Decompression completed successfully, and
the uncompressed buffer is returned in Destination.
@retval RETURN_INVALID_PARAMETER
The source buffer specified by Source is corrupted
(not in a valid compressed format).
**/
RETURN_STATUS
EFIAPI
LzmaUefiDecompress (
IN CONST VOID *Source,
IN UINTN SourceSize,
IN OUT VOID *Destination,
IN OUT VOID *Scratch
);
#endif // __LZMADECOMPRESS_H__

View File

@@ -1,635 +0,0 @@
/*++
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeLoader.c
Abstract:
Revision History:
--*/
#include "EfiLdr.h"
#include "Debug.h"
#include "Support.h"
EFI_STATUS
EfiLdrPeCoffLoadPeRelocate (
IN EFILDR_LOADED_IMAGE *Image,
IN EFI_IMAGE_DATA_DIRECTORY *RelocDir,
IN UINTN Adjust,
IN UINTN *NumberOfMemoryMapEntries,
IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
);
EFI_STATUS
EfiLdrPeCoffImageRead (
IN VOID *FHand,
IN UINTN Offset,
IN OUT UINTN ReadSize,
OUT VOID *Buffer
);
VOID *
EfiLdrPeCoffImageAddress (
IN EFILDR_LOADED_IMAGE *Image,
IN UINTN Address
);
EFI_STATUS
EfiLdrPeCoffSetImageType (
IN OUT EFILDR_LOADED_IMAGE *Image,
IN UINTN ImageType
);
EFI_STATUS
EfiLdrPeCoffCheckImageMachineType (
IN UINT16 MachineType
);
EFI_STATUS
EfiLdrGetPeImageInfo (
IN VOID *FHand,
OUT UINT64 *ImageBase,
OUT UINT32 *ImageSize
)
{
EFI_STATUS Status;
EFI_IMAGE_DOS_HEADER DosHdr;
EFI_IMAGE_OPTIONAL_HEADER_UNION PeHdr;
ZeroMem (&DosHdr, sizeof(DosHdr));
ZeroMem (&PeHdr, sizeof(PeHdr));
//
// Read image headers
//
EfiLdrPeCoffImageRead (FHand, 0, sizeof(DosHdr), &DosHdr);
if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
return EFI_UNSUPPORTED;
}
EfiLdrPeCoffImageRead (FHand, DosHdr.e_lfanew, sizeof(PeHdr), &PeHdr);
if (PeHdr.Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) {
return EFI_UNSUPPORTED;
}
//
// Verify machine type
//
Status = EfiLdrPeCoffCheckImageMachineType (PeHdr.Pe32.FileHeader.Machine);
if (EFI_ERROR(Status)) {
return Status;
}
if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
*ImageBase = (UINT32)PeHdr.Pe32.OptionalHeader.ImageBase;
} else if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
*ImageBase = PeHdr.Pe32Plus.OptionalHeader.ImageBase;
} else {
return EFI_UNSUPPORTED;
}
*ImageSize = PeHdr.Pe32.OptionalHeader.SizeOfImage;
return EFI_SUCCESS;
}
EFI_STATUS
EfiLdrPeCoffLoadPeImage (
IN VOID *FHand,
IN EFILDR_LOADED_IMAGE *Image,
IN UINTN *NumberOfMemoryMapEntries,
IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
)
{
EFI_IMAGE_DOS_HEADER DosHdr;
EFI_IMAGE_OPTIONAL_HEADER_UNION PeHdr;
EFI_IMAGE_SECTION_HEADER *FirstSection;
EFI_IMAGE_SECTION_HEADER *Section;
UINTN Index;
EFI_STATUS Status;
UINT8 *Base;
UINT8 *End;
EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
UINTN DirCount;
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY TempDebugEntry;
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
UINTN CodeViewSize;
UINTN CodeViewOffset;
UINTN CodeViewFileOffset;
UINTN OptionalHeaderSize;
UINTN PeHeaderSize;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY *DataDirectory;
UINT64 ImageBase;
CHAR8 PrintBuffer[256];
ZeroMem (&DosHdr, sizeof(DosHdr));
ZeroMem (&PeHdr, sizeof(PeHdr));
//
// Read image headers
//
EfiLdrPeCoffImageRead (FHand, 0, sizeof(DosHdr), &DosHdr);
if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Dos header signature not found\n");
PrintString (PrintBuffer);
PrintHeader ('F');
return EFI_UNSUPPORTED;
}
EfiLdrPeCoffImageRead (FHand, DosHdr.e_lfanew, sizeof(PeHdr), &PeHdr);
if (PeHdr.Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) {
AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: PE image header signature not found\n");
PrintString (PrintBuffer);
PrintHeader ('G');
return EFI_UNSUPPORTED;
}
//
// Set the image subsystem type
//
Status = EfiLdrPeCoffSetImageType (Image, PeHdr.Pe32.OptionalHeader.Subsystem);
if (EFI_ERROR(Status)) {
AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Subsystem type not known\n");
PrintString (PrintBuffer);
PrintHeader ('H');
return Status;
}
//
// Verify machine type
//
Status = EfiLdrPeCoffCheckImageMachineType (PeHdr.Pe32.FileHeader.Machine);
if (EFI_ERROR(Status)) {
AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Incorrect machine type\n");
PrintString (PrintBuffer);
PrintHeader ('I');
return Status;
}
//
// Compute the amount of memory needed to load the image and
// allocate it. This will include all sections plus the codeview debug info.
// Since the codeview info is actually outside of the image, we calculate
// its size seperately and add it to the total.
//
// Memory starts off as data
//
CodeViewSize = 0;
CodeViewFileOffset = 0;
if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(PeHdr.Pe32.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
} else if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(PeHdr.Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
} else {
return EFI_UNSUPPORTED;
}
for (DirCount = 0;
(DirCount < DirectoryEntry->Size / sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) && (CodeViewSize == 0);
DirCount++) {
Status = EfiLdrPeCoffImageRead (
FHand,
DirectoryEntry->VirtualAddress + DirCount * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY),
sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY),
&TempDebugEntry
);
if (!EFI_ERROR (Status)) {
if (TempDebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
CodeViewSize = TempDebugEntry.SizeOfData;
CodeViewFileOffset = TempDebugEntry.FileOffset;
}
}
}
CodeViewOffset = PeHdr.Pe32.OptionalHeader.SizeOfImage + PeHdr.Pe32.OptionalHeader.SectionAlignment;
Image->NoPages = EFI_SIZE_TO_PAGES (CodeViewOffset + CodeViewSize);
//
// Compute the amount of memory needed to load the image and
// allocate it. Memory starts off as data
//
Image->ImageBasePage = (EFI_PHYSICAL_ADDRESS)FindSpace (Image->NoPages, NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesCode, EFI_MEMORY_WB);
if (Image->ImageBasePage == 0) {
return EFI_OUT_OF_RESOURCES;
}
if (EFI_ERROR(Status)) {
PrintHeader ('J');
return Status;
}
AsciiSPrint (PrintBuffer, 256, "LoadPe: new image base %lx\n", Image->ImageBasePage);
PrintString (PrintBuffer);
Image->Info.ImageBase = (VOID *)(UINTN)Image->ImageBasePage;
Image->Info.ImageSize = (Image->NoPages << EFI_PAGE_SHIFT) - 1;
Image->ImageBase = (UINT8 *)(UINTN)Image->ImageBasePage;
Image->ImageEof = Image->ImageBase + Image->Info.ImageSize;
Image->ImageAdjust = Image->ImageBase;
//
// Copy the Image header to the base location
//
Status = EfiLdrPeCoffImageRead (
FHand,
0,
PeHdr.Pe32.OptionalHeader.SizeOfHeaders,
Image->ImageBase
);
if (EFI_ERROR(Status)) {
PrintHeader ('K');
return Status;
}
//
// Load each directory of the image into memory...
// Save the address of the Debug directory for later
//
if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
NumberOfRvaAndSizes = PeHdr.Pe32.OptionalHeader.NumberOfRvaAndSizes;
DataDirectory = PeHdr.Pe32.OptionalHeader.DataDirectory;
} else {
NumberOfRvaAndSizes = PeHdr.Pe32Plus.OptionalHeader.NumberOfRvaAndSizes;
DataDirectory = PeHdr.Pe32Plus.OptionalHeader.DataDirectory;
}
DebugEntry = NULL;
for (Index = 0; Index < NumberOfRvaAndSizes; Index++) {
if ((DataDirectory[Index].VirtualAddress != 0) && (DataDirectory[Index].Size != 0)) {
Status = EfiLdrPeCoffImageRead (
FHand,
DataDirectory[Index].VirtualAddress,
DataDirectory[Index].Size,
Image->ImageBase + DataDirectory[Index].VirtualAddress
);
if (EFI_ERROR(Status)) {
return Status;
}
if (Index == EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (Image->ImageBase + DataDirectory[Index].VirtualAddress);
}
}
}
//
// Load each section of the image
//
// BUGBUG: change this to use the in memory copy
if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
OptionalHeaderSize = sizeof(EFI_IMAGE_OPTIONAL_HEADER32);
PeHeaderSize = sizeof(EFI_IMAGE_NT_HEADERS32);
} else {
OptionalHeaderSize = sizeof(EFI_IMAGE_OPTIONAL_HEADER64);
PeHeaderSize = sizeof(EFI_IMAGE_NT_HEADERS64);
}
FirstSection = (EFI_IMAGE_SECTION_HEADER *) (
Image->ImageBase +
DosHdr.e_lfanew +
PeHeaderSize +
PeHdr.Pe32.FileHeader.SizeOfOptionalHeader -
OptionalHeaderSize
);
Section = FirstSection;
for (Index=0; Index < PeHdr.Pe32.FileHeader.NumberOfSections; Index += 1) {
//
// Compute sections address
//
Base = EfiLdrPeCoffImageAddress (Image, (UINTN)Section->VirtualAddress);
End = EfiLdrPeCoffImageAddress (Image, (UINTN)(Section->VirtualAddress + Section->Misc.VirtualSize));
if (EFI_ERROR(Status) || !Base || !End) {
// DEBUG((D_LOAD|D_ERROR, "LoadPe: Section %d was not loaded\n", Index));
PrintHeader ('L');
return EFI_LOAD_ERROR;
}
// DEBUG((D_LOAD, "LoadPe: Section %d, loaded at %x\n", Index, Base));
//
// Read the section
//
if (Section->SizeOfRawData) {
Status = EfiLdrPeCoffImageRead (FHand, Section->PointerToRawData, Section->SizeOfRawData, Base);
if (EFI_ERROR(Status)) {
PrintHeader ('M');
return Status;
}
}
//
// If raw size is less then virt size, zero fill the remaining
//
if (Section->SizeOfRawData < Section->Misc.VirtualSize) {
ZeroMem (
Base + Section->SizeOfRawData,
Section->Misc.VirtualSize - Section->SizeOfRawData
);
}
//
// Next Section
//
Section += 1;
}
//
// Copy in CodeView information if it exists
//
if (CodeViewSize != 0) {
Status = EfiLdrPeCoffImageRead (FHand, CodeViewFileOffset, CodeViewSize, Image->ImageBase + CodeViewOffset);
DebugEntry->RVA = (UINT32) (CodeViewOffset);
}
//
// Apply relocations only if needed
//
if (PeHdr.Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
ImageBase = (UINT64)PeHdr.Pe32.OptionalHeader.ImageBase;
} else {
ImageBase = PeHdr.Pe32Plus.OptionalHeader.ImageBase;
}
if ((UINTN)(Image->ImageBase) != (UINTN) (ImageBase)) {
Status = EfiLdrPeCoffLoadPeRelocate (
Image,
&DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC],
(UINTN) Image->ImageBase - (UINTN)ImageBase,
NumberOfMemoryMapEntries,
EfiMemoryDescriptor
);
if (EFI_ERROR(Status)) {
PrintHeader ('N');
return Status;
}
}
//
// Use exported EFI specific interface if present, else use the image's entry point
//
Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)
(EfiLdrPeCoffImageAddress(
Image,
PeHdr.Pe32.OptionalHeader.AddressOfEntryPoint
));
return Status;
}
EFI_STATUS
EfiLdrPeCoffLoadPeRelocate (
IN EFILDR_LOADED_IMAGE *Image,
IN EFI_IMAGE_DATA_DIRECTORY *RelocDir,
IN UINTN Adjust,
IN UINTN *NumberOfMemoryMapEntries,
IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
)
{
EFI_IMAGE_BASE_RELOCATION *RelocBase;
EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd;
UINT16 *Reloc;
UINT16 *RelocEnd;
UINT8 *Fixup;
UINT8 *FixupBase;
UINT16 *F16;
UINT32 *F32;
UINT64 *F64;
UINT8 *FixupData;
UINTN NoFixupPages;
//
// Find the relocation block
//
RelocBase = EfiLdrPeCoffImageAddress (Image, RelocDir->VirtualAddress);
RelocBaseEnd = EfiLdrPeCoffImageAddress (Image, RelocDir->VirtualAddress + RelocDir->Size);
if (!RelocBase || !RelocBaseEnd) {
PrintHeader ('O');
return EFI_LOAD_ERROR;
}
NoFixupPages = EFI_SIZE_TO_PAGES(RelocDir->Size / sizeof(UINT16) * sizeof(UINTN));
Image->FixupData = (UINT8*) FindSpace (NoFixupPages, NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);
if (Image->FixupData == 0) {
return EFI_OUT_OF_RESOURCES;
}
//
// Run the whole relocation block
//
FixupData = Image->FixupData;
while (RelocBase < RelocBaseEnd) {
Reloc = (UINT16 *) ((UINT8 *) RelocBase + sizeof(EFI_IMAGE_BASE_RELOCATION));
RelocEnd = (UINT16 *) ((UINT8 *) RelocBase + RelocBase->SizeOfBlock);
FixupBase = EfiLdrPeCoffImageAddress (Image, RelocBase->VirtualAddress);
if ((UINT8 *) RelocEnd < Image->ImageBase || (UINT8 *) RelocEnd > Image->ImageEof) {
PrintHeader ('P');
return EFI_LOAD_ERROR;
}
//
// Run this relocation record
//
while (Reloc < RelocEnd) {
Fixup = FixupBase + (*Reloc & 0xFFF);
switch ((*Reloc) >> 12) {
case EFI_IMAGE_REL_BASED_ABSOLUTE:
break;
case EFI_IMAGE_REL_BASED_HIGH:
F16 = (UINT16 *) Fixup;
*F16 = (UINT16) (*F16 + (UINT16)(((UINT32)Adjust) >> 16));
if (FixupData != NULL) {
*(UINT16 *) FixupData = *F16;
FixupData = FixupData + sizeof(UINT16);
}
break;
case EFI_IMAGE_REL_BASED_LOW:
F16 = (UINT16 *) Fixup;
*F16 = (UINT16) (*F16 + (UINT16) Adjust);
if (FixupData != NULL) {
*(UINT16 *) FixupData = *F16;
FixupData = FixupData + sizeof(UINT16);
}
break;
case EFI_IMAGE_REL_BASED_HIGHLOW:
F32 = (UINT32 *) Fixup;
*F32 = *F32 + (UINT32) Adjust;
if (FixupData != NULL) {
FixupData = ALIGN_POINTER(FixupData, sizeof(UINT32));
*(UINT32 *) FixupData = *F32;
FixupData = FixupData + sizeof(UINT32);
}
break;
case EFI_IMAGE_REL_BASED_DIR64:
F64 = (UINT64 *) Fixup;
*F64 = *F64 + (UINT64) Adjust;
if (FixupData != NULL) {
FixupData = ALIGN_POINTER(FixupData, sizeof(UINT64));
*(UINT64 *) FixupData = *F64;
FixupData = FixupData + sizeof(UINT64);
}
break;
case EFI_IMAGE_REL_BASED_HIGHADJ:
CpuDeadLoop(); // BUGBUG: not done
break;
default:
// DEBUG((D_LOAD|D_ERROR, "PeRelocate: unknown fixed type\n"));
PrintHeader ('Q');
CpuDeadLoop();
return EFI_LOAD_ERROR;
}
// Next reloc record
Reloc += 1;
}
// next reloc block
RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd;
}
//
// Add Fixup data to whole Image (assume Fixup data just below the image), so that there is no hole in the descriptor.
// Because only NoPages or ImageBasePage will be used in EfiLoader(), we update these 2 fields.
//
Image->NoPages += NoFixupPages;
Image->ImageBasePage -= (NoFixupPages << EFI_PAGE_SHIFT);
return EFI_SUCCESS;
}
EFI_STATUS
EfiLdrPeCoffImageRead (
IN VOID *FHand,
IN UINTN Offset,
IN OUT UINTN ReadSize,
OUT VOID *Buffer
)
{
CopyMem (Buffer, (VOID *)((UINTN)FHand + Offset), ReadSize);
return EFI_SUCCESS;
}
VOID *
EfiLdrPeCoffImageAddress (
IN EFILDR_LOADED_IMAGE *Image,
IN UINTN Address
)
{
UINT8 *FixedAddress;
FixedAddress = Image->ImageAdjust + Address;
if ((FixedAddress < Image->ImageBase) || (FixedAddress > Image->ImageEof)) {
// DEBUG((D_LOAD|D_ERROR, "PeCoffImageAddress: pointer is outside of image\n"));
FixedAddress = NULL;
}
// DEBUG((
// D_LOAD,
// "PeCoffImageAddress: ImageBase %x, ImageEof %x, Address %x, FixedAddress %x\n",
// Image->ImageBase,
// Image->ImageEof,
// Address,
// FixedAddress
// ));
return FixedAddress;
}
EFI_STATUS
EfiLdrPeCoffSetImageType (
IN OUT EFILDR_LOADED_IMAGE *Image,
IN UINTN ImageType
)
{
EFI_MEMORY_TYPE CodeType;
EFI_MEMORY_TYPE DataType;
switch (ImageType) {
case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
CodeType = EfiLoaderCode;
DataType = EfiLoaderData;
break;
case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
CodeType = EfiBootServicesCode;
DataType = EfiBootServicesData;
break;
case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
CodeType = EfiRuntimeServicesCode;
DataType = EfiRuntimeServicesData;
break;
default:
return EFI_INVALID_PARAMETER;
}
Image->Type = ImageType;
Image->Info.ImageCodeType = CodeType;
Image->Info.ImageDataType = DataType;
return EFI_SUCCESS;
}
EFI_STATUS
EfiLdrPeCoffCheckImageMachineType (
IN UINT16 MachineType
)
{
EFI_STATUS Status;
Status = EFI_UNSUPPORTED;
#ifdef MDE_CPU_IA32
if (MachineType == EFI_IMAGE_MACHINE_IA32) {
Status = EFI_SUCCESS;
}
#endif
#ifdef MDE_CPU_X64
if (MachineType == EFI_IMAGE_MACHINE_X64) {
Status = EFI_SUCCESS;
}
#endif
return Status;
}

View File

@@ -1,42 +0,0 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeLoader.h
Abstract:
Revision History:
--*/
#ifndef _EFILDR_PELOADER_H_
#define _EFILDR_PELOADER_H_
#include "EfiLdr.h"
EFI_STATUS
EfiLdrGetPeImageInfo (
IN VOID *FHand,
OUT UINT64 *ImageBase,
OUT UINT32 *ImageSize
);
EFI_STATUS
EfiLdrPeCoffLoadPeImage (
IN VOID *FHand,
IN EFILDR_LOADED_IMAGE *Image,
IN UINTN *NumberOfMemoryMapEntries,
IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor
);
#endif

View File

@@ -1,237 +0,0 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Support.c
Abstract:
Revision History:
--*/
#include "EfiLdr.h"
EFI_STATUS
EfiAddMemoryDescriptor(
UINTN *NoDesc,
EFI_MEMORY_DESCRIPTOR *Desc,
EFI_MEMORY_TYPE Type,
EFI_PHYSICAL_ADDRESS BaseAddress,
UINT64 NoPages,
UINT64 Attribute
)
{
UINTN NumberOfDesc;
UINT64 Temp;
UINTN Index;
if (NoPages == 0) {
return EFI_SUCCESS;
}
//
// See if the new memory descriptor needs to be carved out of an existing memory descriptor
//
NumberOfDesc = *NoDesc;
for (Index = 0; Index < NumberOfDesc; Index++) {
if (Desc[Index].Type == EfiConventionalMemory) {
Temp = DivU64x32 ((BaseAddress - Desc[Index].PhysicalStart), EFI_PAGE_SIZE) + NoPages;
if ((Desc[Index].PhysicalStart < BaseAddress) && (Desc[Index].NumberOfPages >= Temp)) {
if (Desc[Index].NumberOfPages > Temp) {
Desc[*NoDesc].Type = EfiConventionalMemory;
Desc[*NoDesc].PhysicalStart = BaseAddress + MultU64x32 (NoPages, EFI_PAGE_SIZE);
Desc[*NoDesc].NumberOfPages = Desc[Index].NumberOfPages - Temp;
Desc[*NoDesc].VirtualStart = 0;
Desc[*NoDesc].Attribute = Desc[Index].Attribute;
*NoDesc = *NoDesc + 1;
}
Desc[Index].NumberOfPages = Temp - NoPages;
}
if ((Desc[Index].PhysicalStart == BaseAddress) && (Desc[Index].NumberOfPages == NoPages)) {
Desc[Index].Type = Type;
Desc[Index].Attribute = Attribute;
return EFI_SUCCESS;
}
if ((Desc[Index].PhysicalStart == BaseAddress) && (Desc[Index].NumberOfPages > NoPages)) {
Desc[Index].NumberOfPages -= NoPages;
Desc[Index].PhysicalStart += MultU64x32 (NoPages, EFI_PAGE_SIZE);
}
}
}
//
// Add the new memory descriptor
//
Desc[*NoDesc].Type = Type;
Desc[*NoDesc].PhysicalStart = BaseAddress;
Desc[*NoDesc].NumberOfPages = NoPages;
Desc[*NoDesc].VirtualStart = 0;
Desc[*NoDesc].Attribute = Attribute;
*NoDesc = *NoDesc + 1;
return EFI_SUCCESS;
}
UINTN
FindSpace (
UINTN NoPages,
IN UINTN *NumberOfMemoryMapEntries,
IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor,
EFI_MEMORY_TYPE Type,
UINT64 Attribute
)
{
EFI_PHYSICAL_ADDRESS MaxPhysicalStart;
UINT64 MaxNoPages;
UINTN Index;
EFI_MEMORY_DESCRIPTOR *CurrentMemoryDescriptor;
MaxPhysicalStart = 0;
MaxNoPages = 0;
CurrentMemoryDescriptor = NULL;
for (Index = 0; Index < *NumberOfMemoryMapEntries; Index++) {
if (EfiMemoryDescriptor[Index].PhysicalStart + LShiftU64(EfiMemoryDescriptor[Index].NumberOfPages, EFI_PAGE_SHIFT) <= 0x100000) {
continue;
}
if ((EfiMemoryDescriptor[Index].Type == EfiConventionalMemory) &&
(EfiMemoryDescriptor[Index].NumberOfPages >= NoPages)) {
if (EfiMemoryDescriptor[Index].PhysicalStart > MaxPhysicalStart) {
if (EfiMemoryDescriptor[Index].PhysicalStart + LShiftU64(EfiMemoryDescriptor[Index].NumberOfPages, EFI_PAGE_SHIFT) <= 0x100000000ULL) {
MaxPhysicalStart = EfiMemoryDescriptor[Index].PhysicalStart;
MaxNoPages = EfiMemoryDescriptor[Index].NumberOfPages;
CurrentMemoryDescriptor = &EfiMemoryDescriptor[Index];
}
}
}
if ((EfiMemoryDescriptor[Index].Type == EfiReservedMemoryType) ||
(EfiMemoryDescriptor[Index].Type >= EfiACPIReclaimMemory) ) {
continue;
}
if ((EfiMemoryDescriptor[Index].Type == EfiRuntimeServicesCode) ||
(EfiMemoryDescriptor[Index].Type == EfiRuntimeServicesData)) {
break;
}
}
if (MaxPhysicalStart == 0) {
return 0;
}
if (MaxNoPages != NoPages) {
CurrentMemoryDescriptor->NumberOfPages = MaxNoPages - NoPages;
EfiMemoryDescriptor[*NumberOfMemoryMapEntries].Type = Type;
EfiMemoryDescriptor[*NumberOfMemoryMapEntries].PhysicalStart = MaxPhysicalStart + LShiftU64(MaxNoPages - NoPages, EFI_PAGE_SHIFT);
EfiMemoryDescriptor[*NumberOfMemoryMapEntries].NumberOfPages = NoPages;
EfiMemoryDescriptor[*NumberOfMemoryMapEntries].VirtualStart = 0;
EfiMemoryDescriptor[*NumberOfMemoryMapEntries].Attribute = Attribute;
*NumberOfMemoryMapEntries = *NumberOfMemoryMapEntries + 1;
} else {
CurrentMemoryDescriptor->Type = Type;
CurrentMemoryDescriptor->Attribute = Attribute;
}
return (UINTN)(MaxPhysicalStart + LShiftU64(MaxNoPages - NoPages, EFI_PAGE_SHIFT));
}
VOID
GenMemoryMap (
UINTN *NumberOfMemoryMapEntries,
EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor,
BIOS_MEMORY_MAP *BiosMemoryMap
)
{
UINT64 BaseAddress;
UINT64 Length;
EFI_MEMORY_TYPE Type;
UINTN Index;
UINTN Attr;
UINT64 Ceiling;
Ceiling = 0xFFFFFFFF;
for (Index = 0; Index < BiosMemoryMap->MemoryMapSize / sizeof(BIOS_MEMORY_MAP_ENTRY); Index++) {
switch (BiosMemoryMap->MemoryMapEntry[Index].Type) {
case (INT15_E820_AddressRangeMemory):
Type = EfiConventionalMemory;
Attr = EFI_MEMORY_WB;
break;
case (INT15_E820_AddressRangeReserved):
Type = EfiReservedMemoryType;
Attr = EFI_MEMORY_UC;
break;
case (INT15_E820_AddressRangeACPI):
Type = EfiACPIReclaimMemory;
Attr = EFI_MEMORY_WB;
break;
case (INT15_E820_AddressRangeNVS):
Type = EfiACPIMemoryNVS;
Attr = EFI_MEMORY_UC;
break;
default:
// We should not get here, according to ACPI 2.0 Spec.
// BIOS behaviour of the Int15h, E820h
Type = EfiReservedMemoryType;
Attr = EFI_MEMORY_UC;
break;
}
if (Type == EfiConventionalMemory) {
BaseAddress = BiosMemoryMap->MemoryMapEntry[Index].BaseAddress;
Length = BiosMemoryMap->MemoryMapEntry[Index].Length;
if (BaseAddress & EFI_PAGE_MASK) {
Length = Length + (BaseAddress & EFI_PAGE_MASK) - EFI_PAGE_SIZE;
BaseAddress = LShiftU64 (RShiftU64 (BaseAddress, EFI_PAGE_SHIFT) + 1, EFI_PAGE_SHIFT);
}
} else {
BaseAddress = BiosMemoryMap->MemoryMapEntry[Index].BaseAddress;
Length = BiosMemoryMap->MemoryMapEntry[Index].Length + (BaseAddress & EFI_PAGE_MASK);
BaseAddress = LShiftU64 (RShiftU64 (BaseAddress, EFI_PAGE_SHIFT), EFI_PAGE_SHIFT);
if (Length & EFI_PAGE_MASK) {
Length = LShiftU64 (RShiftU64 (Length, EFI_PAGE_SHIFT) + 1, EFI_PAGE_SHIFT);
}
//
// Update Memory Ceiling
//
if ((BaseAddress >= 0x100000) && (BaseAddress < 0x100000000ULL)) {
if (Ceiling > BaseAddress) {
Ceiling = BaseAddress;
}
}
}
EfiAddMemoryDescriptor (
NumberOfMemoryMapEntries,
EfiMemoryDescriptor,
Type,
(EFI_PHYSICAL_ADDRESS)BaseAddress,
RShiftU64 (Length, EFI_PAGE_SHIFT),
Attr
);
}
//
// Update MemoryMap according to Ceiling
//
for (Index = 0; Index < *NumberOfMemoryMapEntries; Index++) {
if ((EfiMemoryDescriptor[Index].Type == EfiConventionalMemory) &&
(EfiMemoryDescriptor[Index].PhysicalStart > 0x100000) &&
(EfiMemoryDescriptor[Index].PhysicalStart < 0x100000000ULL)) {
if (EfiMemoryDescriptor[Index].PhysicalStart >= Ceiling) {
EfiMemoryDescriptor[Index].Type = EfiReservedMemoryType;
}
}
}
}

View File

@@ -1,50 +0,0 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Support.h
Abstract:
Revision History:
--*/
#ifndef _EFILDR_SUPPORT_H_
#define _EFILDR_SUPPORT_H_
EFI_STATUS
EfiAddMemoryDescriptor(
UINTN *NoDesc,
EFI_MEMORY_DESCRIPTOR *Desc,
EFI_MEMORY_TYPE Type,
EFI_PHYSICAL_ADDRESS BaseAddress,
UINT64 NoPages,
UINT64 Attribute
);
UINTN
FindSpace(
UINTN NoPages,
IN UINTN *NumberOfMemoryMapEntries,
IN EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor,
EFI_MEMORY_TYPE Type,
UINT64 Attribute
);
VOID
GenMemoryMap (
UINTN *NumberOfMemoryMapEntries,
EFI_MEMORY_DESCRIPTOR *EfiMemoryDescriptor,
BIOS_MEMORY_MAP *BiosMemoryMap
);
#endif

View File

@@ -1,990 +0,0 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Decompress.c
Abstract:
Decompressor. Algorithm Ported from OPSD code (Decomp.asm)
--*/
#include <TianoDecompress.h>
//
// Decompression algorithm begins here
//
#define BITBUFSIZ 32
#define MAXMATCH 256
#define THRESHOLD 3
#define CODE_BIT 16
#define BAD_TABLE - 1
//
// C: Char&Len Set; P: Position Set; T: exTra Set
//
#define NC (0xff + MAXMATCH + 2 - THRESHOLD)
#define CBIT 9
#define MAXPBIT 5
#define TBIT 5
#define MAXNP ((1U << MAXPBIT) - 1)
#define NT (CODE_BIT + 3)
#if NT > MAXNP
#define NPT NT
#else
#define NPT MAXNP
#endif
typedef struct {
UINT8 *mSrcBase; // Starting address of compressed data
UINT8 *mDstBase; // Starting address of decompressed data
UINT32 mOutBuf;
UINT32 mInBuf;
UINT16 mBitCount;
UINT32 mBitBuf;
UINT32 mSubBitBuf;
UINT16 mBlockSize;
UINT32 mCompSize;
UINT32 mOrigSize;
UINT16 mBadTableFlag;
UINT16 mLeft[2 * NC - 1];
UINT16 mRight[2 * NC - 1];
UINT8 mCLen[NC];
UINT8 mPTLen[NPT];
UINT16 mCTable[4096];
UINT16 mPTTable[256];
//
// The length of the field 'Position Set Code Length Array Size' in Block Header.
// For EFI 1.1 de/compression algorithm, mPBit = 4
// For Tiano de/compression algorithm, mPBit = 5
//
UINT8 mPBit;
} SCRATCH_DATA;
VOID
FillBuf (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfBits
)
/*++
Routine Description:
Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
Arguments:
Sd - The global scratch data
NumOfBits - The number of bits to shift and read.
Returns: (VOID)
--*/
{
Sd->mBitBuf = (UINT32) LShiftU64 (((UINT64)Sd->mBitBuf), NumOfBits);
while (NumOfBits > Sd->mBitCount) {
NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount);
Sd->mBitBuf |= (UINT32) LShiftU64 (((UINT64)Sd->mSubBitBuf), NumOfBits);
if (Sd->mCompSize > 0) {
//
// Get 1 byte into SubBitBuf
//
Sd->mCompSize--;
Sd->mSubBitBuf = 0;
Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
Sd->mBitCount = 8;
} else {
//
// No more bits from the source, just pad zero bit.
//
Sd->mSubBitBuf = 0;
Sd->mBitCount = 8;
}
}
Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
}
UINT32
GetBits (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfBits
)
/*++
Routine Description:
Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
NumOfBits of bits from source. Returns NumOfBits of bits that are
popped out.
Arguments:
Sd - The global scratch data.
NumOfBits - The number of bits to pop and read.
Returns:
The bits that are popped out.
--*/
{
UINT32 OutBits;
OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
FillBuf (Sd, NumOfBits);
return OutBits;
}
UINT16
MakeTable (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfChar,
IN UINT8 *BitLen,
IN UINT16 TableBits,
OUT UINT16 *Table
)
/*++
Routine Description:
Creates Huffman Code mapping table according to code length array.
Arguments:
Sd - The global scratch data
NumOfChar - Number of symbols in the symbol set
BitLen - Code length array
TableBits - The width of the mapping table
Table - The table
Returns:
0 - OK.
BAD_TABLE - The table is corrupted.
--*/
{
UINT16 Count[17];
UINT16 Weight[17];
UINT16 Start[18];
UINT16 *Pointer;
UINT16 Index3;
volatile UINT16 Index;
UINT16 Len;
UINT16 Char;
UINT16 JuBits;
UINT16 Avail;
UINT16 NextCode;
UINT16 Mask;
UINT16 WordOfStart;
UINT16 WordOfCount;
for (Index = 1; Index <= 16; Index++) {
Count[Index] = 0;
}
for (Index = 0; Index < NumOfChar; Index++) {
Count[BitLen[Index]]++;
}
Start[1] = 0;
for (Index = 1; Index <= 16; Index++) {
WordOfStart = Start[Index];
WordOfCount = Count[Index];
Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index)));
}
if (Start[17] != 0) {
/*(1U << 16)*/
return (UINT16) BAD_TABLE;
}
JuBits = (UINT16) (16 - TableBits);
for (Index = 1; Index <= TableBits; Index++) {
Start[Index] >>= JuBits;
Weight[Index] = (UINT16) (1U << (TableBits - Index));
}
while (Index <= 16) {
Weight[Index] = (UINT16) (1U << (16 - Index));
Index++;
}
Index = (UINT16) (Start[TableBits + 1] >> JuBits);
if (Index != 0) {
Index3 = (UINT16) (1U << TableBits);
while (Index != Index3) {
Table[Index++] = 0;
}
}
Avail = NumOfChar;
Mask = (UINT16) (1U << (15 - TableBits));
for (Char = 0; Char < NumOfChar; Char++) {
Len = BitLen[Char];
if (Len == 0) {
continue;
}
NextCode = (UINT16) (Start[Len] + Weight[Len]);
if (Len <= TableBits) {
for (Index = Start[Len]; Index < NextCode; Index++) {
Table[Index] = Char;
}
} else {
Index3 = Start[Len];
Pointer = &Table[Index3 >> JuBits];
Index = (UINT16) (Len - TableBits);
while (Index != 0) {
if (*Pointer == 0) {
Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
*Pointer = Avail++;
}
if (Index3 & Mask) {
Pointer = &Sd->mRight[*Pointer];
} else {
Pointer = &Sd->mLeft[*Pointer];
}
Index3 <<= 1;
Index--;
}
*Pointer = Char;
}
Start[Len] = NextCode;
}
//
// Succeeds
//
return 0;
}
UINT32
DecodeP (
IN SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decodes a position value.
Arguments:
Sd - the global scratch data
Returns:
The position value decoded.
--*/
{
UINT16 Val;
UINT32 Mask;
UINT32 Pos;
Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
if (Val >= MAXNP) {
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Sd->mBitBuf & Mask) {
Val = Sd->mRight[Val];
} else {
Val = Sd->mLeft[Val];
}
Mask >>= 1;
} while (Val >= MAXNP);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mPTLen[Val]);
Pos = Val;
if (Val > 1) {
Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
}
return Pos;
}
UINT16
ReadPTLen (
IN SCRATCH_DATA *Sd,
IN UINT16 nn,
IN UINT16 nbit,
IN UINT16 Special
)
/*++
Routine Description:
Reads code lengths for the Extra Set or the Position Set
Arguments:
Sd - The global scratch data
nn - Number of symbols
nbit - Number of bits needed to represent nn
Special - The special symbol that needs to be taken care of
Returns:
0 - OK.
BAD_TABLE - Table is corrupted.
--*/
{
UINT16 Number;
UINT16 CharC;
volatile UINT16 Index;
UINT32 Mask;
Number = (UINT16) GetBits (Sd, nbit);
if (Number == 0) {
CharC = (UINT16) GetBits (Sd, nbit);
for (Index = 0; Index < 256; Index++) {
Sd->mPTTable[Index] = CharC;
}
for (Index = 0; Index < nn; Index++) {
Sd->mPTLen[Index] = 0;
}
return 0;
}
Index = 0;
while (Index < Number) {
CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
if (CharC == 7) {
Mask = 1U << (BITBUFSIZ - 1 - 3);
while (Mask & Sd->mBitBuf) {
Mask >>= 1;
CharC += 1;
}
}
FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
Sd->mPTLen[Index++] = (UINT8) CharC;
if (Index == Special) {
CharC = (UINT16) GetBits (Sd, 2);
while ((INT16) (--CharC) >= 0) {
Sd->mPTLen[Index++] = 0;
}
}
}
while (Index < nn) {
Sd->mPTLen[Index++] = 0;
}
return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
}
VOID
ReadCLen (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Reads code lengths for Char&Len Set.
Arguments:
Sd - the global scratch data
Returns: (VOID)
--*/
{
UINT16 Number;
UINT16 CharC;
volatile UINT16 Index;
UINT32 Mask;
Number = (UINT16) GetBits (Sd, CBIT);
if (Number == 0) {
CharC = (UINT16) GetBits (Sd, CBIT);
for (Index = 0; Index < NC; Index++) {
Sd->mCLen[Index] = 0;
}
for (Index = 0; Index < 4096; Index++) {
Sd->mCTable[Index] = CharC;
}
return ;
}
Index = 0;
while (Index < Number) {
CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
if (CharC >= NT) {
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Mask & Sd->mBitBuf) {
CharC = Sd->mRight[CharC];
} else {
CharC = Sd->mLeft[CharC];
}
Mask >>= 1;
} while (CharC >= NT);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mPTLen[CharC]);
if (CharC <= 2) {
if (CharC == 0) {
CharC = 1;
} else if (CharC == 1) {
CharC = (UINT16) (GetBits (Sd, 4) + 3);
} else if (CharC == 2) {
CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
}
while ((INT16) (--CharC) >= 0) {
Sd->mCLen[Index++] = 0;
}
} else {
Sd->mCLen[Index++] = (UINT8) (CharC - 2);
}
}
while (Index < NC) {
Sd->mCLen[Index++] = 0;
}
MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
return ;
}
UINT16
DecodeC (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decode a character/length value.
Arguments:
Sd - The global scratch data.
Returns:
The value decoded.
--*/
{
UINT16 Index2;
UINT32 Mask;
if (Sd->mBlockSize == 0) {
//
// Starting a new block
//
Sd->mBlockSize = (UINT16) GetBits (Sd, 16);
Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
if (Sd->mBadTableFlag != 0) {
return 0;
}
ReadCLen (Sd);
Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));
if (Sd->mBadTableFlag != 0) {
return 0;
}
}
Sd->mBlockSize--;
Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
if (Index2 >= NC) {
Mask = 1U << (BITBUFSIZ - 1 - 12);
do {
if (Sd->mBitBuf & Mask) {
Index2 = Sd->mRight[Index2];
} else {
Index2 = Sd->mLeft[Index2];
}
Mask >>= 1;
} while (Index2 >= NC);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mCLen[Index2]);
return Index2;
}
VOID
Decode (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decode the source data and put the resulting data into the destination buffer.
Arguments:
Sd - The global scratch data
Returns: (VOID)
--*/
{
UINT16 BytesRemain;
UINT32 DataIdx;
UINT16 CharC;
BytesRemain = (UINT16) (-1);
DataIdx = 0;
for (;;) {
CharC = DecodeC (Sd);
if (Sd->mBadTableFlag != 0) {
goto Done ;
}
if (CharC < 256) {
//
// Process an Original character
//
if (Sd->mOutBuf >= Sd->mOrigSize) {
goto Done ;
} else {
Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
}
} else {
//
// Process a Pointer
//
CharC = (UINT16) (CharC - (BIT8 - THRESHOLD));
BytesRemain = CharC;
DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;
BytesRemain--;
while ((INT16) (BytesRemain) >= 0) {
Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
if (Sd->mOutBuf >= Sd->mOrigSize) {
goto Done ;
}
BytesRemain--;
}
}
}
Done:
return ;
}
EFI_STATUS
GetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
UINT8 *Src;
*ScratchSize = sizeof (SCRATCH_DATA);
Src = Source;
if (SrcSize < 8) {
return EFI_INVALID_PARAMETER;
}
*DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
return EFI_SUCCESS;
}
EFI_STATUS
Decompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize,
IN UINT8 Version
)
/*++
Routine Description:
The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Version - The version of de/compression algorithm.
Version 1 for EFI 1.1 de/compression algorithm.
Version 2 for Tiano de/compression algorithm.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
UINT32 CompSize;
UINT32 OrigSize;
EFI_STATUS Status;
SCRATCH_DATA *Sd;
UINT8 *Src;
UINT8 *Dst;
volatile UINT32 Index;
Status = EFI_SUCCESS;
Src = Source;
Dst = Destination;
if (ScratchSize < sizeof (SCRATCH_DATA)) {
return EFI_INVALID_PARAMETER;
}
Sd = (SCRATCH_DATA *) Scratch;
if (SrcSize < 8) {
return EFI_INVALID_PARAMETER;
}
CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
//
// If compressed file size is 0, return
//
if (OrigSize == 0) {
return Status;
}
if (SrcSize < CompSize + 8) {
return EFI_INVALID_PARAMETER;
}
if (DstSize != OrigSize) {
return EFI_INVALID_PARAMETER;
}
Src = Src + 8;
for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {
((UINT8 *) Sd)[Index] = 0;
}
//
// The length of the field 'Position Set Code Length Array Size' in Block Header.
// For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4
// For Tiano de/compression algorithm(Version 2), mPBit = 5
//
switch (Version) {
case 1:
Sd->mPBit = 4;
break;
case 2:
Sd->mPBit = 5;
break;
default:
//
// Currently, only have 2 versions
//
return EFI_INVALID_PARAMETER;
}
Sd->mSrcBase = Src;
Sd->mDstBase = Dst;
Sd->mCompSize = CompSize;
Sd->mOrigSize = OrigSize;
//
// Fill the first BITBUFSIZ bits
//
FillBuf (Sd, BITBUFSIZ);
//
// Decompress it
//
Decode (Sd);
if (Sd->mBadTableFlag != 0) {
//
// Something wrong with the source
//
Status = EFI_INVALID_PARAMETER;
}
return Status;
}
EFI_STATUS
EFIAPI
EfiGetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
return GetInfo (
Source,
SrcSize,
DstSize,
ScratchSize
);
}
EFI_STATUS
EFIAPI
EfiDecompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
/*++
Routine Description:
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
//
// For EFI 1.1 de/compression algorithm, the version is 1.
//
return Decompress (
Source,
SrcSize,
Destination,
DstSize,
Scratch,
ScratchSize,
1
);
}
EFI_STATUS
EFIAPI
TianoGetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
return GetInfo (
Source,
SrcSize,
DstSize,
ScratchSize
);
}
EFI_STATUS
EFIAPI
TianoDecompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
/*++
Routine Description:
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
//
// For Tiano de/compression algorithm, the version is 2.
//
return Decompress (
Source,
SrcSize,
Destination,
DstSize,
Scratch,
ScratchSize,
2
);
}

View File

@@ -1,90 +0,0 @@
/** @file
Internal include file for Base UEFI Decompress Library.
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: BaseUefiCustomDecompressLibInternals.h
**/
#ifndef __BASE_UEFI_TIANO_CUSTOM_DECOMPRESS_LIB_INTERNALS_H__
#define __BASE_UEFI_TIANO_CUSTOM_DECOMPRESS_LIB_INTERNALS_H__
#include <PiPei.h>
#include <Library/UefiDecompressLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
EFI_STATUS
EFIAPI
TianoGetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
;
EFI_STATUS
EFIAPI
TianoDecompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
/*++
Routine Description:
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
;
#endif

View File

@@ -1,28 +0,0 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiLdr.c
Abstract:
Revision History:
--*/
//
// BUGBUG, include all C files
//
#include "EfiLoader.c"
#include "PeLoader.c"
#include "Support.c"
#include "Debug.c"

File diff suppressed because it is too large Load Diff

View File

@@ -1,162 +0,0 @@
/*++
Caution: This file is used for Duet platform only, do not use them in real platform.
All variable code, variable metadata, and variable data used by Duet platform are on
disk. They can be changed by user. BIOS is not able to protoect those.
Duet trusts all meta data from disk. If variable code, variable metadata and variable
data is modified in inproper way, the behavior is undefined.
Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FSVariable.h
Abstract:
--*/
#ifndef _FS_VARIABLE_H
#define _FS_VARIABLE_H
//
// Statements that include other header files
//
#include <PiDxe.h>
#include <Library/BaseLib.h>
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Library/HobLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Guid/HobList.h>
#include <Guid/FlashMapHob.h>
#include <Guid/VariableFormat.h>
#include <Guid/GlobalVariable.h>
#include <Protocol/Variable.h>
#include <Protocol/VariableWrite.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/BlockIo.h>
#include "EfiFlashMap.h"
#include "VariableStorage.h"
#define VOLATILE_VARIABLE_STORE_SIZE FixedPcdGet32(PcdVariableStoreSize)
#define VARIABLE_SCRATCH_SIZE MAX(FixedPcdGet32(PcdMaxVariableSize), FixedPcdGet32(PcdMaxHardwareErrorVariableSize))
#define VARIABLE_RECLAIM_THRESHOLD (1024)
///
/// The size of a 3 character ISO639 language code.
///
#define ISO_639_2_ENTRY_SIZE 3
#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
typedef enum {
Physical,
Virtual
} VARIABLE_POINTER_TYPE;
typedef enum {
NonVolatile,
Volatile,
MaxType
} VARIABLE_STORAGE_TYPE;
typedef struct {
VARIABLE_HEADER *CurrPtr;
VARIABLE_HEADER *EndPtr;
VARIABLE_HEADER *StartPtr;
VARIABLE_STORAGE_TYPE Type;
} VARIABLE_POINTER_TRACK;
#define VARIABLE_MEMBER_OFFSET(Member, StartOffset) \
( sizeof (VARIABLE_STORE_HEADER) + (StartOffset) + \
(UINTN) ((UINT8 *) &((VARIABLE_HEADER*) 0)->Member - (UINT8 *) &((VARIABLE_HEADER*) 0)->StartId) \
)
typedef struct {
EFI_EVENT_NOTIFY GoVirtualChildEvent[MaxType];
VARIABLE_STORAGE *VariableStore[MaxType]; // Instance of VariableStorage
VOID *VariableBase[MaxType]; // Start address of variable storage
UINTN LastVariableOffset[MaxType]; // The position to write new variable to (index from VariableBase)
VOID *Scratch; // Buffer used during reclaim
UINTN CommonVariableTotalSize;
UINTN HwErrVariableTotalSize;
CHAR8 *PlatformLangCodes;
CHAR8 *LangCodes;
CHAR8 *PlatformLang;
CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];
} VARIABLE_GLOBAL;
//
// Functions
//
EFI_STATUS
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
VOID
EFIAPI
VariableClassAddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
EFIAPI
DuetGetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
);
EFI_STATUS
EFIAPI
GetNextVariableName (
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid
);
EFI_STATUS
EFIAPI
SetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
);
EFI_STATUS
EFIAPI
QueryVariableInfo (
IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize
);
#endif

View File

@@ -1,80 +0,0 @@
## @file
#
# Caution: This file is used for Duet platform only, do not use them in real platform.
# All variable code, variable metadata, and variable data used by Duet platform are on
# disk. They can be changed by user. BIOS is not able to protoect those.
# Duet trusts all meta data from disk. If variable code, variable metadata and variable
# data is modified in inproper way, the behavior is undefined.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# FSVariable.inf
#
# Abstract:
#
# Component description file for variable module
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = FSVariable
FILE_GUID = A36495C1-C205-414e-B71F-4BE3476D699C
MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = VariableServiceInitialize
[Packages]
MdePkg/MdePkg.dec
DuetPkg/DuetPkg.dec
MdeModulePkg/MdeModulePkg.dec
[Sources]
FSVariable.h
VariableStorage.h
FSVariable.c
FileStorage.c
MemStorage.c
[LibraryClasses]
PcdLib
BaseMemoryLib
BaseLib
UefiBootServicesTableLib
UefiRuntimeLib
DebugLib
UefiLib
HobLib
DxeServicesTableLib
DevicePathLib
UefiDriverEntryPoint
MemoryAllocationLib
[Guids]
gEfiFlashMapHobGuid
gEfiVariableGuid
gEfiGlobalVariableGuid ## PRODUCES ## Variable Guid
[Protocols]
gEfiVariableArchProtocolGuid
gEfiVariableWriteArchProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEfiBlockIoProtocolGuid
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize
gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize
[Depex]
TRUE

View File

@@ -1,437 +0,0 @@
/*++
Caution: This file is used for Duet platform only, do not use them in real platform.
All variable code, variable metadata, and variable data used by Duet platform are on
disk. They can be changed by user. BIOS is not able to protoect those.
Duet trusts all meta data from disk. If variable code, variable metadata and variable
data is modified in inproper way, the behavior is undefined.
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FileStorage.c
Abstract:
handles variable store/reads on file
Revision History
--*/
#include "FSVariable.h"
VOID *mSFSRegistration;
//
// Prototypes
//
VOID
EFIAPI
OnVirtualAddressChangeFs (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
EFIAPI
FileEraseStore(
IN VARIABLE_STORAGE *This
);
EFI_STATUS
EFIAPI
FileWriteStore (
IN VARIABLE_STORAGE *This,
IN UINTN Offset,
IN UINTN BufferSize,
IN VOID *Buffer
);
EFI_STATUS
OpenStore (
IN EFI_DEVICE_PATH_PROTOCOL *Device,
IN CHAR16 *FilePathName,
IN UINT64 OpenMode,
OUT EFI_FILE_PROTOCOL **File
);
//
// Implementation below:
//
VOID
FileClose (
IN EFI_FILE_PROTOCOL *File
)
{
EFI_STATUS Status;
Status = File->Flush (File);
ASSERT_EFI_ERROR (Status);
Status = File->Close (File);
ASSERT_EFI_ERROR (Status);
}
EFI_STATUS
CheckStore (
IN EFI_HANDLE SimpleFileSystemHandle,
IN UINT32 VolumeId,
OUT EFI_DEVICE_PATH_PROTOCOL **Device
)
{
#define BLOCK_SIZE 0x200
#define FAT16_VOLUME_ID_OFFSET 39
#define FAT32_VOLUME_ID_OFFSET 67
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlkIo;
UINT8 BootSector[BLOCK_SIZE];
*Device = NULL;
Status = gBS->HandleProtocol (
SimpleFileSystemHandle,
&gEfiBlockIoProtocolGuid, // BlockIo should be supported if it supports SimpleFileSystem
(VOID*)&BlkIo
);
if (EFI_ERROR (Status)) {
goto ErrHandle;
}
if (!BlkIo->Media->MediaPresent) {
DEBUG ((EFI_D_ERROR, "FileStorage: Media not present!\n"));
Status = EFI_NO_MEDIA;
goto ErrHandle;
}
if (BlkIo->Media->ReadOnly) {
DEBUG ((EFI_D_ERROR, "FileStorage: Media is read-only!\n"));
Status = EFI_ACCESS_DENIED;
goto ErrHandle;
}
Status = BlkIo->ReadBlocks(
BlkIo,
BlkIo->Media->MediaId,
0,
BLOCK_SIZE,
BootSector
);
ASSERT_EFI_ERROR (Status);
if ((*(UINT32 *) &BootSector[FAT16_VOLUME_ID_OFFSET] != VolumeId) &&
(*(UINT32 *) &BootSector[FAT32_VOLUME_ID_OFFSET] != VolumeId)
) {
Status = EFI_NOT_FOUND;
goto ErrHandle;
}
*Device = DuplicateDevicePath (DevicePathFromHandle (SimpleFileSystemHandle));
ASSERT (*Device != NULL);
ErrHandle:
return Status;
}
EFI_STATUS
CheckStoreExists (
IN EFI_DEVICE_PATH_PROTOCOL *Device
)
{
EFI_HANDLE Handle;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_STATUS Status;
Status = gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&Device,
&Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->HandleProtocol (
Handle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID **) &Volume
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
// this routine is still running in BS period, no limitation
// call FileInitStorage(), which load variable content file to memory
// read the store_header, init store_header if it has not been inited (read sth. about format/heathy)
// reclaim space using scratch memory
VOID
EFIAPI
OnSimpleFileSystemInstall (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
UINTN HandleSize;
EFI_HANDLE Handle;
EFI_DEVICE_PATH_PROTOCOL *Device;
VS_DEV *Dev;
EFI_FILE_PROTOCOL *File;
UINTN NumBytes;
Dev = (VS_DEV *) Context;
if (VAR_FILE_DEVICEPATH (Dev) != NULL &&
!EFI_ERROR (CheckStoreExists (VAR_FILE_DEVICEPATH (Dev)))
) {
DEBUG ((EFI_D_ERROR, "FileStorage: Already mapped!\n"));
return ;
}
while (TRUE) {
HandleSize = sizeof (EFI_HANDLE);
Status = gBS->LocateHandle (
ByRegisterNotify,
NULL,
mSFSRegistration,
&HandleSize,
&Handle
);
if (EFI_ERROR (Status)) {
return ;
}
Status = CheckStore (Handle, VAR_FILE_VOLUMEID (Dev), &Device);
if (!EFI_ERROR (Status)) {
break;
}
}
VAR_FILE_DEVICEPATH (Dev) = Device;
Status = OpenStore (
VAR_FILE_DEVICEPATH (Dev),
VAR_FILE_FILEPATH (Dev),
EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ | EFI_FILE_MODE_CREATE,
&File
);
ASSERT_EFI_ERROR (Status);
NumBytes = Dev->Size;
Status = File->Write (File, &NumBytes, VAR_DATA_PTR (Dev));
ASSERT_EFI_ERROR (Status);
FileClose (File);
DEBUG ((EFI_D_ERROR, "FileStorage: Mapped to file!\n"));
}
EFI_STATUS
FileStorageConstructor (
OUT VARIABLE_STORAGE **VarStore,
OUT EFI_EVENT_NOTIFY *GoVirtualEvent,
IN EFI_PHYSICAL_ADDRESS NvStorageBase,
IN UINTN Size,
IN UINT32 VolumeId,
IN CHAR16 *FilePath
)
{
VS_DEV *Dev;
EFI_STATUS Status;
EFI_EVENT Event;
Status = gBS->AllocatePool (EfiRuntimeServicesData, sizeof(VS_DEV), (VOID **) &Dev);
ASSERT_EFI_ERROR (Status);
ZeroMem (Dev, sizeof(VS_DEV));
Dev->Signature = VS_DEV_SIGNATURE;
Dev->Size = Size;
VAR_DATA_PTR (Dev) = (UINT8 *) (UINTN) NvStorageBase;
VAR_FILE_VOLUMEID (Dev) = VolumeId;
StrCpy (VAR_FILE_FILEPATH (Dev), FilePath);
Dev->VarStore.Erase = FileEraseStore;
Dev->VarStore.Write = FileWriteStore;
DEBUG ((EFI_D_ERROR, "FileStorageConstructor(0x%0x:0x%0x): added!\n", NvStorageBase, Size));
// add notify on SFS's installation.
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
OnSimpleFileSystemInstall,
Dev,
&Event
);
ASSERT_EFI_ERROR (Status);
Status = gBS->RegisterProtocolNotify (
&gEfiSimpleFileSystemProtocolGuid,
Event,
&mSFSRegistration
);
ASSERT_EFI_ERROR (Status);
*VarStore = &Dev->VarStore;
*GoVirtualEvent = OnVirtualAddressChangeFs;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FileEraseStore(
IN VARIABLE_STORAGE *This
)
{
EFI_STATUS Status;
VS_DEV *Dev;
EFI_FILE_PROTOCOL *File;
UINTN NumBytes;
Status = EFI_SUCCESS;
Dev = DEV_FROM_THIS(This);
SetMem (VAR_DATA_PTR (Dev), Dev->Size, VAR_DEFAULT_VALUE);
if (!EfiAtRuntime () && VAR_FILE_DEVICEPATH (Dev) != NULL) {
Status = OpenStore (
VAR_FILE_DEVICEPATH (Dev),
VAR_FILE_FILEPATH (Dev),
EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ,
&File
);
ASSERT_EFI_ERROR (Status);
NumBytes = Dev->Size;
Status = File->Write (File, &NumBytes, VAR_DATA_PTR (Dev));
ASSERT_EFI_ERROR (Status);
FileClose (File);
}
return Status;
}
EFI_STATUS
EFIAPI
FileWriteStore (
IN VARIABLE_STORAGE *This,
IN UINTN Offset,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
VS_DEV *Dev;
EFI_FILE_PROTOCOL *File;
Status = EFI_SUCCESS;
Dev = DEV_FROM_THIS(This);
ASSERT (Buffer != NULL);
ASSERT (Offset + BufferSize <= Dev->Size);
CopyMem (VAR_DATA_PTR (Dev) + Offset, Buffer, BufferSize);
if (!EfiAtRuntime () && VAR_FILE_DEVICEPATH (Dev) != NULL) {
Status = OpenStore (
VAR_FILE_DEVICEPATH (Dev),
VAR_FILE_FILEPATH (Dev),
EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ,
&File
);
Status = File->SetPosition (File, Offset);
ASSERT_EFI_ERROR (Status);
Status = File->Write (File, &BufferSize, Buffer);
ASSERT_EFI_ERROR (Status);
FileClose (File);
}
return Status;
}
VOID
EFIAPI
OnVirtualAddressChangeFs (
IN EFI_EVENT Event,
IN VOID *Context
)
{
VS_DEV *Dev;
Dev = DEV_FROM_THIS (Context);
EfiConvertPointer (0, (VOID **) &VAR_DATA_PTR (Dev));
EfiConvertPointer (0, (VOID **) &Dev->VarStore.Erase);
EfiConvertPointer (0, (VOID **) &Dev->VarStore.Write);
}
EFI_STATUS
OpenStore (
IN EFI_DEVICE_PATH_PROTOCOL *Device,
IN CHAR16 *FilePathName,
IN UINT64 OpenMode,
OUT EFI_FILE_PROTOCOL **File
)
{
EFI_HANDLE Handle;
EFI_FILE_HANDLE Root;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_STATUS Status;
*File = NULL;
Status = gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&Device,
&Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->HandleProtocol (
Handle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID **) &Volume
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open the root directory of the volume
//
Root = NULL;
Status = Volume->OpenVolume (
Volume,
&Root
);
ASSERT_EFI_ERROR (Status);
ASSERT (Root != NULL);
//
// Open file
//
Status = Root->Open (
Root,
File,
FilePathName,
OpenMode,
0
);
if (EFI_ERROR (Status)) {
*File = NULL;
}
//
// Close the Root directory
//
Root->Close (Root);
return Status;
}

View File

@@ -1,135 +0,0 @@
/*++
Caution: This file is used for Duet platform only, do not use them in real platform.
All variable code, variable metadata, and variable data used by Duet platform are on
disk. They can be changed by user. BIOS is not able to protoect those.
Duet trusts all meta data from disk. If variable code, variable metadata and variable
data is modified in inproper way, the behavior is undefined.
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
MemStorage.c
Abstract:
handles variable store/reads with emulated memory
Revision History
--*/
#include "FSVariable.h"
VOID
EFIAPI
OnVirtualAddressChangeMs (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
EFIAPI
MemEraseStore(
IN VARIABLE_STORAGE *This
);
EFI_STATUS
EFIAPI
MemWriteStore (
IN VARIABLE_STORAGE *This,
IN UINTN Offset,
IN UINTN BufferSize,
IN VOID *Buffer
);
EFI_STATUS
MemStorageConstructor (
OUT VARIABLE_STORAGE **VarStore,
OUT EFI_EVENT_NOTIFY *GoVirtualEvent,
IN UINTN Size
)
{
EFI_STATUS Status;
VS_DEV *Dev;
Status = gBS->AllocatePool (EfiRuntimeServicesData, sizeof(VS_DEV), (VOID **) &Dev);
ASSERT_EFI_ERROR (Status);
ZeroMem (Dev, sizeof(VS_DEV));
Dev->Signature = VS_DEV_SIGNATURE;
Dev->Size = Size;
Dev->VarStore.Erase = MemEraseStore;
Dev->VarStore.Write = MemWriteStore;
Status = gBS->AllocatePool (EfiRuntimeServicesData, Size, (VOID **) &VAR_DATA_PTR (Dev));
ASSERT_EFI_ERROR (Status);
DEBUG ((EFI_D_ERROR, "VStorage: Size = 0x%x\n", Size));
*VarStore = &Dev->VarStore;
*GoVirtualEvent = OnVirtualAddressChangeMs;
return EFI_SUCCESS;
}
VOID
EFIAPI
OnVirtualAddressChangeMs (
IN EFI_EVENT Event,
IN VOID *Context
)
{
VS_DEV *Dev;
Dev = DEV_FROM_THIS (Context);
EfiConvertPointer (0, (VOID **)&VAR_DATA_PTR (Dev));
EfiConvertPointer (0, (VOID **)&Dev->VarStore.Erase);
EfiConvertPointer (0, (VOID **)&Dev->VarStore.Write);
}
EFI_STATUS
EFIAPI
MemEraseStore(
IN VARIABLE_STORAGE *This
)
{
VS_DEV *Dev;
Dev = DEV_FROM_THIS(This);
SetMem (VAR_DATA_PTR (Dev), Dev->Size, VAR_DEFAULT_VALUE);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
MemWriteStore (
IN VARIABLE_STORAGE *This,
IN UINTN Offset,
IN UINTN BufferSize,
IN VOID *UserBuffer
)
{
VS_DEV *Dev;
Dev = DEV_FROM_THIS(This);
ASSERT (Offset + BufferSize < Dev->Size);
// For better performance
if (VAR_DATA_PTR (Dev) + Offset != UserBuffer) {
CopyMem (VAR_DATA_PTR (Dev) + Offset, UserBuffer, BufferSize);
}
return EFI_SUCCESS;
}

View File

@@ -1,118 +0,0 @@
/*++
Caution: This file is used for Duet platform only, do not use them in real platform.
All variable code, variable metadata, and variable data used by Duet platform are on
disk. They can be changed by user. BIOS is not able to protoect those.
Duet trusts all meta data from disk. If variable code, variable metadata and variable
data is modified in inproper way, the behavior is undefined.
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
VariableStorage.h
Abstract:
handles variable store/reads with memory and file
Revision History
--*/
#ifndef _VARIABLE_STORAGE_H_
#define _VARIABLE_STORAGE_H_
#define VAR_DEFAULT_VALUE (0xff)
#define VAR_DEFAULT_VALUE_16 SIGNATURE_16 (VAR_DEFAULT_VALUE, VAR_DEFAULT_VALUE)
#define VAR_DEFAULT_VALUE_32 SIGNATURE_32 (VAR_DEFAULT_VALUE, VAR_DEFAULT_VALUE, \
VAR_DEFAULT_VALUE, VAR_DEFAULT_VALUE)
typedef struct _VARIABLE_STORAGE VARIABLE_STORAGE;
EFI_STATUS
FileStorageConstructor (
OUT VARIABLE_STORAGE **VarStore,
OUT EFI_EVENT_NOTIFY *GoVirtualEvent,
IN EFI_PHYSICAL_ADDRESS NvStorageBase,
IN UINTN Size,
IN UINT32 VolumeId,
IN CHAR16 *FilePath
);
EFI_STATUS
MemStorageConstructor (
OUT VARIABLE_STORAGE **VarStore,
OUT EFI_EVENT_NOTIFY *GoVirtualEvent,
IN UINTN Size
);
typedef
EFI_STATUS
(EFIAPI *ERASE_STORE) (
IN VARIABLE_STORAGE *This
);
typedef
EFI_STATUS
(EFIAPI *WRITE_STORE) (
IN VARIABLE_STORAGE *This,
IN UINTN Offset,
IN UINTN BufferSize,
IN VOID *Buffer
);
struct _VARIABLE_STORAGE {
//
// Functions to access the storage
//
ERASE_STORE Erase;
WRITE_STORE Write;
};
typedef struct _VS_FILE_INFO {
UINT8 *FileData; // local buffer for reading acceleration
EFI_DEVICE_PATH_PROTOCOL *DevicePath; // device having storage file
UINT32 VolumeId;
CHAR16 FilePath[256];
} VS_FILE_INFO;
typedef struct _VS_MEM_INFO {
UINT8 *MemData;
} VS_MEM_INFO;
typedef struct _VS_DEV {
UINT32 Signature;
VARIABLE_STORAGE VarStore;
UINTN Size;
union {
//
// finally visit FileInfo.FileData or MemInfo.MemData
//
UINT8 *Data;
VS_FILE_INFO FileInfo;
VS_MEM_INFO MemInfo;
} Info;
} VS_DEV;
#define VS_DEV_SIGNATURE SIGNATURE_32 ('$', 'V', 'S', 'D')
#define DEV_FROM_THIS(a) CR (a, VS_DEV, VarStore, VS_DEV_SIGNATURE)
#define VAR_DATA_PTR(a) ((a)->Info.Data)
#define VAR_FILE_DEVICEPATH(a) ((a)->Info.FileInfo.DevicePath)
#define VAR_FILE_VOLUMEID(a) ((a)->Info.FileInfo.VolumeId)
#define VAR_FILE_FILEPATH(a) ((a)->Info.FileInfo.FilePath)
#endif

View File

@@ -1,58 +0,0 @@
## @file
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# DUETFwh.inf
#
# Abstract:
#
# Component description file for DUET Module
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DuetFwh
FILE_GUID = 46E3256A-E5C1-4d2a-8282-505AFB41CE65
MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = FvbInitialize
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
DuetPkg/DuetPkg.dec
[Sources]
FWBlockService.c
FwBlockService.h
FvbInfo.c
FileIo.c
FileIo.h
[LibraryClasses]
DevicePathLib
UefiLib
UefiDriverEntryPoint
UefiRuntimeLib
HobLib
[Guids]
gEfiFlashMapHobGuid
[Protocols]
gEfiSimpleFileSystemProtocolGuid
gEfiFirmwareVolumeBlockProtocolGuid
gEfiBlockIoProtocolGuid
[Depex]
TRUE

Some files were not shown because too many files have changed in this diff Show More