biosvideo.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 2,146 行 · 第 1/5 页
C
2,146 行
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. 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:
BiosVideo.c
Abstract:
ConsoleOut Routines that speak VGA.
Revision History
--*/
#include "BiosVideo.h"
//
// EFI Driver Binding Protocol Instance
//
EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding = {
BiosVideoDriverBindingSupported,
BiosVideoDriverBindingStart,
BiosVideoDriverBindingStop,
0x00000024,
NULL,
NULL
};
//
// Global lookup tables for VGA graphics modes
//
UINT8 mVgaLeftMaskTable[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
UINT8 mVgaRightMaskTable[] = { 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
UINT8 mVgaBitMaskTable[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
EFI_UGA_PIXEL mVgaColorToUgaColor[] = {
{
0x00,
0x00,
0x00,
0x00
},
{
0x98,
0x00,
0x00,
0x00
},
{
0x00,
0x98,
0x00,
0x00
},
{
0x98,
0x98,
0x00,
0x00
},
{
0x00,
0x00,
0x98,
0x00
},
{
0x98,
0x00,
0x98,
0x00
},
{
0x00,
0x98,
0x98,
0x00
},
{
0x98,
0x98,
0x98,
0x00
},
{
0x10,
0x10,
0x10,
0x00
},
{
0xff,
0x10,
0x10,
0x00
},
{
0x10,
0xff,
0x10,
0x00
},
{
0xff,
0xff,
0x10,
0x00
},
{
0x10,
0x10,
0xff,
0x00
},
{
0xf0,
0x10,
0xff,
0x00
},
{
0x10,
0xff,
0xff,
0x00
},
{
0xff,
0xff,
0xff,
0x00
}
};
//
// Driver Entry Point
//
EFI_DRIVER_ENTRY_POINT (BiosVideoDriverEntryPoint)
EFI_STATUS
EFIAPI
BiosVideoDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Driver Entry Point.
Arguments:
ImageHandle - Handle of driver image.
SystemTable - Pointer to system table.
Returns:
EFI_STATUS
--*/
{
EFI_STATUS Status;
Status = EfiLibInstallAllDriverProtocols (
ImageHandle,
SystemTable,
&gBiosVideoDriverBinding,
ImageHandle,
&gBiosVideoComponentName,
NULL,
NULL
);
return Status;
}
VOID
EFIAPI
BiosVideoExitBootServices (
EFI_EVENT Event,
VOID *Context
)
/*++
Routine Description:
Callback function for exit boot service event
Arguments:
Event - EFI_EVENT structure
Context - Event context
Returns:
None
--*/
{
/*
BIOS_VIDEO_DEV *BiosVideoPrivate;
EFI_IA32_REGISTER_SET Regs;
//
// Get our context
//
BiosVideoPrivate = (BIOS_VIDEO_DEV *) Context;
//
// Set the 80x25 Text VGA Mode
//
Regs.H.AH = 0x00;
Regs.H.AL = 0x83;
BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);
Regs.H.AH = 0x11;
Regs.H.AL = 0x14;
Regs.H.BL = 0;
BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);
*/
}
EFI_STATUS
EFIAPI
BiosVideoDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Supported.
Arguments:
This - Pointer to driver binding protocol
Controller - Controller handle to connect
RemainingDevicePath - A pointer to the remaining portion of a device path
Returns:
EFI_STATUS - EFI_SUCCESS:This controller can be managed by this driver,
Otherwise, this controller cannot be managed by this driver
--*/
{
EFI_STATUS Status;
EFI_LEGACY_BIOS_THUNK_PROTOCOL *LegacyBios;
EFI_PCI_IO_PROTOCOL *PciIo;
//
// See if the Legacy BIOS Protocol is available
//
Status = gBS->LocateProtocol (&gEfiLegacyBiosThunkProtocolGuid, NULL, (VOID **) &LegacyBios);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
Controller,
&gEfiPciIoProtocolGuid,
(VOID **) &PciIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
if (!BiosVideoIsVga (PciIo)) {
Status = EFI_UNSUPPORTED;
}
gBS->CloseProtocol (
Controller,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
EFI_STATUS
EFIAPI
BiosVideoDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Install UGA Draw Protocol onto VGA device handles
Arguments:
This - Pointer to driver binding protocol
Controller - Controller handle to connect
RemainingDevicePath - A pointer to the remaining portion of a device path
Returns:
EFI_STATUS
--*/
{
EFI_STATUS Status;
BIOS_VIDEO_DEV *BiosVideoPrivate;
//
// Initialize local variables
//
BiosVideoPrivate = NULL;
//
// Allocate the private device structure
//
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (BIOS_VIDEO_DEV),
&BiosVideoPrivate
);
if (EFI_ERROR (Status)) {
goto Done;
}
EfiZeroMem (BiosVideoPrivate, sizeof (BIOS_VIDEO_DEV));
//
// See if the Legacy BIOS Protocol is available
//
Status = gBS->LocateProtocol (&gEfiLegacyBiosThunkProtocolGuid, NULL, (VOID **) &BiosVideoPrivate->LegacyBios);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Prepare for status code
//
Status = gBS->HandleProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
&BiosVideoPrivate->DevicePath
);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Open the IO Abstraction(s) needed
//
Status = gBS->OpenProtocol (
Controller,
&gEfiPciIoProtocolGuid,
(VOID **) &(BiosVideoPrivate->PciIo),
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
goto Done;
}
if (!BiosVideoIsVga (BiosVideoPrivate->PciIo)) {
Status = EFI_UNSUPPORTED;
goto Done;
}
BiosVideoPrivate->VgaCompatible = TRUE;
//
// Initialize the private device structure
//
BiosVideoPrivate->Signature = BIOS_VIDEO_DEV_SIGNATURE;
BiosVideoPrivate->Handle = Controller;
Status = gBS->CreateEvent (
EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,
EFI_TPL_NOTIFY,
BiosVideoExitBootServices,
BiosVideoPrivate,
&BiosVideoPrivate->ExitBootServicesEvent
);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Fill in UGA Draw specific mode structures
//
BiosVideoPrivate->HardwareNeedsStarting = TRUE;
BiosVideoPrivate->CurrentMode = 0;
BiosVideoPrivate->MaxMode = 0;
BiosVideoPrivate->ModeData = NULL;
BiosVideoPrivate->LineBuffer = NULL;
BiosVideoPrivate->VgaFrameBuffer = NULL;
BiosVideoPrivate->VbeFrameBuffer = NULL;
//
// Fill in the VGA Mini Port Protocol fields
//
BiosVideoPrivate->VgaMiniPort.SetMode = BiosVideoVgaMiniPortSetMode;
BiosVideoPrivate->VgaMiniPort.VgaMemoryOffset = 0xb8000;
BiosVideoPrivate->VgaMiniPort.CrtcAddressRegisterOffset = 0x3d4;
BiosVideoPrivate->VgaMiniPort.CrtcDataRegisterOffset = 0x3d5;
BiosVideoPrivate->VgaMiniPort.VgaMemoryBar = EFI_PCI_IO_PASS_THROUGH_BAR;
BiosVideoPrivate->VgaMiniPort.CrtcAddressRegisterBar = EFI_PCI_IO_PASS_THROUGH_BAR;
BiosVideoPrivate->VgaMiniPort.CrtcDataRegisterBar = EFI_PCI_IO_PASS_THROUGH_BAR;
//
// Assume that UGA Draw will be produced until proven otherwise
//
BiosVideoPrivate->ProduceUgaDraw = TRUE;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?