From 53e1e5c647b73e45569ed6e8b8a0a5b276aa685e Mon Sep 17 00:00:00 2001 From: darylm503 Date: Tue, 28 Jun 2011 02:34:10 +0000 Subject: =?UTF-8?q?Add=20device=20abstraction=20code=20for=20the=20UEFI=20?= =?UTF-8?q?Console=20and=20UEFI=20Shell-based=20file=20systems.=20Make=20a?= =?UTF-8?q?rgv=20use=20narrow=20characters=20instead=20of=20wide=20charact?= =?UTF-8?q?ers.=20Add=20setenv=20functionality.=20Add=20poll()=20system=20?= =?UTF-8?q?call.=20Change=20signal=20names=20into=20macros=20=E2=80=93=20r?= =?UTF-8?q?equired=20for=20standards=20compliance.=20=20The=20enums=20were?= =?UTF-8?q?=20renamed=20and=20moved=20to=20sys/signal.h=20and=20the=20new?= =?UTF-8?q?=20macros=20reference=20the=20enums.=20Added=20SIGBREAK,=20whic?= =?UTF-8?q?h=20is=20required=20for=20Python.=20Modify=20stdio=20functions?= =?UTF-8?q?=20to=20fail=20cleanly=20when=20called=20with=20a=20NULL=20File?= =?UTF-8?q?=20Pointer=20argument.=20Added=20=20that=20just=20?= =?UTF-8?q?includes=20.=20=20By=20adding=20this=20wrapper,?= =?UTF-8?q?=20we=20improve=20compatibility=20with=20*nix=20files=20which?= =?UTF-8?q?=20assume=20=20exists.=20Add=20=20Added=20m?= =?UTF-8?q?acros=20for=20bcopy(),=20bcmp()=20and=20strsep().=20Modify=20th?= =?UTF-8?q?e=20clock()=20function=20so=20that=20it=20does=20not=20hang=20w?= =?UTF-8?q?hen=20running=20under=20an=20emulation=20environment=20such=20a?= =?UTF-8?q?s=20NT32.=20Move=20TM=20structure=20specific=20macros=20from=20?= =?UTF-8?q?the=20private=20tzfile.h=20into=20=20Add=20strncasecmp?= =?UTF-8?q?=20function.=20Add=20strptime=20function.=20Add=20gettimeofday?= =?UTF-8?q?=20function.=20Add=20getcwd=20function.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11908 6f19259b-4bc3-4df7-8a09-765794883524 --- StdLib/LibC/Uefi/Console.c | 393 --------------------------------------------- 1 file changed, 393 deletions(-) delete mode 100644 StdLib/LibC/Uefi/Console.c (limited to 'StdLib/LibC/Uefi/Console.c') diff --git a/StdLib/LibC/Uefi/Console.c b/StdLib/LibC/Uefi/Console.c deleted file mode 100644 index 0c3a21cf45..0000000000 --- a/StdLib/LibC/Uefi/Console.c +++ /dev/null @@ -1,393 +0,0 @@ -/** @file - File abstractions of the console. - - Manipulates EFI_FILE_PROTOCOL abstractions for stdin, stdout, stderr. - - Copyright (c) 2010, 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 that accompanies this distribution. - The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -static const CHAR16 * stdioNames[NUM_SPECIAL] = { - L"stdin:", L"stdout:", L"stderr:" -}; -static const int stdioFlags[NUM_SPECIAL] = { - O_RDONLY, // stdin - O_WRONLY, // stdout - O_WRONLY // stderr -}; - -static const int stdioMode[NUM_SPECIAL] = { - 0444, // stdin - 0222, // stdout - 0222 // stderr -}; - -static -EFI_STATUS -EFIAPI -ConClose( - IN EFI_FILE_PROTOCOL *This - ) -{ - ConInstance *Stream; - - Stream = BASE_CR(This, ConInstance, Abstraction); - // Quick check to see if Stream looks reasonable - if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb' - return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer - } - // Nothing to Flush. - // Mark the Stream as closed. - Stream->Dev = NULL; - - return RETURN_SUCCESS; -} - -static -EFI_STATUS -EFIAPI -ConDelete( - IN EFI_FILE_PROTOCOL *This - ) -{ - return RETURN_UNSUPPORTED; -} - -static -EFI_STATUS -EFIAPI -ConRead( - IN EFI_FILE_PROTOCOL *This, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ) -{ - EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto; - ConInstance *Stream; - CHAR16 *OutPtr; - EFI_INPUT_KEY Key; - UINTN NumChar; - UINTN Edex; - EFI_STATUS Status; - UINTN i; - - Stream = BASE_CR(This, ConInstance, Abstraction); - // Quick check to see if Stream looks reasonable - if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb' - return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer - } - if(Stream->Dev == NULL) { - // Can't read from an unopened Stream - return RETURN_DEVICE_ERROR; - } - if(Stream != &gMD->StdIo[0]) { - // Read only valid for stdin - return RETURN_UNSUPPORTED; - } - // It looks like things are OK for trying to read - // We will accumulate *BufferSize characters or until we encounter - // an "activation" character. Currently any control character. - Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev; - OutPtr = Buffer; - NumChar = (*BufferSize - 1) / sizeof(CHAR16); - i = 0; - do { - Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex); - if(Status != EFI_SUCCESS) { - break; - } - Status = Proto->ReadKeyStroke(Proto, &Key); - if(Status != EFI_SUCCESS) { - break; - } - if(Key.ScanCode == SCAN_NULL) { - *OutPtr++ = Key.UnicodeChar; - ++i; - } - if(Key.UnicodeChar < 0x0020) { // If a control character, or a scan code - break; - } - } while(i < NumChar); - *BufferSize = i * sizeof(CHAR16); - return Status; -} - -/* Write a NULL terminated WCS to the EFI console. - - @param[in,out] BufferSize Number of bytes in Buffer. Set to zero if - the string couldn't be displayed. - @parem[in] Buffer The WCS string to be displayed - -*/ -static -EFI_STATUS -EFIAPI -ConWrite( - IN EFI_FILE_PROTOCOL *This, - IN OUT UINTN *BufferSize, - IN VOID *Buffer - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto; - ConInstance *Stream; - CHAR16 *MyBuf; - UINTN NumChar; - - Stream = BASE_CR(This, ConInstance, Abstraction); - // Quick check to see if Stream looks reasonable - if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb' - return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer - } - if(Stream->Dev == NULL) { - // Can't write to an unopened Stream - return RETURN_DEVICE_ERROR; - } - if(Stream == &gMD->StdIo[0]) { - // Write is not valid for stdin - return RETURN_UNSUPPORTED; - } - // Everything is OK to do the write. - Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev; - MyBuf = (CHAR16 *)Buffer; - NumChar = *BufferSize; - - // Send MyBuf to the console - Status = Proto->OutputString( Proto, MyBuf); - // Depending on status, update BufferSize and return - if(Status != EFI_SUCCESS) { - *BufferSize = 0; // We don't really know how many characters made it out - } - else { - *BufferSize = NumChar; - Stream->NumWritten += NumChar; - } - return Status; -} - -static -EFI_STATUS -EFIAPI -ConGetPosition( - IN EFI_FILE_PROTOCOL *This, - OUT UINT64 *Position - ) -{ - ConInstance *Stream; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto; - XYoffset CursorPos; - - Stream = BASE_CR(This, ConInstance, Abstraction); - // Quick check to see if Stream looks reasonable - if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb' - return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer - } - if(Stream == &gMD->StdIo[0]) { - // This is stdin - *Position = Stream->NumRead; - } - else { - Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev; - CursorPos.XYpos.Column = (UINT32)Proto->Mode->CursorColumn; - CursorPos.XYpos.Row = (UINT32)Proto->Mode->CursorRow; - *Position = CursorPos.Offset; - } - return RETURN_SUCCESS; -} - -static -EFI_STATUS -EFIAPI -ConSetPosition( - IN EFI_FILE_PROTOCOL *This, - IN UINT64 Position - ) -{ - ConInstance *Stream; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto; - XYoffset CursorPos; - - Stream = BASE_CR(This, ConInstance, Abstraction); - // Quick check to see if Stream looks reasonable - if(Stream->Cookie != 0x62416F49) { // Cookie == 'IoAb' - return RETURN_INVALID_PARAMETER; // Looks like a bad This pointer - } - if(Stream->Dev == NULL) { - // Can't write to an unopened Stream - return RETURN_DEVICE_ERROR; - } - if(Stream == &gMD->StdIo[0]) { - // Seek is not valid for stdin - return RETURN_UNSUPPORTED; - } - // Everything is OK to do the final verification and "seek". - Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev; - CursorPos.Offset = Position; - - return Proto->SetCursorPosition(Proto, - (INTN)CursorPos.XYpos.Column, - (INTN)CursorPos.XYpos.Row); -} - -static -EFI_STATUS -EFIAPI -ConGetInfo( - IN EFI_FILE_PROTOCOL *This, - IN EFI_GUID *InformationType, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ) -{ - EFI_FILE_INFO *InfoBuf; - ConInstance *Stream; - - Stream = BASE_CR(This, ConInstance, Abstraction); - // Quick check to see if Stream looks reasonable - if((Stream->Cookie != 0x62416F49) || // Cookie == 'IoAb' - (Buffer == NULL)) - { - return RETURN_INVALID_PARAMETER; - } - if(*BufferSize < sizeof(EFI_FILE_INFO)) { - *BufferSize = sizeof(EFI_FILE_INFO); - return RETURN_BUFFER_TOO_SMALL; - } - // All of our parameters are correct, so fill in the information. - (void) ZeroMem(Buffer, sizeof(EFI_FILE_INFO)); - InfoBuf = (EFI_FILE_INFO *)Buffer; - InfoBuf->Size = sizeof(EFI_FILE_INFO); - InfoBuf->FileSize = 1; - InfoBuf->PhysicalSize = 1; - *BufferSize = sizeof(EFI_FILE_INFO); - - return RETURN_SUCCESS; -} - -static -EFI_STATUS -EFIAPI -ConSetInfo( - IN EFI_FILE_PROTOCOL *This, - IN EFI_GUID *InformationType, - IN UINTN BufferSize, - IN VOID *Buffer - ) -{ - return RETURN_UNSUPPORTED; -} - -static -EFI_STATUS -EFIAPI -ConFlush( - IN EFI_FILE_PROTOCOL *This - ) -{ - return RETURN_SUCCESS; -} - -EFI_STATUS -EFIAPI -ConOpen( - IN EFI_FILE_PROTOCOL *This, - OUT EFI_FILE_PROTOCOL **NewHandle, - IN CHAR16 *FileName, - IN UINT64 OpenMode, // Ignored - IN UINT64 Attributes // Ignored - ) -{ - ConInstance *Stream; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Proto; - UINTN Columns; - UINTN Rows; - int i; - - if((NewHandle == NULL) || - (FileName == NULL)) - { - return RETURN_INVALID_PARAMETER; - } - // Process FileName - for(i = 0; i < NUM_SPECIAL; ++i) { - if(StrCmp( stdioNames[i], FileName) == 0) { - break; - } - } - if(i >= NUM_SPECIAL) { - return RETURN_NO_MAPPING; - } - // Get pointer to instance. - Stream = &gMD->StdIo[i]; - if(Stream->Dev == NULL) { - // If this stream has been closed, then - // Initialize instance. - Stream->Cookie = 0x62416F49; - Stream->NumRead = 0; - Stream->NumWritten = 0; - switch(i) { - case 0: - Stream->Dev = gST->ConIn; - break; - case 1: - Stream->Dev = gST->ConOut; - break; - case 2: - if(gST->StdErr == NULL) { - Stream->Dev = gST->ConOut; - } - else { - Stream->Dev = gST->StdErr; - } - break; - default: - return RETURN_VOLUME_CORRUPTED; // This is a "should never happen" case. - } - Stream->Abstraction.Revision = 0x00010000; - Stream->Abstraction.Open = &ConOpen; - Stream->Abstraction.Close = &ConClose; - Stream->Abstraction.Delete = &ConDelete; - Stream->Abstraction.Read = &ConRead; - Stream->Abstraction.Write = &ConWrite; - Stream->Abstraction.GetPosition = &ConGetPosition; - Stream->Abstraction.SetPosition = &ConSetPosition; - Stream->Abstraction.GetInfo = &ConGetInfo; - Stream->Abstraction.SetInfo = &ConSetInfo; - Stream->Abstraction.Flush = &ConFlush; - // Get additional information if this is an Output stream - if(i != 0) { - Proto = Stream->Dev; - Stream->ConOutMode = Proto->Mode->Mode; - if( Proto->QueryMode(Proto, Stream->ConOutMode, &Columns, &Rows) != RETURN_SUCCESS) { - Stream->Dev = NULL; // Mark this stream as closed - return RETURN_INVALID_PARAMETER; - } - Stream->MaxConXY.XYpos.Column = (UINT32)Columns; - Stream->MaxConXY.XYpos.Row = (UINT32)Rows; - } - } - // Save NewHandle and return. - *NewHandle = &Stream->Abstraction; - - return RETURN_SUCCESS; -} -- cgit v1.2.3