Unix version of EFI emulator

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2182 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
tgingold
2007-01-06 14:59:06 +00:00
parent 8ba7afaf2e
commit c9093a06e7
187 changed files with 54299 additions and 0 deletions

View File

@ -0,0 +1,187 @@
/*++
Copyright (c) 2004, 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:
ComponentName.c
Abstract:
--*/
#include "Console.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
UnixConsoleComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
UnixConsoleComponentNameGetControllerName (
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
//
EFI_COMPONENT_NAME_PROTOCOL gUnixConsoleComponentName = {
UnixConsoleComponentNameGetDriverName,
UnixConsoleComponentNameGetControllerName,
"eng"
};
static EFI_UNICODE_STRING_TABLE mUnixConsoleDriverNameTable[] = {
{ "eng", L"Unix Text Console Driver" },
{ NULL , NULL }
};
EFI_STATUS
EFIAPI
UnixConsoleComponentNameGetDriverName (
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 LookupUnicodeString (
Language,
gUnixConsoleComponentName.SupportedLanguages,
mUnixConsoleDriverNameTable,
DriverName
);
}
EFI_STATUS
EFIAPI
UnixConsoleComponentNameGetControllerName (
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.
--*/
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOut;
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Get out context back
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextOutProtocolGuid,
(void *)&SimpleTextOut,
gUnixConsoleDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
return LookupUnicodeString (
Language,
gUnixConsoleComponentName.SupportedLanguages,
Private->ControllerNameTable,
ControllerName
);
}

View File

@ -0,0 +1,310 @@
/*++
Copyright (c) 2004 - 2005, 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:
Console.c
Abstract:
Console based on Win32 APIs.
--*/
#include "Console.h"
EFI_STATUS
EFIAPI
UnixConsoleDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
UnixConsoleDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
UnixConsoleDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
EFI_DRIVER_BINDING_PROTOCOL gUnixConsoleDriverBinding = {
UnixConsoleDriverBindingSupported,
UnixConsoleDriverBindingStart,
UnixConsoleDriverBindingStop,
0x10,
NULL,
NULL
};
EFI_STATUS
EFIAPI
UnixConsoleDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: Handle - add argument and description to function comment
// TODO: RemainingDevicePath - add argument and description to function comment
{
EFI_STATUS Status;
EFI_UNIX_IO_PROTOCOL *UnixIo;
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
Handle,
&gEfiUnixIoProtocolGuid,
(void *)&UnixIo,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Make sure that the Unix Thunk Protocol is valid
//
Status = EFI_UNSUPPORTED;
if (UnixIo->UnixThunk->Signature == EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {
//
// Check the GUID to see if this is a handle type the driver supports
//
if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixConsoleGuid)) {
Status = EFI_SUCCESS;
}
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
Handle,
&gEfiUnixIoProtocolGuid,
This->DriverBindingHandle,
Handle
);
return Status;
}
EFI_STATUS
EFIAPI
UnixConsoleDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: Handle - add argument and description to function comment
// TODO: RemainingDevicePath - add argument and description to function comment
{
EFI_STATUS Status;
EFI_UNIX_IO_PROTOCOL *UnixIo;
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
//
// Grab the IO abstraction we need to get any work done
//
Status = gBS->OpenProtocol (
Handle,
&gEfiUnixIoProtocolGuid,
(void *)&UnixIo,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (UNIX_SIMPLE_TEXT_PRIVATE_DATA),
(void *)&Private
);
if (EFI_ERROR (Status)) {
goto Done;
}
ZeroMem (Private, sizeof (UNIX_SIMPLE_TEXT_PRIVATE_DATA));
Private->Signature = UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE;
Private->Handle = Handle;
Private->UnixIo = UnixIo;
Private->UnixThunk = UnixIo->UnixThunk;
UnixSimpleTextOutOpenWindow (Private);
UnixSimpleTextInAttachToWindow (Private);
Status = gBS->InstallMultipleProtocolInterfaces (
&Handle,
&gEfiSimpleTextOutProtocolGuid,
&Private->SimpleTextOut,
&gEfiSimpleTextInProtocolGuid,
&Private->SimpleTextIn,
NULL
);
if (!EFI_ERROR (Status)) {
return Status;
}
Done:
gBS->CloseProtocol (
Handle,
&gEfiUnixIoProtocolGuid,
This->DriverBindingHandle,
Handle
);
if (Private != NULL) {
FreeUnicodeStringTable (Private->ControllerNameTable);
#if 0
if (Private->NtOutHandle != NULL) {
Private->UnixThunk->CloseHandle (Private->NtOutHandle);
}
#endif
if (Private->SimpleTextIn.WaitForKey != NULL) {
gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
}
gBS->FreePool (Private);
}
return Status;
}
EFI_STATUS
EFIAPI
UnixConsoleDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Handle - TODO: add argument description
NumberOfChildren - TODO: add argument description
ChildHandleBuffer - TODO: add argument description
Returns:
EFI_UNSUPPORTED - TODO: Add description for return value
--*/
{
EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOut;
EFI_STATUS Status;
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
//
// Kick people off our interface???
//
Status = gBS->OpenProtocol (
Handle,
&gEfiSimpleTextOutProtocolGuid,
(void *)&SimpleTextOut,
This->DriverBindingHandle,
Handle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
ASSERT (Private->Handle == Handle);
Status = gBS->UninstallMultipleProtocolInterfaces (
Handle,
&gEfiSimpleTextOutProtocolGuid,
&Private->SimpleTextOut,
&gEfiSimpleTextInProtocolGuid,
&Private->SimpleTextIn,
NULL
);
if (!EFI_ERROR (Status)) {
//
// Shut down our device
//
Status = gBS->CloseProtocol (
Handle,
&gEfiUnixIoProtocolGuid,
This->DriverBindingHandle,
Handle
);
Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
ASSERT_EFI_ERROR (Status);
#if 0
Private->UnixThunk->CloseHandle (Private->NtOutHandle);
#endif
//
// DO NOT close Private->NtInHandle. It points to StdIn and not
// the Private->NtOutHandle is StdIn and should not be closed!
//
FreeUnicodeStringTable (Private->ControllerNameTable);
gBS->FreePool (Private);
}
return Status;
}

View File

@ -0,0 +1,513 @@
/*++
Copyright (c) 2004 - 2005, 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:
Console.h
Abstract:
Console based on Win32 APIs.
This file attaches a SimpleTextIn protocol to a previously open window.
The constructor for this protocol depends on an open window. Currently
the SimpleTextOut protocol creates a window when it's constructor is called.
Thus this code must run after the constructor for the SimpleTextOut
protocol
--*/
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#define UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE \
EFI_SIGNATURE_32('U','X','s','c')
typedef struct {
UINT64 Signature;
EFI_HANDLE Handle;
EFI_SIMPLE_TEXT_OUT_PROTOCOL SimpleTextOut;
EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutMode;
EFI_UNIX_IO_PROTOCOL *UnixIo;
EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
//
// SimpleTextOut Private Data including Win32 types.
//
// HANDLE NtOutHandle;
// HANDLE NtInHandle;
//COORD MaxScreenSize;
//COORD Position;
//WORD Attribute;
BOOLEAN CursorEnable;
EFI_SIMPLE_TEXT_IN_PROTOCOL SimpleTextIn;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} UNIX_SIMPLE_TEXT_PRIVATE_DATA;
#define UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS(a) \
CR(a, UNIX_SIMPLE_TEXT_PRIVATE_DATA, SimpleTextOut, UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE)
#define UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS(a) \
CR(a, UNIX_SIMPLE_TEXT_PRIVATE_DATA, SimpleTextIn, UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE)
//
// Console Globale Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gUnixConsoleDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gUnixConsoleComponentName;
typedef struct {
UINTN ColumnsX;
UINTN RowsY;
} UNIX_SIMPLE_TEXT_OUT_MODE;
#if 0
//
// Simple Text Out protocol member functions
//
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutReset (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ExtendedVerification - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutOutputString (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN CHAR16 *String
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
String - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutTestString (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN CHAR16 *String
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
String - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutQueryMode (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN ModeNumber,
OUT UINTN *Columns,
OUT UINTN *Rows
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ModeNumber - TODO: add argument description
Columns - TODO: add argument description
Rows - TODO: add argument description
Returns:
TODO: add return values
--*/
;
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetMode (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN ModeNumber
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ModeNumber - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetAttribute (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN Attribute
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Attribute - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutClearScreen (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetCursorPosition (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN Column,
IN UINTN Row
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Column - TODO: add argument description
Row - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutEnableCursor (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN BOOLEAN Enable
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Enable - TODO: add argument description
Returns:
TODO: add return values
--*/
;
#endif
//
// Simple Text Out constructor and destructor.
//
EFI_STATUS
UnixSimpleTextOutOpenWindow (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Private - TODO: add argument description
Returns:
TODO: add return values
--*/
;
EFI_STATUS
UnixSimpleTextOutCloseWindow (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Console - TODO: add argument description
Returns:
TODO: add return values
--*/
;
#if 0
//
// Simple Text In protocol member functions.
//
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextInReset (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ExtendedVerification - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextInReadKeyStroke (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Key - TODO: add argument description
Returns:
TODO: add return values
--*/
;
STATIC
VOID
EFIAPI
UnixSimpleTextInWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Event - TODO: add argument description
Context - TODO: add argument description
Returns:
TODO: add return values
--*/
;
#endif
//
// Simple Text In constructor
//
EFI_STATUS
UnixSimpleTextInAttachToWindow (
IN UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Private - TODO: add argument description
Returns:
TODO: add return values
--*/
;
//
// Main Entry Point
//
EFI_STATUS
EFIAPI
InitializeUnixConsole (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
TODO: Add function description
Arguments:
ImageHandle - TODO: add argument description
SystemTable - TODO: add argument description
Returns:
TODO: add return values
--*/
;
EFI_STATUS
AppendDevicePathInstanceToVar (
IN CHAR16 *VariableName,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
)
/*++
Routine Description:
TODO: Add function description
Arguments:
VariableName - TODO: add argument description
DevicePathInstance - TODO: add argument description
Returns:
TODO: add return values
--*/
;
#endif

View File

@ -0,0 +1,246 @@
/*++
Copyright (c) 2004, 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:
ConsoleIn.c
Abstract:
Console based on Win32 APIs.
This file attaches a SimpleTextIn protocol to a previously open window.
The constructor for this protocol depends on an open window. Currently
the SimpleTextOut protocol creates a window when it's constructor is called.
Thus this code must run after the constructor for the SimpleTextOut
protocol
--*/
#include "Console.h"
#include <sys/poll.h>
//
// Private worker functions
//
STATIC
EFI_STATUS
UnixSimpleTextInCheckKey (
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
);
EFI_STATUS
EFIAPI
UnixSimpleTextInReset (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ExtendedVerification - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
UnixConvertInputRecordToEfiKey (
IN char c,
OUT EFI_INPUT_KEY *Key
)
/*++
Routine Description:
TODO: Add function description
Arguments:
InputRecord - TODO: add argument description
Key - TODO: add argument description
Returns:
EFI_NOT_READY - TODO: Add description for return value
EFI_NOT_READY - TODO: Add description for return value
EFI_NOT_READY - TODO: Add description for return value
EFI_SUCCESS - TODO: Add description for return value
--*/
{
Key->ScanCode = 0;
if (c == '\n')
c = '\r';
Key->UnicodeChar = c;
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextInReadKeyStroke (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Key - TODO: add argument description
Returns:
EFI_DEVICE_ERROR - TODO: Add description for return value
EFI_NOT_READY - TODO: Add description for return value
--*/
{
EFI_STATUS Status;
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
char c;
Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
Status = UnixSimpleTextInCheckKey (Private);
if (EFI_ERROR (Status)) {
return Status;
}
if (Private->UnixThunk->Read (0, &c, 1) != 1)
return EFI_NOT_READY;
Status = UnixConvertInputRecordToEfiKey (c, Key);
return Status;
}
STATIC
VOID
EFIAPI
UnixSimpleTextInWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Event - TODO: add argument description
Context - TODO: add argument description
Returns:
TODO: add return values
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
EFI_STATUS Status;
Private = (UNIX_SIMPLE_TEXT_PRIVATE_DATA *) Context;
Status = UnixSimpleTextInCheckKey (Private);
if (!EFI_ERROR (Status)) {
gBS->SignalEvent (Event);
}
}
STATIC
EFI_STATUS
UnixSimpleTextInCheckKey (
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Private - TODO: add argument description
Returns:
TODO: add return values
--*/
{
struct pollfd pfd;
pfd.fd = 0;
pfd.events = POLLIN;
if (Private->UnixThunk->Poll (&pfd, 1, 0) <= 0) {
return EFI_NOT_READY;
}
return EFI_SUCCESS;
}
EFI_STATUS
UnixSimpleTextInAttachToWindow (
IN UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Private - TODO: add argument description
Returns:
TODO: add return values
--*/
{
EFI_STATUS Status;
Private->SimpleTextIn.Reset = UnixSimpleTextInReset;
Private->SimpleTextIn.ReadKeyStroke = UnixSimpleTextInReadKeyStroke;
Status = gBS->CreateEvent (
EFI_EVENT_NOTIFY_WAIT,
EFI_TPL_NOTIFY,
UnixSimpleTextInWaitForKey,
Private,
&Private->SimpleTextIn.WaitForKey
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@ -0,0 +1,635 @@
/*++
Copyright (c) 2004, 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:
ConsoleOut.c
Abstract:
Console based on Win32 APIs.
This file creates an Win32 window and attaches a SimpleTextOut protocol.
--*/
#include "Console.h"
//
// Private worker functions.
//
#if 0
STATIC
VOID
UnixSimpleTextOutScrollScreen (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
);
#endif
STATIC
VOID
UnixSimpleTextOutPutChar (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console,
IN CHAR16 Char
);
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetAttribute (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN Attribute
);
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetMode (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN ModeNumber
);
//
// Modeule Global for Simple Text Out Mode.
//
#define MAX_SIMPLE_TEXT_OUT_MODE \
(sizeof(mUnixSimpleTextOutSupportedModes)/sizeof(UNIX_SIMPLE_TEXT_OUT_MODE))
STATIC UNIX_SIMPLE_TEXT_OUT_MODE mUnixSimpleTextOutSupportedModes[] = {
{ 80, 25 },
#if 0
{ 80, 50 },
{ 80, 43 },
{ 100, 100 },
{ 100, 999 }
#endif
};
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutReset (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ExtendedVerification - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
UnixSimpleTextOutSetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
UnixSimpleTextOutSetMode (This, 0);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutOutputString (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN CHAR16 *String
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
String - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
CHAR16 *Str;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
for (Str = String; *Str != '\0'; Str++) {
switch (*Str) {
#if 0
case '\n':
if (Private->Position.Y == (Private->MaxScreenSize.Y - 1)) {
UnixSimpleTextOutScrollScreen (Private);
}
if (Private->Position.Y < (Private->MaxScreenSize.Y - 1)) {
Private->Position.Y++;
This->Mode->CursorRow++;
}
break;
case '\r':
Private->Position.X = 0;
This->Mode->CursorColumn = 0;
break;
case '\b':
if (Private->Position.X > 0) {
Private->Position.X--;
This->Mode->CursorColumn--;
}
break;
#endif
default:
UnixSimpleTextOutPutChar (Private, *Str);
}
}
return EFI_SUCCESS;
}
STATIC
VOID
UnixSimpleTextOutPutChar (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console,
IN CHAR16 Char
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Console - TODO: add argument description
Char - TODO: add argument description
Returns:
TODO: add return values
--*/
{
char c = Char;
Console->UnixThunk->Write (1, &c, 1);
}
#if 0
STATIC
VOID
UnixSimpleTextOutScrollScreen (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Console - TODO: add argument description
Returns:
TODO: add return values
--*/
{
}
#endif
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutTestString (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN CHAR16 *String
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
String - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
//
// BugBug: The correct answer would be a function of what code pages
// are currently loaded? For now we will just return success.
//
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutQueryMode (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN ModeNumber,
OUT UINTN *Columns,
OUT UINTN *Rows
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ModeNumber - TODO: add argument description
Columns - TODO: add argument description
Rows - TODO: add argument description
Returns:
EFI_INVALID_PARAMETER - TODO: Add description for return value
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
return EFI_INVALID_PARAMETER;
}
*Columns = mUnixSimpleTextOutSupportedModes[ModeNumber].ColumnsX;
*Rows = mUnixSimpleTextOutSupportedModes[ModeNumber].RowsY;
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetMode (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN ModeNumber
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ModeNumber - TODO: add argument description
Returns:
EFI_INVALID_PARAMETER - TODO: Add description for return value
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
return EFI_INVALID_PARAMETER;
}
This->Mode->Mode = (INT32) ModeNumber;
This->EnableCursor (This, TRUE);
This->ClearScreen (This);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetAttribute (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN Attribute
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Attribute - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
#if 0
Private->Attribute = (WORD) Attribute;
#endif
This->Mode->Attribute = (INT32) Attribute;
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutClearScreen (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
// DWORD ConsoleWindow;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
This->SetCursorPosition (This, 0, 0);
Private->UnixThunk->Write (1, "\e[2J", 4);
#if 0
Private->UnixThunk->FillConsoleOutputCharacter (
Private->NtOutHandle,
' ',
Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
Private->Possition,
&ConsoleWindow
);
Private->UnixThunk->FillConsoleOutputAttribute (
Private->NtOutHandle,
Private->Attribute,
Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
Private->Possition,
&ConsoleWindow
);
#endif
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutSetCursorPosition (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN UINTN Column,
IN UINTN Row
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Column - TODO: add argument description
Row - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
char buf[12];
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
#if 0
Private->Position.X = (WORD) Column;
#endif
This->Mode->CursorColumn = (INT32) Column;
#if 0
Private->Position.Y = (WORD) Row;
#endif
This->Mode->CursorRow = (INT32) Row;
#if 0
Private->UnixThunk->SetConsoleCursorPosition (Private->NtOutHandle, Private->Possition);
#endif
buf[0] = '\e';
buf[1] = '[';
buf[2] = '0' + ((Row / 100) % 10);
buf[3] = '0' + ((Row / 10) % 10);
buf[4] = '0' + ((Row / 1) % 10);
buf[5] = ';';
buf[6] = '0' + ((Column / 100) % 10);
buf[7] = '0' + ((Column / 10) % 10);
buf[8] = '0' + ((Column / 1) % 10);
buf[9] = 'H';
Private->UnixThunk->Write (1, buf, 10);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
UnixSimpleTextOutEnableCursor (
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
IN BOOLEAN Enable
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
Enable - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
#if 0
CONSOLE_CURSOR_INFO Info;
#endif
Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
Private->CursorEnable = Enable;
This->Mode->CursorVisible = Enable;
#if 0
Private->UnixThunk->GetConsoleCursorInfo (Private->NtOutHandle, &Info);
Info.bVisible = Enable;
Private->UnixThunk->SetConsoleCursorInfo (Private->NtOutHandle, &Info);
#endif
return EFI_SUCCESS;
}
EFI_STATUS
UnixSimpleTextOutOpenWindow (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Private - TODO: add argument description
Returns:
TODO: add return values
--*/
{
EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOut;
CHAR16 *WindowName;
//WindowName = Private->UnixIo->EnvString;
#if 0
Private->Attribute = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
if (*WindowName == '?') {
Private->Attribute = BACKGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
WindowName = L"EFI Emulator Error Console";
}
#endif
WindowName = L"EFI Emulator Error Console";
AddUnicodeString (
"eng",
gUnixConsoleComponentName.SupportedLanguages,
&Private->ControllerNameTable,
WindowName
);
//
// Fill in protocol member functions
//
SimpleTextOut = &Private->SimpleTextOut;
SimpleTextOut->Reset = UnixSimpleTextOutReset;
SimpleTextOut->OutputString = UnixSimpleTextOutOutputString;
SimpleTextOut->TestString = UnixSimpleTextOutTestString;
SimpleTextOut->QueryMode = UnixSimpleTextOutQueryMode;
SimpleTextOut->SetMode = UnixSimpleTextOutSetMode;
SimpleTextOut->SetAttribute = UnixSimpleTextOutSetAttribute;
SimpleTextOut->ClearScreen = UnixSimpleTextOutClearScreen;
SimpleTextOut->SetCursorPosition = UnixSimpleTextOutSetCursorPosition;
SimpleTextOut->EnableCursor = UnixSimpleTextOutEnableCursor;
//
// Initialize SimpleTextOut protocol mode structure
//
SimpleTextOut->Mode = &Private->SimpleTextOutMode;
SimpleTextOut->Mode->MaxMode = MAX_SIMPLE_TEXT_OUT_MODE;
SimpleTextOut->Mode->Attribute = 0; //FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
#if 0
//
// Open the window an initialize it!
//
Private->NtOutHandle = Private->UnixThunk->CreateConsoleScreenBuffer (
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL
);
Private->UnixThunk->SetConsoleTitle (WindowName);
#endif
return SimpleTextOut->SetMode (SimpleTextOut, 0);
}
EFI_STATUS
UnixSimpleTextOutCloseWindow (
IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
)
/*++
Routine Description:
TODO: Add function description
Arguments:
Console - TODO: add argument description
Returns:
EFI_SUCCESS - TODO: Add description for return value
--*/
{
#if 0
Console->UnixThunk->CloseHandle (Console->NtOutHandle);
#endif
return EFI_SUCCESS;
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
<MsaHeader>
<ModuleName>UnixConsole</ModuleName>
<ModuleType>UEFI_DRIVER</ModuleType>
<GuidValue>f314a8cc-8985-11db-9f69-0040d02b1835</GuidValue>
<Version>1.0</Version>
<Abstract>Console Dxe driver</Abstract>
<Description>Simulate console with Unix API</Description>
<Copyright>Copyright (c) 2006, Intel Corporation</Copyright>
<License>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.</License>
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
</MsaHeader>
<ModuleDefinitions>
<SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
<BinaryModule>false</BinaryModule>
<OutputFileBasename>UnixConsole</OutputFileBasename>
</ModuleDefinitions>
<LibraryClassDefinitions>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>DebugLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>BaseLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiDriverModelLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiDriverEntryPoint</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>BaseMemoryLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>MemoryAllocationLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>Console.h</Filename>
<Filename>Console.c</Filename>
<Filename>ConsoleIn.c</Filename>
<Filename>ConsoleOut.c</Filename>
<Filename>ComponentName.c</Filename>
</SourceFiles>
<PackageDependencies>
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
<Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
<Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>
</PackageDependencies>
<Protocols>
<Protocol Usage="TO_START">
<ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="BY_START">
<ProtocolCName>gEfiSimpleTextOutProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="BY_START">
<ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>
</Protocol>
</Protocols>
<Guids>
<GuidCNames Usage="ALWAYS_CONSUMED">
<GuidCName>gEfiUnixConsoleGuid</GuidCName>
</GuidCNames>
</Guids>
<Externs>
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
<Extern>
<DriverBinding>gUnixConsoleDriverBinding</DriverBinding>
<ComponentName>gUnixConsoleComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>