summaryrefslogtreecommitdiff
path: root/Core/EM/Sredir
diff options
context:
space:
mode:
authorraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
committerraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
commitb7c51c9cf4864df6aabb99a1ae843becd577237c (patch)
treeeebe9b0d0ca03062955223097e57da84dd618b9a /Core/EM/Sredir
downloadzprj-b7c51c9cf4864df6aabb99a1ae843becd577237c.tar.xz
init. 1AQQW051HEADmaster
Diffstat (limited to 'Core/EM/Sredir')
-rw-r--r--Core/EM/Sredir/LegacySmmSredir.c474
-rw-r--r--Core/EM/Sredir/LegacySredir.c1422
-rw-r--r--Core/EM/Sredir/LegacySredir.chmbin0 -> 220047 bytes
-rw-r--r--Core/EM/Sredir/LegacySredir.cif19
-rw-r--r--Core/EM/Sredir/LegacySredir.dxs104
-rw-r--r--Core/EM/Sredir/LegacySredir.mak135
-rw-r--r--Core/EM/Sredir/LegacySredir.sdl164
-rw-r--r--Core/EM/Sredir/SerialBootCall.asm180
-rw-r--r--Core/EM/Sredir/SredirBootFail.asm179
9 files changed, 2677 insertions, 0 deletions
diff --git a/Core/EM/Sredir/LegacySmmSredir.c b/Core/EM/Sredir/LegacySmmSredir.c
new file mode 100644
index 0000000..bd167e5
--- /dev/null
+++ b/Core/EM/Sredir/LegacySmmSredir.c
@@ -0,0 +1,474 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2009, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySmmSredir.c 6 12/08/14 3:36a Anbuprakashp $
+//
+// $Revision: 6 $
+//
+// $Date: 12/08/14 3:36a $
+//****************************************************************************
+//****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySmmSredir.c $
+//
+// 6 12/08/14 3:36a Anbuprakashp
+// [TAG] EIP192305
+// [Category] Improvement
+// [Description] Replacing SmmGetMemoryType usage in LegacySredir module
+// with AmiBufferValidationLib
+// [Files] LegacySredir.mak, LegacySmmSredir.c, LegacySredir_Setup.C
+//
+// 5 6/25/13 4:40a Rameshr
+// [TAG] EIP125655
+// [Category] Improvement
+// [Description] MMIO Address validated before reading or writing to the
+// MMIO region in the SW SMI handler
+// [Files] LegacySmmSredir.c, LegacySredir.dxs
+//
+// 4 4/10/12 12:49a Rameshr
+// [TAG] EIP84345
+// [Category] Improvement
+// [Description] Error checking and SMM dependency added
+// [Files] LegacySmmSredir.c, LegacySredir.dxs
+//
+// 3 6/17/11 4:41a Rameshr
+// [TAG] - EIP 47188
+// [Category]- IMPROVEMENT
+// [Description]- MMIO COM device access width SDL token support added
+// [Files] - legacysredir.c, LegacySredirSmm.c, LegacySredir_setup.c
+//
+// 2 9/24/10 1:37a Rameshr
+// [TAG] - EIP 44133
+// [Category]- BUG FIX & IMPROVEMENT
+// [Severity]- Major
+// [Symptom] - Flowcontrol and Terminal type is not working in Legacy
+// console redirection
+// [RootCause] - Baud rate value overwrites the Flowcontrol and Terminal
+// Type fields.
+// [Solution] - BaudRate programming done in EFI driver. So removed the
+// baud rate value passing into Sredir.bin
+// MMIO com device width added based on SDL token.
+// [Files] - LegacySmmSredir.c , Legacysredir.c, Legacysredir.sdl
+//
+// 1 3/05/10 4:17a Rameshr
+// Initial Check-in
+//
+// MMIO COM device support added.
+// EIP 33847
+//
+//
+//****************************************************************************
+//****************************************************************************
+//<AMI_FHDR_START>
+//****************************************************************************
+//
+// Name: LegacySmmSredir.C
+//
+// Description: Legacy console redirection SMM support
+//****************************************************************************
+//<AMI_FHDR_END>
+
+#include "token.h"
+#include "Protocol/LegacySredir.h"
+#include "AmiDxeLib.h"
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION>=0x4028B)
+#include <Protocol\SmmCpu.h>
+#include <Protocol\SmmBase2.h>
+#include <Protocol\SmmSwDispatch2.h>
+#else
+#include <Protocol\SmmBase.h>
+#include <Protocol\SmmSwDispatch.h>
+#endif
+#include <Protocol\DevicePath.h>
+#include <Protocol\LoadedImage.h>
+#include <AmiSmm.h>
+#include <AmiBufferValidationLib.h>
+
+
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION>=0x4028B)
+EFI_SMM_BASE2_PROTOCOL *gSmmBase2;
+EFI_SMM_SYSTEM_TABLE2 *pSmst2;
+EFI_GUID gEfiSmmCpuProtocolGuid = EFI_SMM_CPU_PROTOCOL_GUID;
+EFI_SMM_CPU_PROTOCOL *gSmmCpu=NULL;
+#define RETURN(status) {return status;}
+#else
+EFI_GUID gEfiSmmSwDispatchProtocolGuid = EFI_SMM_SW_DISPATCH_PROTOCOL_GUID;
+EFI_GUID gSwSmiCpuTriggerGuid = SW_SMI_CPU_TRIGGER_GUID;
+#define RETURN(status) {return ;}
+#endif
+
+#pragma pack(1)
+typedef struct {
+ UINT32 MMIOAddress;
+ UINT8 FuncNo;
+ UINT8 ReadWrite;
+ UINT8 Offset;
+ UINT8 Value;
+ UINT8 Count;
+ UINT32 BufferAddress;
+} SREDIR_INPUT_PARAMETER;
+#pragma pack()
+
+EFI_STATUS
+LegacySreDirInSmmFunction(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION >= 0x4028B)
+EFI_STATUS LegacySredirSMIHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *DispatchContext OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
+#else
+VOID LegacySredirSMIHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
+#endif
+);
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------
+// Procedure: ReadSerialPort
+//
+// Description: Read the Data from Serial Port
+//
+// Input: SREDIR_INPUT_PARAMETER SredirParam
+//
+// Output:
+//
+// Returns:
+//
+//----------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS ReadSerialPort(
+ IN OUT SREDIR_INPUT_PARAMETER *SredirParam
+)
+{
+
+ UINT32 TempValue;
+#if COM_MMIO_WIDTH == 4
+ TempValue=*(UINT32*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH));
+#else
+ #if COM_MMIO_WIDTH == 2
+ TempValue=*(UINT16*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH));
+ #else
+ TempValue=*(UINT8*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH));
+ #endif
+#endif
+
+ SredirParam->Value=(UINT8)TempValue;
+ return EFI_SUCCESS;
+}
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------
+// Procedure: WriteSerialPort
+//
+// Description: Write the Data to Serial Port
+//
+// Input: SREDIR_INPUT_PARAMETER SredirParam
+//
+// Output:
+//
+// Returns:
+//
+//----------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS WriteSerialPort(
+ IN OUT SREDIR_INPUT_PARAMETER *SredirParam
+)
+{
+ UINT32 TempValue=(UINT32)SredirParam->Value;
+
+#if COM_MMIO_WIDTH == 4
+ *(UINT32*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH))=TempValue;
+#else
+ #if COM_MMIO_WIDTH == 2
+ *(UINT16*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH))=(UINT16)TempValue;
+ #else
+ *(UINT8*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH))=(UINT8)TempValue;
+ #endif
+#endif
+
+ return EFI_SUCCESS;
+}
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------
+// Procedure: WriteBufferSerialPort
+//
+// Description: Write the buffer of data to Serial port
+//
+// Input: SREDIR_INPUT_PARAMETER SredirParam
+//
+// Output:
+//
+// Returns:
+//
+//----------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS WriteBufferSerialPort(
+ IN OUT SREDIR_INPUT_PARAMETER *SredirParam
+)
+{
+ UINT8 i;
+ UINT32 TempValue=0;
+ UINT8 *DataBuffer=(UINT8*)SredirParam->BufferAddress;
+ EFI_STATUS Status;
+
+ if(SredirParam->Count == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if( !DataBuffer ) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Validate Input buffer is valid and not resides in SMRAM region
+ Status = AmiValidateMemoryBuffer ( (VOID*)DataBuffer, SredirParam->Count );
+ if( Status != EFI_SUCCESS ) {
+ RETURN(Status);
+ }
+
+ for(i=0;i<SredirParam->Count;i++) {
+ TempValue=*DataBuffer;
+
+#if COM_MMIO_WIDTH == 4
+ *(UINT32*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH))=TempValue;
+#else
+ #if COM_MMIO_WIDTH == 2
+ *(UINT16*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH))=(UINT16)TempValue;
+ #else
+ *(UINT8*)(SredirParam->MMIOAddress+(SredirParam->Offset*COM_MMIO_WIDTH))=(UINT8)TempValue;
+ #endif
+#endif
+ DataBuffer++;
+ }
+
+ return EFI_SUCCESS;
+}
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Procedure: LegacySredirSMIHandler
+//
+// Description: Legacy Serial Redirection Smm handler function
+//
+// Input: DispatchHandle - EFI Handle
+// DispatchContext - Pointer to the EFI_SMM_SW_DISPATCH_CONTEXT
+//
+// Output:
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION >= 0x4028B)
+EFI_STATUS LegacySredirSMIHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *DispatchContext OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
+#else
+VOID LegacySredirSMIHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
+#endif
+)
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ UINT8 Data;
+ UINT64 pCommBuff;
+ UINT32 HighBufferAddress = 0;
+ UINT32 LowBufferAddress = 0;
+ UINTN Cpu=(UINTN)-1;
+ SREDIR_INPUT_PARAMETER *SredirParam;
+#if PI_SPECIFICATION_VERSION < 0x1000A
+ EFI_SMM_CPU_SAVE_STATE *pCpuSaveState;
+ SW_SMI_CPU_TRIGGER *SwSmiCpuTrigger;
+ UINTN i;
+#endif
+
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION >= 0x4028B)
+
+ Cpu = ((EFI_SMM_SW_CONTEXT*)CommBuffer)->SwSmiCpuIndex;
+ //
+ // Found Invalid CPU number, return
+ //
+ if(Cpu == (UINTN)-1) RETURN(Status);
+
+ Status = gSmmCpu->ReadSaveState ( gSmmCpu, \
+ 4, \
+ EFI_SMM_SAVE_STATE_REGISTER_RBX, \
+ Cpu, \
+ &LowBufferAddress );
+
+ Status = gSmmCpu->ReadSaveState ( gSmmCpu, \
+ 4, \
+ EFI_SMM_SAVE_STATE_REGISTER_RCX, \
+ Cpu, \
+ &HighBufferAddress );
+
+ Data = ((EFI_SMM_SW_CONTEXT*)CommBuffer)->CommandPort;
+#else
+ for (i = 0; i < pSmst->NumberOfTableEntries; ++i) {
+ if (guidcmp(&pSmst->SmmConfigurationTable[i].VendorGuid,&gSwSmiCpuTriggerGuid) == 0) {
+ break;
+ }
+ }
+
+ //If found table, check for the CPU that caused the software Smi.
+ if (i != pSmst->NumberOfTableEntries) {
+ SwSmiCpuTrigger = pSmst->SmmConfigurationTable[i].VendorTable;
+ Cpu = SwSmiCpuTrigger->Cpu;
+ }
+
+ //
+ // Found Invalid CPU number, return
+ //
+ if(Cpu == (UINTN) -1) {
+ RETURN(Status);
+ }
+
+ Data = (UINT8)DispatchContext->SwSmiInputValue;
+
+ pCpuSaveState = pSmst->CpuSaveState;
+ HighBufferAddress = pCpuSaveState[Cpu].Ia32SaveState.ECX;
+ LowBufferAddress = pCpuSaveState[Cpu].Ia32SaveState.EBX;
+
+#endif
+
+ pCommBuff = HighBufferAddress;
+ pCommBuff = Shl64(pCommBuff, 32);
+ pCommBuff += LowBufferAddress;
+ SredirParam =(SREDIR_INPUT_PARAMETER *)pCommBuff;
+
+ // Validate COM port register's MMIO address space are valid and not reside in SMRAM region
+ Status = AmiValidateMmioBuffer( (VOID*)SredirParam->MMIOAddress, 8*COM_MMIO_WIDTH );
+ if( Status != EFI_SUCCESS ) {
+ SredirParam->Value=0;
+ RETURN(Status);
+ }
+
+ switch(SredirParam->FuncNo) {
+
+ case 0x1:
+ ReadSerialPort(SredirParam);
+ break;
+
+ case 0x2:
+ WriteSerialPort(SredirParam);
+ break;
+
+ case 0x3:
+ Status = WriteBufferSerialPort(SredirParam);
+ break;
+
+ }
+
+ RETURN(Status);
+}
+
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Name: LegacySreDirInSmmFunction
+//
+// Description: Legacy Serial Redirection Smm entry point
+//
+// Input: Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT
+// EFI System Table - Pointer to System Table
+//
+// Output: EFI_STATUS OR EFI_NOT_FOUND
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS
+LegacySreDirInSmmFunction(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+
+ EFI_HANDLE Handle;
+ EFI_STATUS Status;
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION >= 0x4028B)
+ EFI_SMM_SW_DISPATCH2_PROTOCOL *pSwDispatch = NULL;
+ EFI_SMM_SW_REGISTER_CONTEXT SwContext;
+#else
+ EFI_SMM_SW_DISPATCH_PROTOCOL *pSwDispatch;
+ EFI_SMM_SW_DISPATCH_CONTEXT SwContext;
+#endif
+
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION >= 0x4028B)
+ Status = InitAmiSmmLib( ImageHandle, SystemTable );
+
+ Status = pBS->LocateProtocol(&gEfiSmmBase2ProtocolGuid, NULL, &gSmmBase2);
+
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ //
+ // We are in SMM, retrieve the pointer to SMM System Table
+ //
+ Status = gSmmBase2->GetSmstLocation( gSmmBase2, &pSmst2);
+ if (EFI_ERROR(Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = pSmst2->SmmLocateProtocol( &gEfiSmmSwDispatch2ProtocolGuid, \
+ NULL, \
+ &pSwDispatch );
+
+ if(EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ Status = pSmst2->SmmLocateProtocol(&gEfiSmmCpuProtocolGuid, NULL, &gSmmCpu);
+
+#else
+ Status = pBS->LocateProtocol(&gEfiSmmSwDispatchProtocolGuid, NULL, &pSwDispatch);
+#endif
+
+ ASSERT_EFI_ERROR(Status);
+
+ if(EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ InitAmiBufferValidationLib( ImageHandle, SystemTable );
+
+ SwContext.SwSmiInputValue = LEGACY_SREDIR_SWSMI;
+ Status = pSwDispatch->Register(pSwDispatch, LegacySredirSMIHandler, &SwContext, &Handle);
+ return EFI_SUCCESS;
+}
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2009, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/Sredir/LegacySredir.c b/Core/EM/Sredir/LegacySredir.c
new file mode 100644
index 0000000..78b3293
--- /dev/null
+++ b/Core/EM/Sredir/LegacySredir.c
@@ -0,0 +1,1422 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySredir.c 51 11/27/14 12:38a Srilathasc $
+//
+// $Revision: 51 $
+//
+// $Date: 11/27/14 12:38a $
+//****************************************************************************
+//****************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySredir.c $
+//
+// 51 11/27/14 12:38a Srilathasc
+// [TAG] EIP193345
+// [Category] Improvement
+// [Description] Sredir bin module needs to be modified to make use ACPI
+// timer instead of 8254 timer
+// [Files] Sredir.asm, LegacySredir.c, csm.sdl, Sredir,bin
+//
+// 50 11/18/14 5:22a Anandakrishnanl
+// [TAG] EIP192802
+// [Category] Improvement
+// [Description] Support for legacy redirection by UART polling is added
+// for platforms in which serial port does not support IRQ on PIC Mode.
+// [Files] LegacySredir.c LegacySredir.h,LegacySredir.sdl
+//
+// 49 12/20/13 6:53a Divyac
+// [TAG] EIP147701
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] DOS redirection is not working in Shark Bay platform.
+// [RootCause] Wrong Value assigned to CTRLH_MAPPING Macro in
+// LegacySredir.c
+// [Solution] Assigned Value to CTRLH_MAPPING Macro, according to the
+// value defined for CTRLH_MAPPING Equate in Sredir.asm
+// [Files] LegacySredir.c
+//
+// 48 12/09/13 5:23a Divyac
+// [TAG] EIP129549
+// [Category] Improvement
+// [Description] Serial Redirection has dependency on Amilegacy16.bin
+// [Files] LegacySredir.c, LegacySredir.h, OR_MOD.EQU, SREDIR.ASM
+//
+// 47 12/09/13 4:45a Divyac
+// [TAG] EIP146051
+// [Category] Improvement
+// [Description] Refresh Key needs to be configured via SDL token for
+// Legacy Serial Redirection.
+// [Files] LegacySredir.c, LegacySredir_Setup.C, LegacySredir.h,
+// Sredir.bin
+//
+// 46 9/17/13 5:31a Rameshr
+// [TAG] EIP134807
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] Redirection doesn't work with MMIO PCI device
+// [RootCause] CTRLH_MAPPING and MMIO_WORD_WIDTH both the equate uses
+// the same values.
+// [Solution] Modified CTRLH_MAPPING equate value
+// [Files] LegacySredir.c, Sredir.bin
+//
+// 45 5/30/13 2:46a Rameshr
+// [TAG] EIP123584
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] when active PCI console redirectioin support, keyboard not
+// response at POST stage
+// [RootCause] CSM16 region status changed by Legacy Serial Redirection
+// driver
+// [Solution] CSM16 region unlocked and locked again only when the
+// Legacy OS booting happens
+// [Files] Legacysredir.c
+//
+// 44 5/29/13 8:51a Srikantakumarp
+// [TAG] EIP122394
+// [Category] Bug Fix
+// [Severity] Normal
+// [Symptom] 0xE0000~0xEFFFF was overwrite by Legacy Serial Redirection
+// module.
+// [RootCause] LegacySerialRedirection driver assumed that
+// SerialBootcall.asm will be the first entry in CsmOem16Functions which
+// was wrong.
+// [Solution] Added a Signature check code for SerialBootCall.asm and
+// SredirBootFail.asm before it writes to the memory location
+// 0xE0000~0xEFFFF.
+// [Files] LegacySredir.c, SerialBootCall.asm, SredirBootFail.asm
+//
+// 43 9/17/12 7:27a Srikantakumarp
+// [TAG] EIP101094
+// [Category] Improvement
+// [Description] Generic change for sdl token to control the ctrl+H key
+// [Files] LegacySredir.c, LegacySredir.sdl, Sredir.asm
+//
+// 42 7/27/12 5:00a Rajeshms
+// [TAG] EIP95246
+// [Category] Improvement
+// [Description] RTS is used to control redirection flow when
+// FlowControl is enabled. When RTS is disabled (host not ready to accept
+// data) Redirection is disabled and when RTS is enabled (i.e CTS is set)
+// Redirection is enabled again.
+// [Files] Terminal.sdl, SerialIo.c, LegacySredir.c, SREDIR.ASM,
+// INT10REDIR.ASM, GRAPHREDIR.ASM
+//
+// 41 3/29/12 11:51p Rajeshms
+// [TAG] EIP84341
+// [Category] Improvement
+// [Description] Added Separate PCI_UART_INPUT_CLOCK token for setting
+// the Clock for PCI Serial UART.
+// [Files] Terminal.sdl, TerminalSetup.c, SerialIo.c, LegacySredir.c,
+// LegacySredir_Setup.c
+//
+// 40 2/29/12 11:37p Rameshr
+// [TAG] EIP82480
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] System does not boot to Legacy Devices when Launch Video
+// OpRom DISABLED
+// [RootCause] Temp buffer address is not correct
+// [Solution] Redirection uses the 0x9F000 are temp buffer to save the
+// Video data. It should have been calculated in runtime based on the Base
+// memory allocated for sredir.bin
+// [Files] Legacysredir.c, LegacySredir.h
+//
+// 39 2/27/12 5:48a Jittenkumarp
+// [TAG] EIP81401
+// [Category] New Feature
+// [Description] Select Redirection After BIOS POST as BootLoader in
+// serial redirection, the behaviour is not same as Core8.
+// [Files] LegacySredir.c, LegacySredir.mak, LegacySredir.sdl,
+// LegacySredir_Setup.c, LegacySredir.h ,SerialBootCall.asm,
+// SredirBootFail.asm,GRAPHREDIR.ASM, INT10REDIR.ASM, OR_MOD.EQU,
+// SREDIR.ASM
+//
+// 38 12/28/11 10:52p Rajeshms
+// [TAG] EIP65051
+// [Category] Improvement
+// [Description] Data passing between EFI to Legacy has been changed in
+// Legacy console redirection as we are running out of registers to pass
+// parameters from EFI to Legacy.
+// [Files] LegacySredir.c, LegacySredir.h, LegacySredir_Setup.C,
+// SREDIR.ASM, OR_MOD.ASM, OR_MOD.EQU
+//
+// 37 12/12/11 2:06a Jittenkumarp
+// [TAG] EIP75982
+// [Category] New Feature
+// [Description] Redirection After BIOS POST item on the setup menu
+// [Files] Terminal.sd, Terminal.uni, LegacySredir.c,
+// LegacySredir_Setup.c
+//
+// 36 12/12/11 12:12a Jittenkumarp
+// [TAG] EIP75169
+// [Category] Improvement
+// [Description] Added ESC sequence support for Legacy Serial
+// Redirection.
+// [Files] LegacySredir.c, SREDIR.ASM, KEYREDIR.ASM
+//
+// 35 11/10/11 3:44a Rameshr
+// [TAG] EIP64383
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] System will hang when dash redirection disconnect in legacy
+// environment
+// [RootCause] Waiting for the Transmitter Holding Register Empty bit to
+// set to send the next data.
+// [Solution] After retry count is reached, redirection disabled.
+// [Files] Graphredir.asm , Or_mod.asm , Sredir.asm , Legacysredir.c
+//
+// 34 11/09/11 11:52p Rajeshms
+// [TAG]- EIP 63665
+// [Category]-IMPROVEMENT
+// [Description]- Install Linux(Legacy OS) through remote. Some Linux
+// versions are forced to text mode to redirect and some are redirected in
+// graphics mode itself. It might not work for all the Linux versions as
+// the Linux kernel's behave differently.
+// [Files]- Terminal.sdl, Terminal.uni, Terminal.sd, LegacySredir.c,
+// LegacySredir.h, LegacySredir_Setup.c, GRAPHREDIR.ASM, INT10REDIR.ASM,
+// OR_MOD.ASM, OR_MOD.EQU, SREDIR.ASM
+//
+// 33 8/16/11 4:45p Davidd
+// [TAG] EIP55337
+// [Category] New Feature
+// [Description] Add optional code to clear keyboard buffer at
+// ReadyToBoot in Legacy Serial Redirection driver
+// [Files] LegacySredir.c
+// LegacySredir.h
+// LegacySredir.sdl
+// Sredir.asm
+//
+// 32 8/05/11 4:19a Rameshr
+// [TAG] - EIP 66389
+// [Category]- BUG FIX
+// [Severity]- Minor
+// [Symptom] - System hangs at 0xAE when legacy serial redirection is
+// enable
+// [RootCause]- Before Legacy console redirection allocates the base
+// memory, some other driver allocates the base memory. So legacy console
+// redirection memory location moved down. But Sredir.bin thinks that seg
+// address of the sredir.bin is 0x9cc00. So system is hanging when we call
+// 0x9cc00:offset, as this region is not used to copy the sredir.bin
+// [Solution] - insteed of using the segment address from bin( hardcoded
+// value), Used the segment address we get it in runtime
+// [Files] - Legacysredir.c
+//
+// 31 7/13/11 2:38a Rajeshms
+// [TAG]- EIP 36444
+// [Category]- New Feature
+// [Description]- Add Setup option for Various Putty keyPad support in
+// Legacy console redirection driver
+// [Files]- LegacySredir.c, LegacySredir.h, LegacySredir_Setup.C,
+// SREDIR.ASM, KEYREDIR.ASM, OR_MOD.EQU, SREDIR.MAK
+//
+// 30 6/17/11 4:42a Rameshr
+// [TAG] - EIP 47188
+// [Category]- IMPROVEMENT
+// [Description]- MMIO COM device access width SDL token support added
+// [Files] - legacysredir.c, LegacySredirSmm.c, LegacySredir_setup.c
+//
+// 29 6/14/11 5:37a Rameshr
+// [TAG]- EIP 58140
+// [Category]- New Feature
+// [Description]- Add Setup option for Vt-UTF8 combo key support in Legacy
+// console redirection driver
+// [Files]- Sredir.asm, Legacysredir.c, Legacysredir.h,
+// Legacysredir_setup.c
+//
+// 28 2/11/11 4:58a Rameshr
+// [TAG]- EIP 53465
+// [Category]-IMPROVEMENT
+// [Description]- gLegacySredir variable name used as global and local
+// variable. Changed the Local Variable name
+// [Files]- LegacySredir.c
+//
+// 27 1/10/11 5:06a Rameshr
+// [TAG] - EIP 47188
+// [Category]- IMPROVEMENT
+// [Description]- MMIO COM device access width SDL token support added
+// [Files] - legacysredir.c, Sredir.asm
+//
+// 26 1/04/11 11:40p Rameshr
+// [TAG] - EIP 48120
+// [Category]- BUG FIX
+// [Severity]- Minor
+// [Symptom] - Function key Ctrl + i do not work via serial redirection.
+// [RootCause]- Crtl+I is mapped to tab key in the redirection module
+// [Solution] - Provided the SDL token for Ctrl+I key mapping. Tab and
+// Ctrl+I can be selected through this sdl token
+// [Files] - Legacysredir.c, Legacysredir.sdl, Sredir.asm(Sredir.bin)
+//
+// 25 9/24/10 1:37a Rameshr
+// [TAG] - EIP 44133
+// [Category]- BUG FIX & IMPROVEMENT
+// [Severity]- Major
+// [Symptom] - Flowcontrol and Terminal type is not working in Legacy
+// console redirection
+// [RootCause] - Baud rate value overwrites the Flowcontrol and Terminal
+// Type fields.
+// [Solution] - BaudRate programming done in EFI driver. So removed the
+// baud rate value passing into Sredir.bin
+// MMIO com device width added based on SDL token.
+// [Files] - LegacySmmSredir.c , Legacysredir.c, Legacysredir.sdl
+//
+// 24 6/04/10 2:01a Rameshr
+// Sredir.bin Size increased.
+//
+// 23 6/01/10 1:05a Rameshr
+// Issue: Sredir.bin always allocated memory in basememory
+// Solution: If the redirection is enabled, allocaed the base memory and
+// copied the Sredir.bin
+// EIP 37831
+//
+// 22 5/03/10 1:55a Rameshr
+// Callback function added for read and write function of the Serial Port.
+// EIP 37850
+//
+// 21 5/03/10 1:21a Rameshr
+// Issue:Need to handle different Base Hz values for SerialStatusCode,
+// Terminal, and Legacy Serial Redirection.
+// Solution: Moved Uart input clock into Core.sdl token and used in all
+// the above modules.
+// EIP: 37332
+//
+// 20 4/13/10 4:13a Rameshr
+// Recorder Mode support added
+// EIP 36514
+// Some of the MMIO COM port has non standard bits implemented. These bits
+// are reset to 0 in Sredir.bin
+// EIP 37123
+//
+// 19 3/05/10 4:20a Rameshr
+// MMIO COM device support added.
+// EIP 33847
+//
+// 18 2/03/10 12:58a Rameshr
+// Int10 Workaround added based on SDL token.
+// EIP 33300
+//
+// 17 11/26/09 5:16a Rameshr
+// Legacy console redirection module size increased. So changing the base
+// address.
+// EIP:26405
+//
+// 16 10/23/09 10:46a Yul
+// EIP 24167 and EIP 26405
+// Serial redirection selection of 80X24 or 80X25 implemented based on
+// setup question instead of BUILD token
+//
+// 15 9/21/09 3:36p Rameshr
+// compile Error in legacy sredir when using VS 2008
+// EIP 27263
+//
+// 14 6/29/09 12:11p Rameshr
+// Coding Standard and File header updated.
+//
+// 13 4/21/09 12:17p Rameshr
+// Updated the Legacy console redirection to get the Databits,Parity and
+// Stop bits from the Terminal Driver Setup option
+// EIP20874-Legacy serial redirection is using hra coded values for
+// Databits as 8, Parity as None and Stop bit as 1
+//
+// 12 4/20/09 12:58p Rameshr
+// EIP 20251 -Ebda value inside Legacy Serial Redirection need to be
+// Dynamic
+//
+// Removed Unwanted code and updated with proper comments on Sredir.bin
+// Memory allocation.
+//
+// 11 3/09/09 3:09p Rameshr
+// Symptom: PXE boot messages are not displayed on local console.
+// Solution: Without Disabling the Legacy console redirection, Enable
+// redirection is not processed.
+// EIP:19089
+//
+// 10 12/24/08 3:51p Rameshraju
+//
+// 9 12/16/08 2:49a Iminglin
+// (EIP17767) The function value of FindLegacySreDirTable for compliance.
+//
+// 8 11/20/08 12:50p Rameshraju
+// SDL parameters passed from EFI to 16bit code
+// Added code to display whole screen before disalbing the redirection.
+// This is done based on the SDL token. default set to disabled.
+//
+// 7 29/10/08 4:27p Anandakrishnanl
+// Added Status Check For GetSetupValuesForLegacySredir so that Legacy
+// Serial Redirection Can be Enabled Based on Setup Options.
+//
+// 6 10/24/08 11:21a Rameshraju
+// Disable redirection is called only when the enabled redirection call is
+// done.
+//
+// 5 9/10/08 12:44p Pats
+// Reverted method for reserving memory for Sredir.bin to previous method
+// (AllocateEbda not used).
+//
+// 4 8/26/08 10:01a Pats
+// Removed call to GetInterruptAddress function since it is not used.
+//
+// 3 8/20/08 6:52p Pats
+// Fixed bug of setup values being loaded into uninitialized null pointer.
+// Changed EBDA allocation to use AllocateEbda function.
+//
+// 2 4/17/07 4:41a Rameshraju
+// PCIserial support added
+//
+//****************************************************************************
+//****************************************************************************
+//<AMI_FHDR_START>
+//****************************************************************************
+//
+// Name: LegacySredir.C
+//
+// Description: Serial Redirection Compatibility Support Module entry point and interface functions
+//****************************************************************************
+//<AMI_FHDR_END>
+
+//
+// Disabling the warnings.
+//
+#pragma warning (disable : 4100 )
+
+#pragma warning (disable : 4306 )
+#include "Token.h"
+#include "Protocol/LoadedImage.h"
+#include "Protocol/LegacySredir.h"
+#include "Protocol/LegacyBios.h"
+#include "Protocol/LegacyBiosExt.h"
+#include "AmiDxeLib.h"
+
+
+#ifndef SERIAL_WRITE_ERROR_CHECK
+#define SERIAL_WRITE_ERROR_CHECK 1
+#ifndef MAXIMUM_SERIAL_WRITE_ERROR_COUNT
+#define MAXIMUM_SERIAL_WRITE_ERROR_COUNT 10
+#endif
+#endif
+
+#ifndef MAX_FAILURES_ALLOWED
+#define MAX_FAILURES_ALLOWED 5
+#endif
+
+
+#define CONVENTIONAL_MEMORY_TOP 0xA0000
+#define SREDIR_BIN_SIZE 0x3C00
+
+//
+//Parameter passed to sredir.bin
+//
+#define DISPLAY_SCREEN 0x0001
+#define INT10_WORKAROUND 0x0002
+#define MMIO_DEVICE 0x0004
+#define SERIAL_READWRITE_CALLBACK 0x0008
+#define CTRLI_MAPPING 0x0010
+#define MMIO_BYTE_WIDTH 0x0000
+#define MMIO_WORD_WIDTH 0x0020
+#define MMIO_DWORD_WIDTH 0x0040
+#define SERIAL_ERROR_CHECK 0x0080
+#define ESC_SEQUENCES 0x0100
+#define CTRLH_MAPPING 0x0200
+
+EFI_GUID gEfiLoadedImageGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
+EFI_GUID gEfiFirmwareVolumeProtocol = EFI_FIRMWARE_VOLUME_PROTOCOL_GUID;
+
+UINT32 Int10hAddress;
+UINT32 Int0chAddress;
+UINT32 Int14hAddress;
+VOID *EmbeddedRom;
+UINTN EmbeddedRomSize;
+
+AMI_LEGACYSREDIR_TABLE *mLegacySreDirHeader;
+EFI_EVENT SreDir;
+BOOLEAN RedirectionStatus=FALSE;
+UINTN gSreDirImageStart=0;
+EFI_LEGACY_BIOS_PROTOCOL *pLegacy=NULL;
+BOOLEAN IsCopied = FALSE;
+BOOLEAN IsDataCopied = FALSE;
+extern BOOLEAN IsPciDevice;
+BOOLEAN LegacyOSBooting=FALSE;
+
+//
+// The GetSetupValuesForLegacySredir procedure to get the setup values
+//
+extern EFI_STATUS GetSetupValuesForLegacySredir(
+ OUT AMI_COM_PARAMETERS *AmiComParameters
+);
+
+EFI_STATUS
+InitilizeNonCommonSerialRegsiters(
+ IN AMI_COM_PARAMETERS *AmiComParameters
+);
+
+
+EFI_STATUS
+EnableLegacySredir (
+ IN AMI_LEGACY_SREDIR_PROTOCOL * This
+);
+
+EFI_STATUS
+DisableLegacySredir (
+ IN AMI_LEGACY_SREDIR_PROTOCOL * This
+);
+
+EFI_STATUS
+LegacySreDirInSmmFunction(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+EFI_STATUS FindLegacySredirRom(
+ UINT16 ModuleId, UINT16 VendorId, UINT16 DeviceId,
+ VOID **ImageStart, UINT32 *ImageSize
+);
+
+EFI_STATUS DataCopiedToCsm16Function(
+ UINTN StructStartAddress,
+ AMI_COM_PARAMETERS *AmiComParameters
+);
+
+//
+// AMI_LEGACY_SREDIR_PROTOCOL
+//
+AMI_LEGACY_SREDIR_PROTOCOL gLegacySredir = {
+ EnableLegacySredir,
+ DisableLegacySredir
+};
+#define DLAB_BIT 1
+#define LSR_OFFSET 0x05
+#define LCR_OFFSET 0x03
+#define DIV_MSB 0x01
+#define DIV_LSB 0
+
+//
+// ACPI PM timer signature,for 'TM' the ASCII code is 0x544D
+// the MSB bit of the signature denotes 24bit/32bit timer
+//
+#if ACPI_SUPPORT
+#if FACP_FLAG_TMR_VAL_EXT
+#define TIMER_SIGNATURE_32BIT 0xD44D0000
+#else
+#define TIMER_SIGNATURE_24BIT 0x544D0000
+#endif
+#endif
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Name: DataCopiedToCsm16Function
+//
+// Description: This function copies the segment and offset address of sredir.bin
+//
+// Input: UINTN StructStartAddress
+// AMI_COM_PARAMETERS *AmiComParameters
+//
+//
+// Output: EFI_SUCCESS
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+
+EFI_STATUS DataCopiedToCsm16Function(
+ IN UINTN StructStartAddress,
+ IN AMI_COM_PARAMETERS *AmiComParameters
+)
+{
+ EFI_STATUS Status;
+ UINTN ImageSize = 0x10;
+ UINT32 LockUnlockAddr, LockUnlockSize;
+ UINT16 *Addr;
+ UINT32 Addr16;
+ EFI_LEGACY_BIOS_EXT_PROTOCOL *BiosExtensions = NULL;
+ UINT8 *RpSBCSig = "$SBC";
+ UINT8 *RpSBFSig = "$SBF";
+ //
+ // Check Data already copied into CSM16 call backfunction
+ //
+ if(IsDataCopied) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ //Data copied into CSM16 callback function
+ //
+ IsDataCopied=TRUE;
+
+ Status = pBS->LocateProtocol(
+ &gEfiLegacyBiosExtProtocolGuid,\
+ NULL,\
+ &BiosExtensions);
+
+ if (EFI_ERROR(Status))
+ return Status;
+
+ Status = BiosExtensions->Get16BitFuncAddress(
+ CSM16_OEM_BEFORE_CALL_BOOT_VECTOR, \
+ &Addr16);
+
+ if (EFI_ERROR(Status))
+ return Status;
+
+ Status = BiosExtensions->UnlockShadow(
+ (UINT8*)Addr16, \
+ ImageSize, \
+ &LockUnlockAddr, \
+ &LockUnlockSize);
+
+ ASSERT_EFI_ERROR(Status);
+
+
+ while(Addr16 < 0xf0000)
+ {
+ if (!MemCmp((UINT8*)Addr16, RpSBCSig, 4))
+ {
+ Addr16 = Addr16+4; // Skip the Signature "$SBC"
+ Addr = (UINT16*) Addr16;
+ *Addr =((StructStartAddress>>4) & 0xF000);
+ Addr++;
+ *Addr =(UINT16)StructStartAddress;
+ Addr++;
+ *Addr = (UINT16)(((UINT8 *)&(AmiComParameters->Flag)) - ((UINT8*)(AmiComParameters)));
+ break;
+ }
+ Addr16++;
+ }
+
+ Status = BiosExtensions->Get16BitFuncAddress(
+ CSM16_OEM_ON_BOOT_FAIL, \
+ &Addr16);
+
+ if (EFI_ERROR(Status))
+ return Status;
+
+
+
+ while(Addr16 < 0xf0000)
+ {
+ if (!MemCmp((UINT8*)Addr16, RpSBFSig, 4))
+ {
+ Addr16 = Addr16+4; // Skip the Signature "$SBF"
+ Addr = (UINT16*) Addr16;
+ *Addr =((StructStartAddress>>4) & 0xF000);
+ Addr++;
+ *Addr =(UINT16)StructStartAddress;
+ Addr++;
+ *Addr = (UINT16)(((UINT8 *)&(AmiComParameters->Flag)) - ((UINT8*)(AmiComParameters))) ;
+ break;
+ }
+ Addr16++;
+ }
+ BiosExtensions->LockShadow(LockUnlockAddr, LockUnlockSize);
+
+ return EFI_SUCCESS;
+}
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Name: CopySredirBinIntoBaseMemory
+//
+// Description: This function copies the Sredir.bin into Base Memory
+//
+// Input: This
+// Indicates the AMI_LEGACY_SREDIR_PROTOCOL instance.
+//
+//
+// Output: EFI_SUCCESS
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS
+CopySredirBinIntoBaseMemory (
+ IN AMI_LEGACY_SREDIR_PROTOCOL * This
+)
+{
+
+ VOID *SreDirImageStart = NULL;
+ UINT32 SreDirImageSize = 0;
+ UINT16 EbdaSeg = (UINT16)(*(UINT16*)0x40E);
+ UINT8 *EbdaAddress = (UINT8*)((UINTN)EbdaSeg<<4);
+ UINT32 EbdaSize = (*EbdaAddress)<<10;
+ UINT32 NewEbdaAdd;
+ UINT32 NewEbdaSeg;
+ EFI_STATUS Status;
+
+
+ //
+ // Check Sredir.bin already copied into Memory
+ //
+ if(IsCopied) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ //Sredir.bin copied into Base Memory
+ //
+ IsCopied=TRUE;
+
+ //
+ // Sredir.bin is placed in below A0000. It will not be reported as EBDA memory.
+ // So sredir place will not be changed when there is allocateEbda.
+ //
+ if(EbdaSeg== 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ //New EBDA Address will be EbdaAddress - Sredir.bin
+ //
+ NewEbdaAdd = (EbdaSeg<<4)-SREDIR_BIN_SIZE; //To allocate memory for sredir.bin
+ NewEbdaSeg = NewEbdaAdd>>4;
+
+ //
+ //We are taking memory for the Sredir.bin from the base memory. So adjust the Base Memory
+ //
+ *(UINT16*)0x413 = ((*(UINT16*)0x413) - (SREDIR_BIN_SIZE >> 10));
+
+ //
+ //Update the New EBDA address
+ //
+ *(UINT16*)0x40e = (UINT16)NewEbdaSeg;
+
+ //
+ //Move the OLD ebda data to new EBDA area. We have not changed the EBDA Size here. This makes
+ //Sredir.bin area will not be moved any where.it means Sredir.bin is not placed under EBDA area.
+ //
+ pBS->CopyMem((VOID*)NewEbdaAdd,(VOID*)(EbdaSeg<<4),EbdaSize);
+
+ Status = FindLegacySredirRom(SREDIR_MODULEID, SREDIR_VENDORID, SREDIR_DEVICEID,&SreDirImageStart, &SreDirImageSize);
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ //
+ // Copy the Sredir.bin Base Memory.
+ //
+ pBS->CopyMem((VOID*)(NewEbdaAdd+EbdaSize), SreDirImageStart, SreDirImageSize);
+ gSreDirImageStart = (UINTN)(NewEbdaAdd+EbdaSize);
+
+
+ return EFI_SUCCESS;
+
+}
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Name: InitilizeBuadRate
+//
+// Description: This Function is used to Initilize the Baud Rate of the COM port
+//
+// Input: AMI_COM_PARAMETERS AmiComParameters
+//
+//
+// Output: Com port Baud Rate Initilized.
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS
+InitilizeBuadRate(
+ OUT AMI_COM_PARAMETERS *AmiComParameters
+)
+{
+
+ UINT8 Data8;
+ UINT16 Divisor;
+ UINTN Remainder;
+ UINTN UartInputClock;
+
+ if( IsPciDevice ) {
+#ifdef PCI_UART_INPUT_CLOCK
+ UartInputClock = PCI_UART_INPUT_CLOCK;
+#else
+ //
+ // Set the default value((24000000/13)MHz input clock)
+ // if the PCI_UART_INPUT_CLOCK SDL token is not present.
+ //
+ UartInputClock=1843200;
+#endif
+ } else {
+#ifdef UART_INPUT_CLOCK
+ UartInputClock=UART_INPUT_CLOCK;
+#else
+ //
+ // Set the default value((24000000/13)MHz input clock)
+ // if the UART_INPUT_CLOCK SDL token is not present.
+ //
+ UartInputClock=1843200;
+#endif
+ }
+
+ //
+ // Compute the baud rate divisor.
+ //
+ Divisor = (UINT32) Div64 (UartInputClock,
+ ((UINT32)AmiComParameters->Baudrate * 16),
+ &Remainder);
+ if ( Remainder ) {
+ Divisor += 1;
+ }
+
+ if ((Divisor == 0) || (Divisor & 0xffff0000)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Check for the MMIO device. If it's MMIO device do MMIO access to
+ // Read and Write to the COM port Regsiters. Otherwise use IO access
+ // to Read and Write to Com port Registers.
+ //
+ if(AmiComParameters->MMIOBaseAddress != 0) {
+ //
+ // Programm Serial port.
+ // Set Line Control Register (LCR)
+ //
+ Data8 = DLAB_BIT << 7;
+
+#if COM_MMIO_WIDTH == 4
+ *(UINT32*)(AmiComParameters->MMIOBaseAddress+(LCR_OFFSET*COM_MMIO_WIDTH))=(UINT32)Data8;
+#else
+ #if COM_MMIO_WIDTH == 2
+ *(UINT16*)(AmiComParameters->MMIOBaseAddress+(LCR_OFFSET*COM_MMIO_WIDTH))=(UINT16)Data8;
+ #else
+ *(UINT8*)(AmiComParameters->MMIOBaseAddress+(LCR_OFFSET*COM_MMIO_WIDTH))=(UINT8)Data8;
+ #endif
+#endif
+
+ //
+ //Program the Baud Rate
+ //
+
+#if COM_MMIO_WIDTH == 4
+ *(UINT32*)(AmiComParameters->MMIOBaseAddress+(DIV_LSB*COM_MMIO_WIDTH))=(UINT32)Divisor & 0xFF;
+ *(UINT32*)(AmiComParameters->MMIOBaseAddress+(DIV_MSB*COM_MMIO_WIDTH))=(UINT32)Divisor >> 8;
+#else
+ #if COM_MMIO_WIDTH == 2
+ *(UINT16*)(AmiComParameters->MMIOBaseAddress+(DIV_LSB*COM_MMIO_WIDTH))=(UINT16)Divisor & 0xFF;
+ *(UINT16*)(AmiComParameters->MMIOBaseAddress+(DIV_MSB*COM_MMIO_WIDTH))=(UINT16)Divisor >> 8;
+
+ #else
+ *(UINT8*)(AmiComParameters->MMIOBaseAddress+(DIV_LSB*COM_MMIO_WIDTH))=(UINT8)Divisor & 0xFF;
+ *(UINT8*)(AmiComParameters->MMIOBaseAddress+(DIV_MSB*COM_MMIO_WIDTH))=(UINT8)(Divisor >> 8);
+ #endif
+#endif
+
+ //
+ // Clear DLAB bit in LCR
+ //
+ Data8 &= ~((UINT8)DLAB_BIT << 7);
+
+#if COM_MMIO_WIDTH == 4
+ *(UINT32*)(AmiComParameters->MMIOBaseAddress+(LCR_OFFSET*COM_MMIO_WIDTH))=(UINT32)Data8;
+#else
+ #if COM_MMIO_WIDTH == 2
+ *(UINT16*)(AmiComParameters->MMIOBaseAddress+(LCR_OFFSET*COM_MMIO_WIDTH))=(UINT16)Data8;
+ #else
+ *(UINT8*)(AmiComParameters->MMIOBaseAddress+(LCR_OFFSET*COM_MMIO_WIDTH))=(UINT8)Data8;
+ #endif
+#endif
+
+ } else {
+ //
+ // Programm Serial port.
+ // Set Line Control Register (LCR)
+ //
+ Data8 = DLAB_BIT << 7;
+ IoWrite8(AmiComParameters->BaseAddress + LCR_OFFSET, Data8 );
+
+ //
+ //Program the Baud Rate
+ //
+ IoWrite8(AmiComParameters->BaseAddress + DIV_LSB, Divisor & 0xFF);
+ IoWrite8(AmiComParameters->BaseAddress + DIV_MSB, Divisor >> 8);
+
+ //
+ // Clear DLAB bit in LCR
+ //
+ Data8 &= ~((UINT8)DLAB_BIT << 7);
+ IoWrite8(AmiComParameters->BaseAddress + LCR_OFFSET, Data8 );
+ }
+
+ return EFI_SUCCESS;
+}
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Name: EnableLegacySredir
+//
+// Description: This function is used for enabling the legacy Serial Redirection
+// This function contains calls for Intialising Serial ports and
+// hooking the interrupts which are required for purpose of Redirection
+//
+// Input: This
+// Indicates the AMI_LEGACY_SREDIR_PROTOCOL instance.
+//
+//
+// Output: EFI_SUCCESS
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS
+EnableLegacySredir (
+ IN AMI_LEGACY_SREDIR_PROTOCOL * This
+)
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ EFI_IA32_REGISTER_SET RegSet;
+ AMI_COM_PARAMETERS AmiComParameters;
+ UINT32 SdlParameters=0;
+ AMI_COM_PARAMETERS *SredirSetupComParameters;
+ UINTN StructStartAddress = NULL;
+
+ if(RedirectionStatus) {
+ return EFI_NOT_FOUND;
+ }
+
+ if(pLegacy==NULL) {
+ Status = pBS->LocateProtocol(&gEfiLegacyBiosProtocolGuid, NULL, &pLegacy);
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+ }
+
+ //
+ //Getting Setup values from terminal module
+ //
+ Status = GetSetupValuesForLegacySredir(&AmiComParameters);
+
+ if(EFI_ERROR(Status)){
+ return Status;
+ }
+ //
+ //Copy the Sredir.bin into Base Memory
+ //
+ Status=CopySredirBinIntoBaseMemory(This);
+
+ if(EFI_ERROR(Status)){
+ return Status;
+ }
+
+ //
+ //Serial Redirection starting Address
+ //
+ mLegacySreDirHeader = (AMI_LEGACYSREDIR_TABLE*)gSreDirImageStart;
+
+ if (mLegacySreDirHeader == NULL) return EFI_NOT_FOUND;
+
+#if DISPLAY_WHOLE_SCREEN
+ SdlParameters |= DISPLAY_SCREEN;
+#endif
+#if TRAP_INT10_WORKAROUND
+ SdlParameters |= INT10_WORKAROUND;
+#endif
+#if SERIAL_READ_WRITE_CALLBACK
+ SdlParameters |= SERIAL_READWRITE_CALLBACK;
+#endif
+#if CTRLI_KEY_MAPPING
+ SdlParameters |= CTRLI_MAPPING;
+#endif
+#if CTRLH_KEY_MAPPING
+ SdlParameters |= CTRLH_MAPPING;
+#endif
+#if SERIAL_WRITE_ERROR_CHECK
+ SdlParameters |= SERIAL_ERROR_CHECK;
+#endif
+#if OEM_ESC_SEQUENCES
+ SdlParameters |= ESC_SEQUENCES;
+#endif
+#if COM_MMIO_WIDTH == 1
+ SdlParameters |= MMIO_BYTE_WIDTH;
+#endif
+#if COM_MMIO_WIDTH == 2
+ SdlParameters |= MMIO_WORD_WIDTH;
+#endif
+#if COM_MMIO_WIDTH == 4
+ SdlParameters |= MMIO_DWORD_WIDTH;
+#endif
+
+
+ Status=InitilizeBuadRate(&AmiComParameters);
+
+ if(EFI_ERROR(Status)){
+ return Status;
+ }
+
+ //
+ //Initilize the Non Standard Serial Port Regsiters.
+ //
+ Status = InitilizeNonCommonSerialRegsiters(&AmiComParameters);
+
+ if(EFI_ERROR(Status)){
+ return Status;
+ }
+
+ if(AmiComParameters.MMIOBaseAddress != 0) {
+ SdlParameters |= MMIO_DEVICE;
+ AmiComParameters.BaseAddress = 0;
+ AmiComParameters.SwSMIValue = LEGACY_SREDIR_SWSMI;
+#if defined(SW_SMI_IO_ADDRESS)
+ AmiComParameters.SwSMIPort = SW_SMI_IO_ADDRESS;
+#endif
+ }
+
+
+ AmiComParameters.SdlParameters = SdlParameters;
+
+ AmiComParameters.SredirBinSize=SREDIR_BIN_SIZE;
+ AmiComParameters.RefreshScreenKey = REFRESH_SCREEN_KEY;
+ AmiComParameters.UartPollingRedirection = UART_POLLING_REDIRECTION;
+
+ //
+ // Transfer the Setup Values and Com Parameters from EFI to Legacy.
+ //
+
+ SredirSetupComParameters = (AMI_COM_PARAMETERS *)(gSreDirImageStart + (mLegacySreDirHeader->SreDirEfiToLegacyOffset));
+
+ pBS->CopyMem((VOID*)SredirSetupComParameters, (VOID*)&AmiComParameters, sizeof(AMI_COM_PARAMETERS));
+
+ StructStartAddress = (UINTN )SredirSetupComParameters;
+
+ if(LegacyOSBooting) {
+ Status=DataCopiedToCsm16Function(StructStartAddress, &AmiComParameters);
+
+ if(EFI_ERROR(Status)){
+ return Status;
+ }
+ }
+
+ pBS->SetMem(&RegSet, sizeof (EFI_IA32_REGISTER_SET), 0);
+ RegSet.X.AX = LEGACY_SreDirInitializeSerialPort;
+
+ RegSet.X.BX = MAXIMUM_SERIAL_WRITE_ERROR_COUNT;
+ RegSet.X.CX = MAX_FAILURES_ALLOWED;
+#if ACPI_SUPPORT
+ #if FACP_FLAG_TMR_VAL_EXT
+ RegSet.E.EDX = TIMER_SIGNATURE_32BIT;
+ #else
+ RegSet.E.EDX = TIMER_SIGNATURE_24BIT;
+ #endif
+#if ACPI_TIMER_IN_LEGACY_SUPPORT
+ RegSet.X.DX = PM_TMR_BLK_ADDRESS;
+#else
+ RegSet.X.DX = 0;
+#endif
+#endif
+
+ Status = pLegacy->FarCall86(pLegacy,
+ (UINT16)(gSreDirImageStart>>4),
+ mLegacySreDirHeader->SreDirOffset,
+ &RegSet,
+ NULL,
+ 0);
+
+ if(EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ pBS->SetMem(&RegSet, sizeof (EFI_IA32_REGISTER_SET), 0);
+ RegSet.X.AX = LEGACY_SerialRedirection;
+
+
+ Status = pLegacy->FarCall86(pLegacy,
+ (UINT16)(gSreDirImageStart>>4),
+ mLegacySreDirHeader->SreDirOffset,
+ &RegSet,
+ NULL,
+ 0);
+
+ if(EFI_ERROR(Status)) {
+ return Status;
+ }
+
+/*
+ //
+ // Intel wants to have interface to get the Original Int10, Int0c and Int14
+ // Address. By default this code is disabled.
+ //
+ pBS->SetMem(&RegSet, sizeof (EFI_IA32_REGISTER_SET), 0);
+
+ RegSet.X.AX = LEGACY_GetInterruptAddress; //returns Int10,Int0c,Int14 original
+ //vector address in EAX,EBX and ECX
+
+ Status = pLegacy->FarCall86(pLegacy,
+ (UINT16)(gSreDirImageStart>>4),
+ mLegacySreDirHeader->SreDirOffset,
+ &RegSet,
+ NULL,
+ 0);
+
+ Int10hAddress = RegSet.E.EAX;
+ Int0chAddress = RegSet.E.EBX;
+ Int14hAddress = RegSet.E.ECX;
+*/
+ RedirectionStatus=TRUE;
+ return Status;
+}
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Name: DisableLegacySredir
+//
+// Description: This function is used to disable the Legacy Serial redirection
+// This function contains calls for functions which are used to
+// release the interrupts which are used for Serial Redirection
+//
+// Input: This
+// Indicates the AMI_LEGACY_SREDIR_PROTOCOL instance.
+//
+//
+// Output: EFI_SUCCESS
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS
+DisableLegacySredir (
+ IN AMI_LEGACY_SREDIR_PROTOCOL * This
+)
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ EFI_IA32_REGISTER_SET RegSet;
+
+ if(!RedirectionStatus) {
+ return EFI_NOT_FOUND;
+ }
+
+ if(pLegacy==NULL) {
+ Status = pBS->LocateProtocol(&gEfiLegacyBiosProtocolGuid, NULL, &pLegacy);
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+ }
+
+ //
+ //Serial Redirection starting Address
+ //
+ mLegacySreDirHeader = (AMI_LEGACYSREDIR_TABLE*)gSreDirImageStart;
+
+ if (mLegacySreDirHeader == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ pBS->SetMem(&RegSet, sizeof (EFI_IA32_REGISTER_SET), 0);
+ RegSet.X.AX = LEGACY_ReleaseSerialRedirection;
+
+ Status = pLegacy->FarCall86(pLegacy,
+ (UINT16)(gSreDirImageStart>>4),
+ mLegacySreDirHeader->SreDirOffset,
+ &RegSet,
+ NULL,
+ 0);
+
+ RedirectionStatus=FALSE;
+
+ return Status;
+}
+
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Name: FindLegacySredirRom
+//
+// Description: This function searches for ROM within the data previously loaded
+// from the main FV image and returns its pointer and size.
+//
+// Input: Module Id
+// Vendor Id
+// Device Id
+// Image Start Address
+// Image Size
+//
+// Output: EFI_SUCCESS or EFI_NOT_FOUND
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS FindLegacySredirRom(
+ UINT16 ModuleId, UINT16 VendorId, UINT16 DeviceId,
+ VOID **ImageStart, UINT32 *ImageSize
+)
+{
+#pragma pack(push,1)
+ typedef struct{
+ UINT16 ModuleId, VendorId, DeviceId;
+ UINT32 Size;
+ } OPROM_HEADER;
+#pragma pack(pop)
+
+ OPROM_HEADER *Header;
+ for( Header = (OPROM_HEADER*)EmbeddedRom
+ ; (UINT8*)Header<(UINT8*)EmbeddedRom+EmbeddedRomSize
+ ; Header = (OPROM_HEADER*)((UINT8*)(Header+1)+Header->Size)
+ )
+ {
+ if ( Header->ModuleId==ModuleId
+ && Header->VendorId==VendorId
+ && Header->DeviceId==DeviceId
+ )
+ {
+ *ImageStart = Header+1;
+ *ImageSize=Header->Size;
+ return EFI_SUCCESS;
+ }
+ }
+ return EFI_NOT_FOUND;
+}
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Name: Legacy_OS_SerialRedirection
+//
+// Description: This function is used for Legacy Serial Redirection
+//
+// Input: EFI_Hanlde - Image Handle
+// EFI_System_Table - Pointer to System Table
+//
+// Output: EFI_SUCCESS or EFI_NOT_FOUND
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS Legacy_OS_SerialRedirection (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+)
+{
+
+ EFI_STATUS Status;
+ AMI_LEGACY_SREDIR_PROTOCOL *LegacySredir=NULL;
+
+ Status=pBS->LocateProtocol(&gAmiLegacySredirProtocolGuid, NULL, &LegacySredir);
+
+ if(EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ LegacyOSBooting=TRUE;
+ Status = LegacySredir->EnableLegacySredir(LegacySredir);
+
+ return Status;
+
+}
+
+#if CLEAR_LEGACYSREDIR_KB_BUFFER_AT_READYTOBOOT
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Name: ClearKbCharBuffer
+//
+// Description: Function to clear the Keyboard character buffer
+// (in the 16-bit Serial Redirection module)
+//
+// Input: IN EFI_EVENT Event
+// IN VOID *Context
+//
+// Output: None
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+VOID
+ClearKbCharBuffer (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+)
+{
+ EFI_IA32_REGISTER_SET RegSet;
+
+ //
+ // Serial Redirection starting Address
+ //
+ mLegacySreDirHeader = (AMI_LEGACYSREDIR_TABLE*)gSreDirImageStart;
+
+ if (mLegacySreDirHeader != NULL) {
+ pBS->SetMem(&RegSet, sizeof (EFI_IA32_REGISTER_SET), 0);
+ RegSet.X.AX = LEGACY_ClearKbCharBuffer;
+
+ pLegacy->FarCall86(pLegacy,
+ mLegacySreDirHeader->SreDirSegment,
+ mLegacySreDirHeader->SreDirOffset,
+ &RegSet,
+ NULL,
+ 0);
+ }
+
+ pBS->CloseEvent(Event);
+}
+#endif
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+// Name: LegacySreDirNotInSmmFunction
+//
+// Description: Legacy Serial Redirection Non Smm entry point
+//
+// Input: Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT
+// EFI System Table - Pointer to System Table
+//
+// Output: EFI_STATUS OR EFI_NOT_FOUND
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS
+LegacySreDirNotInSmmFunction(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ EFI_GUID gFile;
+ EFI_FIRMWARE_VOLUME_PROTOCOL *pFV;
+ UINT32 Authentication;
+ EFI_HANDLE NewHandle;
+#if CLEAR_LEGACYSREDIR_KB_BUFFER_AT_READYTOBOOT
+ EFI_EVENT ReadyToBootEvent;
+#endif
+
+
+ Status = pBS->HandleProtocol(ImageHandle, &gEfiLoadedImageGuid, &LoadedImage);
+
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ //
+ // Now we have EFI_DEVICE_PATH *LoadedImage->FilePath
+ //
+ gFile = ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH*)(LoadedImage->FilePath))->NameGuid;
+
+ //
+ // Get the Firmware Volume Protocol
+ //
+ Status = pBS->HandleProtocol (
+ LoadedImage->DeviceHandle,
+ &gEfiFirmwareVolumeProtocol,
+ &pFV
+ );
+
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ //
+ // Read section with Legacy ROMs
+ //
+ EmbeddedRom = NULL; // make ReadSection allocate memory
+ EmbeddedRomSize = 0;
+ Status = pFV->ReadSection (
+ pFV,
+ &gFile,
+ EFI_SECTION_RAW,
+ 0,
+ &EmbeddedRom,
+ &EmbeddedRomSize,
+ &Authentication);
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ NewHandle = NULL;
+ Status = pBS->InstallProtocolInterface (
+ &NewHandle,
+ &gAmiLegacySredirProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &gLegacySredir
+ );
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+
+#if CLEAR_LEGACYSREDIR_KB_BUFFER_AT_READYTOBOOT
+ //
+ // Register the ReadyToBoot event function to clear the Keyboard
+ // character buffer (in the 16-bit Serial Redirection module)
+ //
+#if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT) && (EFI_SPECIFICATION_VERSION < 0x20000)
+ pBS->CreateEvent(
+ EFI_EVENT_SIGNAL_READY_TO_BOOT,
+ TPL_NOTIFY,
+ ClearKbCharBuffer,
+ NULL,
+ &ReadyToBootEvent
+ );
+#else
+ CreateReadyToBootEvent(TPL_CALLBACK,
+ ClearKbCharBuffer,
+ NULL,
+ &ReadyToBootEvent
+ );
+#endif
+#endif
+
+#if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT) && (EFI_SPECIFICATION_VERSION < 0x20000)
+ Status = pBS->CreateEvent(
+ EFI_EVENT_SIGNAL_LEGACY_BOOT,
+ TPL_CALLBACK,
+ Legacy_OS_SerialRedirection,
+ NULL,
+ &SreDir
+ );
+#else
+ Status = CreateLegacyBootEvent(
+ TPL_CALLBACK,
+ Legacy_OS_SerialRedirection,
+ NULL,
+ &SreDir
+ );
+#endif
+ ASSERT_EFI_ERROR(Status);
+ return Status;
+}
+
+//<AMI_PHDR_START>
+//---------------------------------------------------------------------------
+//
+// Name: LegacySredirEntryPoint
+//
+// Description: Legacy Serial Redirection driver entry point
+//
+// Input: Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT
+// EFI System Table - Pointer to System Table
+//
+// Output: EFI_STATUS OR EFI_NOT_FOUND
+//
+//---------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+EFI_STATUS
+LegacySredirEntryPoint(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ InitAmiLib(ImageHandle, SystemTable);
+ return InitSmmHandler(ImageHandle, SystemTable, LegacySreDirInSmmFunction, LegacySreDirNotInSmmFunction);
+
+}
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/Sredir/LegacySredir.chm b/Core/EM/Sredir/LegacySredir.chm
new file mode 100644
index 0000000..42fa76d
--- /dev/null
+++ b/Core/EM/Sredir/LegacySredir.chm
Binary files differ
diff --git a/Core/EM/Sredir/LegacySredir.cif b/Core/EM/Sredir/LegacySredir.cif
new file mode 100644
index 0000000..ca866ba
--- /dev/null
+++ b/Core/EM/Sredir/LegacySredir.cif
@@ -0,0 +1,19 @@
+<component>
+ name = "Legacy Serial Redirection"
+ category = eModule
+ LocalRoot = "Core\EM\Sredir\"
+ RefName = "LEGACYSREDIR"
+[files]
+"LegacySredir.mak"
+"LegacySredir.sdl"
+"LegacySredir.dxs"
+"LegacySredir.c"
+"LegacySmmSredir.c"
+"LegacySredir.chm"
+"SerialBootCall.asm"
+"SredirBootFail.asm"
+[parts]
+"LSREDIR_BOARD"
+"LSREDIR_BIN"
+"LEGACY_SREDIR_PROTOCOL"
+<endComponent>
diff --git a/Core/EM/Sredir/LegacySredir.dxs b/Core/EM/Sredir/LegacySredir.dxs
new file mode 100644
index 0000000..5532cd0
--- /dev/null
+++ b/Core/EM/Sredir/LegacySredir.dxs
@@ -0,0 +1,104 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2009, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySredir.dxs 7 6/25/13 4:41a Rameshr $
+//
+// $Revision: 7 $
+//
+// $Date: 6/25/13 4:41a $
+//**********************************************************************
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySredir.dxs $
+//
+// 7 6/25/13 4:41a Rameshr
+// [TAG] EIP125655
+// [Category] Improvement
+// [Description] MMIO Address validated before reading or writing to the
+// MMIO region in the SW SMI handler
+// [Files] LegacySmmSredir.c, LegacySredir.dxs
+//
+// 6 4/10/12 12:50a Rameshr
+// [TAG] EIP84345
+// [Category] Improvement
+// [Description] Error checking and SMM dependency added
+// [Files] LegacySmmSredir.c, LegacySredir.dxs
+//
+// 5 3/05/10 4:19a Rameshr
+// MMIO COM device support added.
+// EIP 33847
+//
+// 4 6/29/09 12:11p Rameshr
+// Coding Standard and File header updated.
+//
+// 3 12/24/08 3:51p Rameshraju
+// Added the dependency for LegacyBios
+//
+// 2 4/17/07 4:41a Rameshraju
+// PCIserial support added
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//**********************************************************************
+// Name: LegacySredir.dxs
+//
+// Description: Dependancy Expression file for Legacy Serial Redirection
+//
+//**********************************************************************
+//<AMI_FHDR_END>
+
+#include <Protocol/LegacyRegion.h>
+#include <Protocol/LegacyInterrupt.h>
+#include <Protocol/Legacy8259.h>
+#include <Protocol/FirmwareVolume.h>
+#include <Protocol/Cpu.h>
+#include <Protocol/LegacyBios.h>
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION >= 0x4028B)
+#include <Protocol\SmmBase2.h>
+#include <Protocol\SmmSwDispatch2.h>
+#else
+#include <Protocol/SmmBase.h>
+#include <Protocol/SmmSwDispatch.h>
+#endif
+
+DEPENDENCY_START
+ EFI_LEGACY_INTERRUPT_PROTOCOL_GUID AND
+ EFI_LEGACY_REGION_PROTOCOL_GUID AND
+ EFI_LEGACY_8259_PROTOCOL_GUID AND
+ EFI_FIRMWARE_VOLUME_PROTOCOL_GUID AND
+ EFI_LEGACY_BIOS_PROTOCOL_GUID AND
+ EFI_CPU_ARCH_PROTOCOL_GUID AND
+#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)&&(CORE_COMBINED_VERSION >= 0x4028B)
+ EFI_SMM_BASE2_PROTOCOL_GUID AND
+ EFI_SMM_SW_DISPATCH2_PROTOCOL_GUID
+#else
+ EFI_SMM_BASE_PROTOCOL_GUID AND
+ EFI_SMM_SW_DISPATCH_PROTOCOL_GUID
+#endif
+DEPENDENCY_END
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2009, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/Sredir/LegacySredir.mak b/Core/EM/Sredir/LegacySredir.mak
new file mode 100644
index 0000000..814d9a6
--- /dev/null
+++ b/Core/EM/Sredir/LegacySredir.mak
@@ -0,0 +1,135 @@
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2009, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
+# $Header: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySredir.mak 8 12/08/14 3:36a Anbuprakashp $
+#
+# $Revision: 8 $
+#
+# $Date: 12/08/14 3:36a $
+#**********************************************************************
+#**********************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/Legacy Serial Redirection/LegacySredir.mak $
+#
+# 8 12/08/14 3:36a Anbuprakashp
+# [TAG] EIP192305
+# [Category] Improvement
+# [Description] Replacing SmmGetMemoryType usage in LegacySredir module
+# with AmiBufferValidationLib
+# [Files] LegacySredir.mak, LegacySmmSredir.c, LegacySredir_Setup.C
+#
+# 7 2/27/12 5:49a Jittenkumarp
+# [TAG] EIP81401
+# [Category] New Feature
+# [Description] Select Redirection After BIOS POST as BootLoader in
+# serial redirection, the behaviour is not same as Core8.
+# [Files] LegacySredir.c, LegacySredir.mak, LegacySredir.sdl,
+# LegacySredir_Setup.c, LegacySredir.h ,SerialBootCall.asm,
+# SredirBootFail.asm,GRAPHREDIR.ASM, INT10REDIR.ASM, OR_MOD.EQU,
+# SREDIR.ASM
+#
+# 6 9/20/10 4:09a Rameshr
+# [TAG]- EIP 44007
+# [Category]-IMPROVEMENT
+# [Description]- Invalid PCI COM device list added as Elink. These
+# devices will not be used for Redirection.
+# [Files]- LegacySredir.mak, LegacySredir.sdl, LegacySredir_Setup.c
+#
+# 5 5/03/10 1:55a Rameshr
+# Callback function added for read and write function of the Serial Port.
+# EIP 37850
+#
+# 4 6/29/09 12:11p Rameshr
+# Coding Standard and File header updated.
+#
+# 3 11/06/08 9:54a Rameshraju
+# Guid's updated.
+#
+# 2 4/17/07 4:41a Rameshraju
+# PCIserial support added
+#
+#**********************************************************************
+#<AMI_FHDR_START>
+#**********************************************************************
+#
+# Name: LegacySredir.MAK
+#
+# Description: Make file for the Legacy Serial Redirection Module part
+#
+#**********************************************************************
+#<AMI_FHDR_END>
+
+all : LEGACYSREDIR
+
+LEGACYSREDIR : $(BUILD_DIR)\LEGACYSREDIR.mak SerialCallBack LEGACYR_ROM LEGACYSREDIRBin
+
+$(BUILD_DIR)\LEGACYSREDIR.mak : $(LEGACYSREDIR_DIR)\LEGACYSREDIR.cif $(LEGACYSREDIR_BOARD_DIR)\LegacySredir-Board.cif $(LEGACYSREDIR_DIR)\LEGACYSREDIR.mak $(BUILD_RULES)
+ $(CIF2MAK) $(LEGACYSREDIR_DIR)\LEGACYSREDIR.cif $(LEGACYSREDIR_BOARD_DIR)\LegacySredir-Board.cif $(CIF2MAK_DEFAULTS)
+
+LEGACYSREDIR_INCLUDES = $(AMIDXELIB) \
+ $(AMICSPLib) \
+ $(BUILD_DIR)\AmiBufferValidationLib.lib
+
+LegacySreDir_OBJECTS = \
+$(BUILD_DIR)\$(LEGACYSREDIR_DIR)\LegacySredir.obj \
+$(BUILD_DIR)\$(LEGACYSREDIR_DIR)\LegacySmmSredir.obj \
+$(BUILD_DIR)\$(LEGACYSREDIR_BOARD_DIR)\LegacySredir_Setup.obj
+
+LEGACYSREDIRBin : $(LEGACYSREDIR_INCLUDES)
+ @set INCLUDE=%%INCLUDE%%
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\LEGACYSREDIR.mak all\
+ GUID=4A3602BC-1A05-4c82-99B4-588CD2A32CD5 \
+ ENTRY_POINT=LegacySredirEntryPoint \
+ "CFLAGS=$(CFLAGS) /I$(LEGACYSREDIR_DIR) /D\"INVALID_PCICOM_DEVICELIST=$(InvalidPciComDeviceList)\"" \
+ "OBJECTS=$(LegacySreDir_OBJECTS)"\
+ TYPE=BS_DRIVER \
+ EXT_HEADERS=$(BUILD_DIR)\token.h\
+ BINFILE=$(BUILD_DIR)\ROMss.bin \
+ SECTION_GUID=9BA21891-7E7D-4e94-B8DF-F4D2D320801C \
+ COMPRESS=1\
+
+SerialCallBack: $(BUILD_DIR)\SerialCallback.obj
+
+$(BUILD_DIR)\SerialCallback.obj: $(LEGACYSREDIR_BOARD_DIR)\SerialCallback.asm
+ $(ASM) /c /nologo /Fo$(BUILD_DIR)\ /Fl$(BUILD_DIR)\ $(LEGACYSREDIR_BOARD_DIR)\SerialCallback.asm
+
+$(BUILD_DIR)\SerialBootCall.obj: $(LEGACYSREDIR_DIR)\SerialBootCall.asm
+ $(ASM) /c /nologo /Fo$(BUILD_DIR)\ /Fl$(BUILD_DIR)\ $(LEGACYSREDIR_DIR)\SerialBootCall.asm
+
+$(BUILD_DIR)\SredirBootFail.obj: $(LEGACYSREDIR_DIR)\SredirBootFail.asm
+ $(ASM) /c /nologo /Fo$(BUILD_DIR)\ /Fl$(BUILD_DIR)\ $(LEGACYSREDIR_DIR)\SredirBootFail.asm
+
+LEGACYR_ROM :
+ $(PACKOPROM) /o$(BUILD_DIR)\ROMss.bin <<$(BUILD_DIR)\ROMss.inf
+[MODULE]
+ModuleID = 3
+VendorID = 7
+DeviceID = 9
+File = addon\SREDIR.bin
+<<KEEP
+
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2008, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
diff --git a/Core/EM/Sredir/LegacySredir.sdl b/Core/EM/Sredir/LegacySredir.sdl
new file mode 100644
index 0000000..7941dd7
--- /dev/null
+++ b/Core/EM/Sredir/LegacySredir.sdl
@@ -0,0 +1,164 @@
+TOKEN
+ Name = "LEGACYSREDIR_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable AMI Legacy Serial Redirection support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+ Token = "CSM_SUPPORT" "=" "1"
+ Token = "Terminal_SUPPORT" "=" "1"
+End
+
+PATH
+ Name = "LEGACYSREDIR_DIR"
+ Path = "core\em\sredir"
+End
+
+TOKEN
+ Name = "DISPLAY_WHOLE_SCREEN"
+ Value = "0"
+ Help = "Display the whole screen before disabling the Legacy console redirection"
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TRAP_INT10_WORKAROUND"
+ Value = "0"
+ Help = "Trap Int10 to avoid the b8000 region accessed by Video option rom and Legacy console redirection."
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "SERIAL_READ_WRITE_CALLBACK"
+ Value = "0"
+ Help = "1- Call back will come from Sredir.bin for SerialRead and SerialWrite(SerialCallback.asm).0-Disabled."
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "LEGACY_SREDIR_SWSMI"
+ Value = "0x41"
+ Help = "SW SMI value to be used in Legacy console redirection"
+ TokenType = Integer
+ TargetH = Yes
+ Range = "0...0FFh"
+End
+
+TOKEN
+ Name = "COM_MMIO_WIDTH"
+ Value = "4"
+ Help = "MMIO Com device width size. 1- Byte, 2- Word, 4-Dword. Default Set to Dword"
+ TokenType = Integer
+ TargetH = Yes
+ Range = "1...4h"
+End
+
+TOKEN
+ Name = "CTRLI_KEY_MAPPING"
+ Value = "1"
+ Help = "0- Mapped to TAB key, 1- Mapped to CtrlI Key"
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "CTRLH_KEY_MAPPING"
+ Value = "1"
+ Help = "0- Mapped to BackSpace Key, 1- Mapped to CtrlH Key"
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "CHECK_FOR_LOOPBACK_DEVICE"
+ Value = "0"
+ Help = "0- hardware Loop back checking disabled 1- Hardware loopback checking enabled and if present redirection skipped for the port"
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "CLEAR_LEGACYSREDIR_KB_BUFFER_AT_READYTOBOOT"
+ Value = "0"
+ Help = "ON -> Legacy Serial Redirection KB Buffer will be cleared at ReadyToBoot.\OFF -> Legacy Serial Redirection KB Buffer will not be cleared at ReadyToBoot."
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "UART_POLLING_REDIRECTION"
+ Value = "0"
+ Help = "Use polling method redirection to send and receive data from COM Port"
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+PATH
+ Name = "LEGACYSREDIR_BOARD_DIR"
+ Path = "Board\em\sredir"
+End
+
+MODULE
+ Help = "Includes LegacySredir.cif to Project"
+ Path = "$(LEGACYSREDIR_DIR)"
+ File = "LEGACYSREDIR.mak"
+End
+
+ELINK
+ Name = "InvalidPciComDeviceList"
+ InvokeOrder = ReplaceParent
+ Help = "Invalid PCI Device List to skip the redirection from that device. Format of the InvalidPciComDeviceList is {VendorId, DeviceId), "
+End
+
+ELINK
+ Name = "SerialCallBackApiModuleStart"
+ Parent = "CsmOem16Functions"
+ ProcID = 0Bh
+ SrcFile = "$(LEGACYSREDIR_BOARD_DIR)\SerialCallback.asm"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\SerialCallback.obj"
+ Parent = "CSM_OEM16_OBJS"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "LegcaySredirModuleStart"
+ Parent = "CsmOem16Functions"
+ ProcID = 08h
+ SrcFile = "Core\em\Sredir\SerialBootCall.asm"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\SerialBootCall.obj"
+ Parent = "CSM_OEM16_OBJS"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "EnableLegcaySredirModuleStart"
+ Parent = "CsmOem16Functions"
+ ProcID = 06h
+ SrcFile = "Core\em\Sredir\SredirBootFail.asm"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\SredirBootFail.obj"
+ Parent = "CSM_OEM16_OBJS"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\LEGACYSREDIR.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End
diff --git a/Core/EM/Sredir/SerialBootCall.asm b/Core/EM/Sredir/SerialBootCall.asm
new file mode 100644
index 0000000..ebd9c1b
--- /dev/null
+++ b/Core/EM/Sredir/SerialBootCall.asm
@@ -0,0 +1,180 @@
+;**********************************************************************
+;**********************************************************************
+;** **
+;** (C)Copyright 1985-2014, American Megatrends, Inc. **
+;** **
+;** All Rights Reserved. **
+;** **
+;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+;** **
+;** Phone: (770)-246-8600 **
+;** **
+;**********************************************************************
+;**********************************************************************
+
+;**********************************************************************
+; $Header: /Alaska/SOURCE/Modules/Legacy Serial Redirection/SerialBootCall.asm 3 6/16/14 7:39a Divyac $
+;
+; $Revision: 3 $
+;
+; $Date: 6/16/14 7:39a $
+;**********************************************************************
+; Revision History
+; ----------------
+; $Log: /Alaska/SOURCE/Modules/Legacy Serial Redirection/SerialBootCall.asm $
+;
+; 3 6/16/14 7:39a Divyac
+; [TAG] EIP172120
+; [Category] Bug Fix
+; [Severity] Important
+; [Symptom] Redirection After BIOS POST feature is not working.
+; [RootCause] The flag Indicating whether redirection can happen or not
+; is not updated.
+; 1)The way of Defining signatures and Comparing Signatures are
+; different.
+; 2)The variables defined in CSM16 files( SreDirBin_Base_Segadd,
+; SreDirBin_Base_Offadd, Flag ) are accessed wrongly.
+;
+; [Solution] a) The pointer used to check for signatures must be
+; UINT32* or we should define signatures byte by byte (db
+; '$','S','B','F', db '$','S','B','C'). so changed the way of defining
+; Signatures in CSM16 files from dd '$SBF' to db '$','S','B','F'.
+; b) Variables should be accessed using OFFSET Keyword.
+; [Files] SerialBootCall.asm, SerialBootFail.asm
+;
+; 2 5/29/13 8:53a Srikantakumarp
+; [TAG] EIP122394
+; [Category] Bug Fix
+; [Severity] Normal
+; [Symptom] 0xE0000~0xEFFFF was overwrite by Legacy Serial Redirection
+; module.
+; [RootCause] LegacySerialRedirection driver assumed that
+; SerialBootcall.asm will be the first entry in CsmOem16Functions which
+; was wrong.
+; [Solution] Added a Signature check code for SerialBootCall.asm and
+; SredirBootFail.asm before it writes to the memory location
+; 0xE0000~0xEFFFF.
+; [Files] LegacySredir.c, SerialBootCall.asm, SredirBootFail.asm
+;
+; 1 2/27/12 5:57a Jittenkumarp
+; [TAG] EIP81401
+; [Category] New Feature
+; [Description] Select Redirection After BIOS POST as BootLoader in
+; serial redirection, the behaviour is made same as Core8.
+; [Files] LegacySredir.c, LegacySredir.mak, LegacySredir.sdl,
+; LegacySredir_Setup.c, LegacySredir.h ,SerialBootCall.asm,
+; SredirBootFail.asm,GRAPHREDIR.ASM, INT10REDIR.ASM, OR_MOD.EQU,
+; SREDIR.ASM
+;
+;**********************************************************************
+;<AMI_FHDR_START>
+;
+; Name: SerialBootCall.asm
+;
+; Description: Call Back function registered for
+; CSM16_OEM_BEFORE_CALL_BOOT_VECTOR
+;
+;<AMI_FHDR_END>
+;**********************************************************************
+
+
+;----------------------------------------------------------------------------
+; INCLUDE FILES
+;----------------------------------------------------------------------------
+
+ include token.equ
+
+;----------------------------------------------------------------------------
+; EXTERNS USED
+;----------------------------------------------------------------------------
+
+.586p
+OEM16_CSEG SEGMENT PARA PUBLIC 'CODE' USE16
+ ASSUME cs:OEM16_CSEG, ds:OEM16_CSEG
+;-------------------------------------------------------------------------
+ PUBLIC LegcaySredirModuleStart
+LegcaySredirModuleStart LABEL BYTE
+ jmp SHORT LegcaySredirCsm16Api
+ db '$','S','B','C'
+SreDirBin_Base_Segadd dw 0000h ;SreDirBin Segement Address
+SreDirBin_Base_Offadd dw 0000h ;SreDirbin offset Address
+Flag dw 0000h
+
+;----------------------------------------------------------------------------
+; IMPORTANT: Do not put any OEM/CHIPSET code above this, the above code and
+; and data are at fixed locations.
+;----------------------------------------------------------------------------
+
+;-------------------------------------------------------------------------
+; LEGACYSREDIR_CSM16_API_Start
+;----------------------------------------------------------------------------
+; This routine is implementation of the CSM16 API #8.
+;
+; Input: BX - SreDirBin Segment add
+; BX - SreDirBin Offset add
+; AX - Flag offset value
+;
+; Output: None
+;
+; Register Usage: Do not destroy any register
+;
+;----------------------------------------------------------------------------
+
+LegcaySredirCsm16Api PROC FAR PUBLIC
+; Adjust current IP so that the data offsets are valid
+
+ call $+3 ; Push curent IP
+ pop bx ; Get current IP in BX
+ shr bx, 4
+ mov ax, cs ; Always x000h
+ add ax, bx ; New CS
+ push ax
+ push newOffset-LegcaySredirModuleStart
+ retf ; Execute from new CS:IP
+
+newOffset:
+
+ push bx
+ push si
+ push ax
+ push es
+ push 0
+ pop es
+ mov si, offset SreDirBin_Base_Segadd
+ mov bx, word ptr cs:[si]
+ mov es, bx
+ mov si, offset SreDirBin_Base_Offadd
+ mov bx, word ptr cs:[si]
+ mov si, offset Flag
+ mov ax, word ptr cs:[si]
+ mov si, ax
+ add si, bx
+ mov al, 01h
+ mov byte ptr es:[si], al
+
+ pop es
+ pop ax
+ pop si
+ pop bx
+
+ retf
+
+LegcaySredirCsm16Api ENDP
+
+OEM16_CSEG ENDS
+
+END
+
+;**********************************************************************
+;**********************************************************************
+;** **
+;** (C)Copyright 1985-2012, American Megatrends, Inc. **
+;** **
+;** All Rights Reserved. **
+;** **
+;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+;** **
+;** Phone: (770)-246-8600 **
+;** **
+;**********************************************************************
+;********************************************************************** \ No newline at end of file
diff --git a/Core/EM/Sredir/SredirBootFail.asm b/Core/EM/Sredir/SredirBootFail.asm
new file mode 100644
index 0000000..b8433b9
--- /dev/null
+++ b/Core/EM/Sredir/SredirBootFail.asm
@@ -0,0 +1,179 @@
+;**********************************************************************
+;**********************************************************************
+;** **
+;** (C)Copyright 1985-2014, American Megatrends, Inc. **
+;** **
+;** All Rights Reserved. **
+;** **
+;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+;** **
+;** Phone: (770)-246-8600 **
+;** **
+;**********************************************************************
+;**********************************************************************
+
+;**********************************************************************
+; $Header: /Alaska/SOURCE/Modules/Legacy Serial Redirection/SredirBootFail.asm 3 6/16/14 7:40a Divyac $
+;
+; $Revision: 3 $
+;
+; $Date: 6/16/14 7:40a $
+;**********************************************************************
+; Revision History
+; ----------------
+; $Log: /Alaska/SOURCE/Modules/Legacy Serial Redirection/SredirBootFail.asm $
+;
+; 3 6/16/14 7:40a Divyac
+; [TAG] EIP172120
+; [Category] Bug Fix
+; [Severity] Important
+; [Symptom] Redirection After BIOS POST feature is not working.
+; [RootCause] The flag Indicating whether redirection can happen or not
+; is not updated.
+; 1)The way of Defining signatures and Comparing Signatures are
+; different.
+; 2)The variables defined in CSM16 files( SreDirBin_Base_Segadd,
+; SreDirBin_Base_Offadd, Flag ) are accessed wrongly.
+;
+; [Solution] a) The pointer used to check for signatures must be
+; UINT32* or we should define signatures byte by byte (db
+; '$','S','B','F', db '$','S','B','C'). so changed the way of defining
+; Signatures in CSM16 files from dd '$SBF' to db '$','S','B','F'.
+; b) Variables should be accessed using OFFSET Keyword.
+; [Files] SerialBootCall.asm, SerialBootFail.asm
+;
+; 2 5/29/13 8:54a Srikantakumarp
+; [TAG] EIP122394
+; [Category] Bug Fix
+; [Severity] Normal
+; [Symptom] 0xE0000~0xEFFFF was overwrite by Legacy Serial Redirection
+; module.
+; [RootCause] LegacySerialRedirection driver assumed that
+; SerialBootcall.asm will be the first entry in CsmOem16Functions which
+; was wrong.
+; [Solution] Added a Signature check code for SerialBootCall.asm and
+; SredirBootFail.asm before it writes to the memory location
+; 0xE0000~0xEFFFF.
+; [Files] LegacySredir.c, SerialBootCall.asm, SredirBootFail.asm
+;
+; 1 2/27/12 5:58a Jittenkumarp
+; [TAG] EIP81401
+; [Category] New Feature
+; [Description] Select Redirection After BIOS POST as BootLoader in
+; serial redirection, the behaviour is made same as Core8.
+; [Files] LegacySredir.c, LegacySredir.mak, LegacySredir.sdl,
+; LegacySredir_Setup.c, LegacySredir.h ,SerialBootCall.asm,
+; SredirBootFail.asm,GRAPHREDIR.ASM, INT10REDIR.ASM, OR_MOD.EQU,
+; SREDIR.ASM
+;
+;**********************************************************************
+;<AMI_FHDR_START>
+;
+; Name: SredirBootFail.asm
+;
+; Description: Call Back function registered for CSM16_OEM_ON_BOOT_FAIL
+;
+;<AMI_FHDR_END>
+;**********************************************************************
+
+
+;----------------------------------------------------------------------------
+; INCLUDE FILES
+;----------------------------------------------------------------------------
+
+ include token.equ
+
+;----------------------------------------------------------------------------
+; EXTERNS USED
+;----------------------------------------------------------------------------
+
+.586p
+OEM16_CSEG SEGMENT PARA PUBLIC 'CODE' USE16
+ ASSUME cs:OEM16_CSEG, ds:OEM16_CSEG
+;-------------------------------------------------------------------------
+ PUBLIC EnableLegcaySredirModuleStart
+EnableLegcaySredirModuleStart LABEL BYTE
+ jmp SHORT EnableLegcaySredirCsm16Api
+ db '$','S','B','F'
+SreDirBin_Base_Segadd dw 0000h ;SreDirBin Segement Address
+SreDirBin_Base_Offadd dw 0000h ;SreDirbin offset Address
+Flag dw 0000h
+
+
+;----------------------------------------------------------------------------
+; IMPORTANT: Do not put any OEM/CHIPSET code above this, the above code and
+; and data are at fixed locations.
+;----------------------------------------------------------------------------
+
+;-------------------------------------------------------------------------
+; LEGACYSREDIR_CSM16_API_Start
+;----------------------------------------------------------------------------
+; This routine is implementation of the CSM16 API #6.
+; Input: BX - SreDirBin Segment add
+; BX - SreDirBin Offset add
+; AX - Flag offset value
+;
+; Output: None
+;
+; Register Usage: Do not destroy any register
+;
+;----------------------------------------------------------------------------
+
+EnableLegcaySredirCsm16Api PROC FAR PUBLIC
+; Adjust current IP so that the data offsets are valid
+
+ call $+3 ; Push curent IP
+ pop bx ; Get current IP in BX
+ shr bx, 4
+ mov ax, cs ; Always x000h
+ add ax, bx ; New CS
+ push ax
+ push newOffset-EnableLegcaySredirModuleStart
+ retf ; Execute from new CS:IP
+
+newOffset:
+
+ push bx
+ push si
+ push ax
+ push es
+ push 0
+ pop es
+ mov si, offset SreDirBin_Base_Segadd
+ mov bx, word ptr cs:[si]
+ mov es, bx
+ mov si, offset SreDirBin_Base_Offadd
+ mov bx, word ptr cs:[si]
+ mov si, offset Flag
+ mov ax, word ptr cs:[si]
+ mov si, ax
+ add si, bx
+ mov al, 00h
+ mov byte ptr es:[si], al
+
+ pop es
+ pop ax
+ pop si
+ pop bx
+
+ retf
+
+EnableLegcaySredirCsm16Api ENDP
+
+OEM16_CSEG ENDS
+
+END
+
+;**********************************************************************
+;**********************************************************************
+;** **
+;** (C)Copyright 1985-2014, American Megatrends, Inc. **
+;** **
+;** All Rights Reserved. **
+;** **
+;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+;** **
+;** Phone: (770)-246-8600 **
+;** **
+;**********************************************************************
+;********************************************************************** \ No newline at end of file